Jump to content

need help in php code for inserting data to mysql db


doforumda

Recommended Posts

hi my html page is here

 

<html>
<head>
<title>Untitled Document</title>
</head>

<body>
<form method="post" action="feedback.php">
  <label>Name:
  <input name="user" type="text" maxlength="40" size="40">
  </label>
  <p>
    <label>Email:
    <input type="text" name="email">
    </label>
  </p>
  <p>
    <label>Comments:
    <textarea name="comments" cols="45" rows="5"></textarea>
    </label>
</p>
  <p>
    <label>
    <input type="submit" value="Submit">
    </label>
  </p>
</form>
</body>
</html>

 

and php code is here

 

<body>
<?php
if(!$user || !$email || !$comments)
{
echo "Fill in all fields.";
exit;
}

$user = addslashes($user);
$email = addslashes($email);
$comments = addslashes($comments);

$db = mysql_connect("localhost");
mysql_select_db("videoshop", $db);

$addfeedback = "insert into feedback
								(name,email,comments)
								values('".$user."','".$email."','".$comments."')";
$result = mysql_query($addfeedback) or die(mysql_error());

echo "Thank you your data is added.";

?>
</body>
</html>

 

the problem i am facing is when i fill all the textfields in html page and submit it the on php side it says

 

"Notice: Undefined variable: user in D:\wamp\www\feedback\feedback.php on line 10

Fill in all fields."

 

how can this problem be fixed?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.