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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.