Jump to content

MYSQL php error


darkshad0w

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/236504-mysql-php-error/
Share on other sites

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);

Link to comment
https://forums.phpfreaks.com/topic/236504-mysql-php-error/#findComment-1215887
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/236504-mysql-php-error/#findComment-1215889
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.