Jump to content

Mysql_fetch_array problem


smc

Recommended Posts

Ello,

Okay I'm making myself a login script (which how much success, who knows?) but I am getting a parse error I can't figure out:

Here is my code to the releavent portion

[code=php:0]
// This will translate the fields into variables PHP can use
$username = $_POST['username'] ;
$password = $_POST['password'] ;

//This will now load the config login information, connect to the DB, select the DB, and then search for a matching username
$cms_root_path = './';
include($cms_root_path . 'config.php');
$conn = mysql_connect ($dblocation, $dbusername, $dbpassword)
or die ("Sorry - I got lost and couldn't find the database. Please try back later.");
$result = @mysql_select_db("$dbdatabase", $conn)
or die("Sorry - the database decided to give me trouble. Please try back after I've put it in it's place.");
//This checks to see if there are any entries in the table users where the username matches the one just entered
$execute = mysql_query("select * from users where username=$username");
// or namenotfound();
//NOTE: SQL<MODIFIER> will represent the information retrieved from the database
while($row = mysql_fetch_array($execute)){
$sqlusername = $row["username"];
$sqlpassword = $row["password"];
$sqlfirstname = $row["first_name"];
$sqllastname = $row["last_name"];
$sqlposition = $row["position"];
$sqlrank = $row["rank"];
$sqlemail = $row["email"];
}

//Now we are going to make sure the password is correct, if it isn't then our custom function will return to the error page
if ( $password != $sqlpassword ){
wrongpassword();
}
[/code]

I get

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/een/public_html/login.php on line 58

when attempting to login and it returns with my wrongpassword(); function.

Help would be greatly appreciated!
Link to comment
Share on other sites

Firstly, @ surpresses errors, so I think having this
$result = @mysql_select_db("$dbdatabase", $conn) or die("stuff");
won't work, as no error could trigger the die.

You also don't need quotes around a var, so just $dbdatabase.
Take out the @ and see if you get an error?

Before trying to use $execute you also need to check if it exists, if anything was returned.
Link to comment
Share on other sites

Try adding single quotes around the variable in your sql statement:

[code]$execute = mysql_query("select * from users where username='$username'");[/code]

If that doesn't work, change it to:
[code]$execute = mysql_query("select * from users where username='$username'") or die(mysql_error());[/code]

Orio.
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.