ismail_nasar Posted June 16, 2013 Share Posted June 16, 2013 i m new in php i make two pages first was first.php the second was insert.php the codes are below but it show Notice: Undefined index: how to remove this error thanks first page <!DOCTYPE html> <html> <body> <form id="firstform" action="insert.php" method="post"> <center> My First Page in PHP </center> <center>Name:<input type="text" id="name" size=20> FatherName: <input type="text" id="fname" size=20> Address:<input type="text" id="add" size=20> <input type="submit" name="sub"> </form> </body> </html> insert page <html> <body> <?php $con=mysqli_connect("localhost","root","khan","first"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $sql="INSERT INTO bio(name, fathername , address) VALUES ('$_POST[name]','$_POST[fname]','$_POST[add]')"; if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } echo "1 record added"; mysqli_close($con); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/279224-notice-undefined-index/ Share on other sites More sharing options...
xenLiam Posted June 16, 2013 Share Posted June 16, 2013 What was the complete error? A line and a variable must be shown after "Notice: Undefined index". I can't follow which one. Quote Link to comment https://forums.phpfreaks.com/topic/279224-notice-undefined-index/#findComment-1436235 Share on other sites More sharing options...
Barand Posted June 16, 2013 Share Posted June 16, 2013 Your inputs need name attributes. It is the name and value that is passed in the post (not the id and value) Quote Link to comment https://forums.phpfreaks.com/topic/279224-notice-undefined-index/#findComment-1436236 Share on other sites More sharing options...
Strider64 Posted June 16, 2013 Share Posted June 16, 2013 (edited) For example Address:<input type="text" id="add" size=20> might look something like <input type="text" name="address" id="address-style" size="20"> and your php: $address = $_POST['address']; Edited June 16, 2013 by Strider64 Quote Link to comment https://forums.phpfreaks.com/topic/279224-notice-undefined-index/#findComment-1436238 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.