Page 1 of 1

Code not working - help

Posted: Thu Apr 13, 2006 11:47 am
by steverossco
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi, 
I have got this codeing to search two mysql Username and password tables and depending on which table the data is found on - pass the user to a different webpage.

Code: Select all

<? 

echo "username" . 
$_REQUEST["username"] . " was selected.";    // use this to declare the variable "date" in your 
echo "<BR>";                     // case it will be $_REQUEST["Username"] 

echo "password" . 
$_REQUEST["password"]. " was seleted.";   // same thing again here, u change urs to $_REQUEST["Password"] 
echo "<BR>";                     // i used the echos to make sure that i was passing the correct values 
$username = $_REQUEST["username"];            // here i just made the variable easier to type into my code 
$password = $_REQUEST["password"]; 

// Make a MySQL Connection 
mysql_connect("localhost", "s14633902", "230683") or die(mysql_error()); 
mysql_select_db("s14633902") 
or die(mysql_error()); 

function AuthUser($tableName,$username,$password) 
{ 
global $dbLink; 

if (!($result = @mysql_query("SELECT * FROM $tableName where username='$username' AND password = '$password'",$dbLink))) 
{ 
return 0; 
} 
if (($row = @mysql_fetch_array($result)) && ($password == $row["password"] && $password != "")) 
return 1; 
else 
return 0; 
} 

if(AuthUser("newlogin",$username,$password)) 
{ 
// Redirect to home page 
echo "<p class=data> <center>Successfully,Logged in<br><br><a href='Log out.php'> Log OUT </a><br><br><a href=home.htm>Click here if your browser is not redirecting automatically or you don't want to wait.</a><br></center>"; 
     print "<script>"; 
       print " self.location='home.htm';"; //  re-direct 
          print "</script>"; 


}elseif(AuthUser("piclogin",$username,$password)) 
{ 
// Redirect to Registration page 
echo "<p class=data> <center>Successfully,Logged in<br><br><a href='Log out.php'> Log OUT </a><br><br><a href=Registration>Click here if your browser is not redirecting automatically or you don't want to wait.</a><br></center>"; 
     print "<script>"; 
       print " self.location='Registration.php';"; //  re-direct 
          print "</script>"; 

}else{ 
// Redirect to login page 
echo "<font face='Verdana' size='2' color=red><center>Wrong Login. Please Enter your Username and Password and Try Again </center><br><p>&nbsp;</p><center><input type='button' value='Retry' onClick='history.go(-1)'></center>"; 

} 
?>


However it just passes me to the else statement at the end of the codeing every time. There is data in both tables and i can send and retrieve data from these files however this script doesnt seem to work....... Please if anyone has an idea as to why it isnt working please tell me....

Distraught newbie

Stephen


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Thu Apr 13, 2006 12:37 pm
by feyd
If you remove the @ operators, what happens? (Make sure to check your error logs)

Re: Removing the @ symbol

Posted: Thu Apr 13, 2006 12:52 pm
by steverossco
thanks for the advice Feyd,
i will post code like that in the future.

Removing the @ symbols throws up the following error:

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/s14633902/public_html/loginck23.php on line 30


Think im out of my depth with this but i cannot see any other way around it so i have to try and get it to work.
Any help greatly appreciated.

Thanks
Stephen

Posted: Thu Apr 13, 2006 12:59 pm
by feyd
The code that you have posted thus far does not set $dbLink.