jas21 Posted January 6, 2014 Share Posted January 6, 2014 (edited) Hello experts, I am running with an app and i have some notice error while inserting records. My form code is pasted below: <form action="add_bk_insert.php"> Name <input type="text" name="name"/><br /> E-mail <input type="text" name="email" /><br /> Contact <input type="text" name="contact" /><br /> Requirement <input type="text" name="requirement" /><br /> <input type="submit" value="Submit" /> </form> and my add_bk_insert.php code is as shown below: <?php mysql_connect("localhost","root",""); mysql_select_db("test"); $order = "INSERT INTO sal2 (name,email_id, contact,requirement) VALUES ('$_POST[name]','$_POST[email_id]','$_POST[contact]','$_POST[requirement]')"; $result = mysql_query($order); if($result){ echo "Inserted"; //include_once("testimonials.php"); } else{ echo("<br>Input data is fail"); } ?> when i run the above code it shows a notice error as below: Notice: Undefined index: name Notice: Undefined index: email_id Notice: Undefined index: contact Notice: Undefined index: requirement So i dont know what exactly i am missing. Please some one can help me out with this. I am really stuck. Edited January 6, 2014 by jas21 Quote Link to comment https://forums.phpfreaks.com/topic/285130-notice-undefined-index-name-in-cxampphtdocs/ Share on other sites More sharing options...
PravinS Posted January 6, 2014 Share Posted January 6, 2014 try replacing this code <form action="add_bk_insert.php"> Name <input type="text" name="name"/><br /> E-mail <input type="text" name="email" /><br /> Contact <input type="text" name="contact" /><br /> Requirement <input type="text" name="requirement" /><br /> <input type="submit" value="Submit" name="btnSubmit"/> </form> <?php mysql_connect("localhost","root",""); mysql_select_db("test"); if (isset($_POST['btnSubmit'])) { $name = isset($_POST[name]) ? $_POST[name] : ''; $email_id = isset($_POST[email_id]) ? $_POST[email_id] : ''; $contact = isset($_POST[contact]) ? $_POST[contact] : ''; $requirement = isset($_POST[requirement]) ? $_POST[requirement] : ''; $order = "INSERT INTO sal2 (name,email_id, contact,requirement) VALUES('".$name."','".$email_id."','".$contact."','".$requirement."')"; $result = mysql_query($order); if($result) { echo "Inserted"; //include_once("testimonials.php"); } else{ echo("<br>Input data is fail"); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/285130-notice-undefined-index-name-in-cxampphtdocs/#findComment-1464044 Share on other sites More sharing options...
Solution jas21 Posted January 6, 2014 Author Solution Share Posted January 6, 2014 try replacing this code <form action="add_bk_insert.php"> Name <input type="text" name="name"/><br /> E-mail <input type="text" name="email_id" /><br /> Contact <input type="text" name="contact" /><br /> Requirement <input type="text" name="requirement" /><br /> <input type="submit" value="Submit" name="btnSubmit"/> </form> <?php mysql_connect("localhost","root",""); mysql_select_db("test"); if (isset($_POST['btnSubmit'])) { $name = isset($_POST[name]) ? $_POST[name] : ''; $email_id = isset($_POST[email_id]) ? $_POST[email_id] : ''; $contact = isset($_POST[contact]) ? $_POST[contact] : ''; $requirement = isset($_POST[requirement]) ? $_POST[requirement] : ''; $order = "INSERT INTO sal2 (name,email_id, contact,requirement) VALUES('".$name."','".$email_id."','".$contact."','".$requirement."')"; $result = mysql_query($order); if($result) { echo "Inserted"; //include_once("testimonials.php"); } else{ echo("<br>Input data is fail"); } } ?> Thanks a lot of replying. But did u run the code because the serverside script is not working. Or may be i am wrong. But i do tried it out and not working for me. Quote Link to comment https://forums.phpfreaks.com/topic/285130-notice-undefined-index-name-in-cxampphtdocs/#findComment-1464067 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.