Jump to content

Login Script Error - HELP!


EATON106

Recommended Posts

Hi,

 

Im using the code below to check a users username and password is ligit before adding their username to their session.

 

<?php

$con = mysql_connect("localhost","user","password");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

mysql_select_db("hiddenbid", $con);

  $username = mysql_real_escape_string($_POST['username']);

  $password = md5($_POST['password']);

  $mysql = mysql_query("SELECT * FROM users WHERE name = '{$username}' AND password = '{$password}'");

  if(mysql_num_rows($mysql)=1){

    $_SESSION['USERID'] = $username;

    print "<b>Welcome</b>, you are signed in as " . $_SESSION['USERID'] . ".";

    print "<br /><br />Redirecting...";

    header ("location:index.php");

    }

  else{

    header ("location:signin.php");

    }

?>

 

Anyway, it doesnt work as I get the following error:

 

Fatal error: Can't use function return value in write context in C:\Program Files\Abyss Web Server\htdocs\signinconfirmer.php on line 35

 

Any ideas what is causing this please?

 

Also can I add a pause after the redirect message before it takes the user to the index.php page?

 

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/210651-login-script-error-help/
Share on other sites

Hi

 

You are assigning 1 to the return from mysql_num_rows, rather than checking it. You need 2 equals signs:-

 

if(mysql_num_rows($mysql)==1){

 

All the best

 

Keith

 

Thanks Keith, however it still doesn't like it as returns me to the signin.php page regardless of if the username and password are incorrect or not.

Put this echo '<pre>'; print_r($_POST); echo '</pre>'; at the top of the script to make sure the values are making it to the script in the $_POST array.

 

Then, immediately after you assign the query string to the $mysql variable, echo it also. echo '<br />' . $mysql . '<br />;

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.