Page 1 of 1

Question about tutorial user authentication with Mysql

Posted: Sun Dec 28, 2003 3:47 am
by billspeg
hi i was very interested in the code example of the tutorialon user authentication with mysql since i would like to create a portal application for my web sitehere is the code it always dies at the third line and says can't do it
<?
if($submit){
$db=mysql_connect("xxxxxx","xxxxxx","xxxxxx") or die ("cant connect");
mysql_select_db("techunit",$db) or die("cant change");
$result=mysql_query("SELECT * FROM user WHERE name='$username'",$db) or die ("cant do it");
while($row=mysql_fetch_array($result)){
if($row["password"]==$password){
printf("Successfully Logged IN!<a href='indexhigh.asp'>Enter</a>");
}
}
}
?>
any help would be appreciated thanks

Posted: Sun Dec 28, 2003 3:53 am
by vigge89
try this instead:

Code: Select all

<?php

if($submit){

$db=mysql_connect("xxxxxx","xxxxxx","xxxxxx") or die ("cant connect");

mysql_select_db("techunit",$db) or die("cant change");

$query = "SELECT * FROM user WHERE name='$username'";

$result=mysql_query($query) or die ("cant do it");

while($row=mysql_fetch_array($result)){
    if($row["password"]==$password){
    printf("Successfully Logged IN!<a href='indexhigh.asp'>Enter</a>");
    }
}

}

?>
also, is there an table anmed 'user'? Have you set $username to something at all? Just checking ;)

tried code change same thing dies on cant do it query

Posted: Sun Dec 28, 2003 4:12 am
by billspeg
hi really appreciate your quick reply unfortunatly code does same thing dies on the query for further explanation yes i have supplied a user table in the techunit database and i have filled in a row of data in the table so their will be a name and password already enetered to match up with the entry

solved original code worked when i allowed select access

Posted: Sun Dec 28, 2003 8:34 am
by billspeg
hi once i used mysql_error() instead of cant do it code explained i did not have select permissions on database gave myself permissions and now it works