Jump to content

Recommended Posts

Hello everyone,

Forgive my ignorance I am totally new to PHP and have come across the follow error while trying to run a user login script:

 

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/content/do_authusers.php on line 21

 

Here is my code:

 

<?

if ((!$_POST[username]) || (!$_POST[password])) {

    header("Location: show_login.html");

    exit;

 

}

 

//set up names of database and table to use

$db_name = "blogtasticc";

$table_name = "logins";

 

//connect to server and select database

$connection = mysql_connect("blogtasticc.xxxxxxxx", "xxxxxxx", "xxxxxx")

    or die(mysql_error());

$db = mysql_select_db($db_name, $connection) or die(mysql_error());

 

//build and issue the query

$sql = "SELECT * FROM $table_name WHERE username = '$_POST(username)'

    AND password = password('_POST[password]')";

 

$result = mysql_query($sql,connection) or die(mysql_error());

 

//get the number of rows in the result set

$num = mysql_num_rows($result);

 

//print a message or redirect elsewhere, based on result

if ($num !=0) {

    $msg = "<P>Congratulations, you're authorized!</p>";

} else {

    header("Location: show_login.html");

    exit;

 

}

?>

<HTML>

<HEAD>

<TITLE>Secret Area</TITLE>

</HEAD>

<BODY>

<? echo "$msg"; ?>

</BODY>

</HTML>

 

I ran a syntax check on it and it came back fine.  Any help would be much appreciated.

Thanks,

Dave

$sql = "SELECT * FROM $table_name WHERE username = '$_POST(username)'
    AND password = password('_POST[password]')";

I'm pretty sure that query fails.

 

to fix it, it would be $_POST[username] with brackets.  You should sanitize your inputs though.

You're also missing a $ before the _POST[password]

 

Should be closer to this iirc:

$sql = "SELECT * FROM $table_name WHERE username = '{$_POST['username']}'
    AND password = password({$_POST['password']})";

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/content/do_authusers.php on line 21

 

At least look at the line where the error is being reported at -

 

$result = mysql_query($sql,connection) or die(mysql_error());

 

The second parameter of the mysql_query() is the link resource. Your's is missing the $ in front of connection, making it a defined constant instead of a variable holding the link resource from your mysql_connect() statement.

Okay everyone thanks for all the help!  I am not getting any more error codes but now I am getting the following Message:

 

Unknown column 'bacon' in 'where clause'

 

'bacon' is the password for this particular user.  So instead of posting:

 

$msg = "<P>Congratulations, you're authorized!</p>";

 

it is posting the users password?

 

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.