programming.name Posted May 28, 2010 Share Posted May 28, 2010 Please consider the following code: <form method="post"> Passwrod: <input tyep="text" name="name" /> <input type="submit" value="Ok" /> </form> $db_conn = new MySQLi('localhost', 'root', '', 'db'); $result = $db_conn->query("SELECT * FROM user_name"); $row = $result->fetch_assoc(); $fetched_name = $row['user_name']; $input_name = $_POST['user_name']; // Notice: Undefined index error if($fetched_name == $input_name) { header("Location: welcome.php "); } *This code simply fetches user names from the db and if the user name exists then it redirect to welcome.php page. When I run this code I get 'Notice: Undefined index:' error. Of course I can simply ignore this notice. But I don't want to have any error messages; I want to make my code CLEAN. Also I don't want to use the @ operator to hide the error. I wonder If there is any better solution for this. Thanks. Link to comment https://forums.phpfreaks.com/topic/203171-notice-undefined-index/ Share on other sites More sharing options...
phpchamps Posted May 28, 2010 Share Posted May 28, 2010 $_POST['user_name'] your texbox's name is name not user_name so replace this line with $_POST['name'] Link to comment https://forums.phpfreaks.com/topic/203171-notice-undefined-index/#findComment-1064574 Share on other sites More sharing options...
Pikachu2000 Posted May 28, 2010 Share Posted May 28, 2010 Also, look at: <input tyep= . . . Link to comment https://forums.phpfreaks.com/topic/203171-notice-undefined-index/#findComment-1064697 Share on other sites More sharing options...
The Eagle Posted May 28, 2010 Share Posted May 28, 2010 You want some clean coding, you should watch for spelling mistakes. You spelled the word password incorrectly below. Also, your PHP code is looking for "user_name" where you have not sent it, your form is sending data with "name" so take the below code and replace it with your HTML form and see how it works. <form method="post"> Password: <input tyep="text" name="user_name" /> <input type="submit" value="Ok" /> </form> Link to comment https://forums.phpfreaks.com/topic/203171-notice-undefined-index/#findComment-1064828 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.