Jump to content

[SOLVED] Help with login script


tigomark

Recommended Posts

Hello,

 

I am having a problem with a login script not responding how I would hope

 

 
<?php 

session_start(); 


if (isset($_POST['username']) && isset($_POST['password'])){ 
  
  
$username = $_POST['username']; 
$password = $_POST['password']; 


include ("../includes/prefs.php"); 

$db_name = "weekends"; 

$table_name = "users"; 

$connection = @mysql_connect("$host", "$root", "$password") or die("Couldn't connect."); 

$db = @mysql_select_db($db_name, $connection) or die("Couldn't select database."); 

$sql = "SELECT * FROM $table_name 
WHERE username = \"$username\" AND password = \"$password\" 
"; 

$result = @mysql_query($sql, $connection) or die("Couldn't execute query."); 




                        if (mysql_num_rows($result) > 0){ 

                //looks for registered users 
                                $_SESSION['valid_user'] = $username; 
                                        } 
                
                
                } 

?> 

 

Right now if I add the information

 

  

$num_rows = mysql_num_rows($result); 

                echo "$num_rows"; 

 

I get a result of 0 even though I have verified that username and password are correct. I have done a query straight to My_SQL and I do recieve the data I am looking for.

 

Thank you in advance for any help.

Link to comment
https://forums.phpfreaks.com/topic/57866-solved-help-with-login-script/
Share on other sites

try single quote instead of double quote

 

Your code:

$sql = "SELECT * FROM $table_name

WHERE username = \"$username\" AND password = \"$password\"

";

 

Updated:

$sql = "SELECT * FROM $table_name

WHERE username = '$username' AND password = '$password'

";

 

 

Try this one. I think it may be ok.

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.