darkshad0w Posted May 16, 2011 Share Posted May 16, 2011 Hi I am trying to figure out with this example i saw online does not work...I am building a database to store user and password and i keep getting an error "undefined index username" i need it to pull the username from mysql database so how do i do this??? mysql_connect("host", "username", "pw") or die (mysql_error()); mysql_select_db('username') or die (mysql_error()); if(mysql_num_rows(mysql_query("SELECT * from users WHERE username='" . $_POST['username'] . "'")) == 1) ( this is the error line) now I have the actual host username and pw in my file i just took it off for my security lol. Quote Link to comment https://forums.phpfreaks.com/topic/236504-mysql-php-error/ Share on other sites More sharing options...
Pikachu2000 Posted May 16, 2011 Share Posted May 16, 2011 This isn't a MySQL problem. Moving to PHP Coding help. Quote Link to comment https://forums.phpfreaks.com/topic/236504-mysql-php-error/#findComment-1215882 Share on other sites More sharing options...
JasonLewis Posted May 16, 2011 Share Posted May 16, 2011 The undefined index is coming from the $_POST['username'] part, to be precise. This is because either 1) you have no submitted a form or 2) the username field in your form has an incorrect name. My suggestion is to ensure that you have a form, and that the name for the username field matches the key name in your $_POST array. You can do a print_r on $_POST to see if it's all being sent properly. print_r($_POST); Quote Link to comment https://forums.phpfreaks.com/topic/236504-mysql-php-error/#findComment-1215887 Share on other sites More sharing options...
darkshad0w Posted May 16, 2011 Author Share Posted May 16, 2011 here is my current form this is where the "username" is being pulled from no? <html> <head> </head> <body> <form action="submit.php" method="post"><br/> <h1>Registration form</h1><br/> Username: <input type="text" name="username" /><br/> Password: <input type="password" name="password" /><br/> <input type="submit" value="submit" /> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/236504-mysql-php-error/#findComment-1215889 Share on other sites More sharing options...
fugix Posted May 16, 2011 Share Posted May 16, 2011 as project fear said above...this notice is being triggered because your form has not been submitted...what is the results that you receive when this script is ran? Quote Link to comment https://forums.phpfreaks.com/topic/236504-mysql-php-error/#findComment-1215893 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.