doforumda Posted April 23, 2009 Share Posted April 23, 2009 hi i need help in the following code <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Untitled Document</title> </head> <body> <form name="form1" method="post" action="insert.php"> <label>First Name: <input type="text" name="fname" id="fname"> </label> <p> <label>Last Name: <input type="text" name="lname" id="lname"> </label> </p> <p> <label>Address: <input type="text" name="address" id="address"> </label> </p> <p> <label>Phone: <input type="text" name="phone" id="phone"> </label> </p> <p> <label> <input type="submit" name="submit" id="submit" value="Submit"> </label> </p> </form> </body> </html> above is my form and below is my php code <?php $db = mysql_connect("localhost","username","password"); mysql_select_db("example",$db); $query = "insert into example(fname, lname, address, phone) values('".$fname."','".$lname."','".$address."','".$phone."')" or die(mysql_error()); $result = mysql_query($query) or die(mysql_error()); echo "data entered"; ?> when i insert something using that form it displays following error Notice: Undefined variable: fname in C:\wamp\www\New Folder\insert.php on line 12 Notice: Undefined variable: lname in C:\wamp\www\New Folder\insert.php on line 12 Notice: Undefined variable: address in C:\wamp\www\New Folder\insert.php on line 12 Notice: Undefined variable: phone in C:\wamp\www\New Folder\insert.php on line 12 data entered how can i solve this problem Quote Link to comment https://forums.phpfreaks.com/topic/155330-need-help-in-insert-query/ Share on other sites More sharing options...
RichardRotterdam Posted April 23, 2009 Share Posted April 23, 2009 next time please use [ code][ /code] tags please You need to fetch the values using $_POST $fname=(isset($_POST['fname']))?$_POST['fname']:""; Quote Link to comment https://forums.phpfreaks.com/topic/155330-need-help-in-insert-query/#findComment-817214 Share on other sites More sharing options...
doforumda Posted April 23, 2009 Author Share Posted April 23, 2009 ok i ll use those tags next time can please make changes in above code Quote Link to comment https://forums.phpfreaks.com/topic/155330-need-help-in-insert-query/#findComment-817227 Share on other sites More sharing options...
revraz Posted April 23, 2009 Share Posted April 23, 2009 He showed you what you need to do, you need to set your variables from your $_POST array. Quote Link to comment https://forums.phpfreaks.com/topic/155330-need-help-in-insert-query/#findComment-817289 Share on other sites More sharing options...
RichardRotterdam Posted April 23, 2009 Share Posted April 23, 2009 ok i ll use those tags next time can please make changes in above code I could adjust your script so it does what it is suppose to do. However this forum is intended as help and not a "can you fix this for me" forum. I am very willingly to point you in the right direction and say whether you are on the right track but fixing this thing is up to you. Quote Link to comment https://forums.phpfreaks.com/topic/155330-need-help-in-insert-query/#findComment-817567 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.