Click here to Skip to main content
15,905,325 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Please help i have succeed to send data to my data base but on load  error showing on top of the page "Notice: Undefined index: uname in C:\xampp\htdocs\bbaluchistan.com\Suggestions.php on line 18 , line 19 . line 22 .line 29 .line 31 . line 33. line 35,


What I have tried:

<pre><!DOCTYPE>
<?php
$server="localhost";
$user="root";
$pass="";
$database="sug";

$con=mysql_connect($server,$user,$pass);
$db=mysql_select_db($database,$con);

if(!$con && !db)
{
}
else
{
$uname=$_POST["uname"];
$coments=$_POST["coments"];

if ($_FILES["upload"]["error"] > 0)
 
{
echo "Error: " . $_FILES["upload"]["error"]. "<br>";
}
else
{
$name=$_FILES["upload"]["name"];
	
	$type=$_FILES["upload"]["type"]; 
	
	$size=$_FILES["upload"]["size"] /1024;
	
	$path=$_FILES["upload"]["tmp_name"];
	
	$name=preg_replace("/\s+/","-",$name);
	$picname=pathinfo($name, PATHINFO_FILENAME);
	$picext=pathinfo($name, PATHINFO_EXTENSION);
	$mix=$picname . date("YmjHis") . "." .$picext;

	move_uploaded_file($path, "pictures/" . $mix);		
	
$sql = "INSERT INTO sugt (sr,name,coments,upload) VALUES(NULL,'$uname','$coments','$mix')";

  mysql_query($sql);

}
}
  
?>


<table  width="450" height="150"  >
    <form   action="" method="post" enctype="multipart/form-data">
    <tr>
    <td width="200">Name</td>.
    <td><input type="text" size="38" placeholder="Type Name" name="uname"></td>
    </tr>   
   
    <tr>
    <td width="200">Your suggestion</td>
    <td><textarea cols="42"  rows="7" placeholder="Type Your suggestions" name="coments"></textarea></td>
    </tr>
    
    <tr>
    <td width="200">Upload File</td>
    <td><input type="file" name="upload"></td>
    </tr>
    
    <tr>
    <td colspan="2" align="right">
    <input type="submit" value="Submit">
    <input type="reset" value="Reset">
    </td>
    </tr>
   	</form>
    </table>
Posted
Updated 3-Apr-20 9:07am
v2
Comments
Richard Deeming 2-Apr-20 16:35pm    
Don't do it like that!

Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.

PHP: SQL Injection - Manual[^]
ZurdoDev 3-Apr-20 7:07am    
Figure out which line is line 18 and then see why you have an undefined index.
Member 14790660 3-Apr-20 8:51am    
I can't understand error still please give me any solution.
ZurdoDev 3-Apr-20 16:20pm    
Did you do what I suggested?

1 solution

Here's a way to let you see what there is to see:

In the action file, add the line:
JavaScript
print_r($_POST);
It will dump the entire contents of the $_POST array - you can see what's there and what's not. Another thing to try: change the method to 'get' -and then you can see the results in the URL (don't forget to change how you reference(read) the data!).

A shortcut, by the way, is to retrieve $_REQUEST - which works for both post and get methods - it has a minor drawback (if both methods use the same name= for example) but it's not that easy to do without trying.

In any case - this lets you see what it is your sending and receiving - and don't forget that php is case sensitive.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900