jamesyrawr Posted October 14, 2010 Share Posted October 14, 2010 I'm building a site for a uni project and i seem to be getting these errors back from it this script allows the user to update their info once they have logged in so if you notice anything else i need please say the errors i get are: Notice: Undefined index: firstname in C:\wamp\www\flerp\update_conn.php on line 14 Notice: Undefined index: lastname in C:\wamp\www\flerp\update_conn.php on line 15 Notice: Undefined index: email in C:\wamp\www\flerp\update_conn.php on line 16 <?php $host="localhost"; $username="root"; $password=""; $db_name="flerpusers"; $tbl_name="users"; mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $email = $_POST['email']; $sql = "UPDATE `$tbl_name` SET `firstname` = '$firstname',`lastname` = '$lastname',`email` = '$email'"; mysql_query($sql) or die ("Error: ".mysql_error()); echo "Database updated. <a href='editinfo.php'>Return to edit info</a>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/215879-uni-project-undefined-index-s/ Share on other sites More sharing options...
PFMaBiSmAd Posted October 14, 2010 Share Posted October 14, 2010 You are referencing $_POST['firstname'], $_POST['lastname'], and $_POST['email'] when those variables don't exist, hence undefined index errors ($_POST is an array and is referenced using the index names of its elements.) You would need to determine why those variables don't exist. Quote Link to comment https://forums.phpfreaks.com/topic/215879-uni-project-undefined-index-s/#findComment-1122206 Share on other sites More sharing options...
btherl Posted October 15, 2010 Share Posted October 15, 2010 At a wild guess, I would say either 1. Your form is using the get method, not the post method 2. Or, your input tags have different names to what you are looking for in the script 3. Or, the input tags are not inside the form you are submitting Quote Link to comment https://forums.phpfreaks.com/topic/215879-uni-project-undefined-index-s/#findComment-1122353 Share on other sites More sharing options...
Oziam Posted October 15, 2010 Share Posted October 15, 2010 You might want to reference these variables with an if isset statement to stop the error when the page loads before submitting the form! Best practice is to reference the form name. e.g if(isset($_POST['form_name'])){ $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $email = $_POST['email']; // etc... do other stuff // } Quote Link to comment https://forums.phpfreaks.com/topic/215879-uni-project-undefined-index-s/#findComment-1122356 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.