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

Link to comment
Share on other sites

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

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.