Question about tutorial user authentication with Mysql

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
billspeg
Forum Newbie
Posts: 7
Joined: Sun Dec 28, 2003 3:47 am

Question about tutorial user authentication with Mysql

Post 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
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post 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 ;)
billspeg
Forum Newbie
Posts: 7
Joined: Sun Dec 28, 2003 3:47 am

tried code change same thing dies on cant do it query

Post 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
billspeg
Forum Newbie
Posts: 7
Joined: Sun Dec 28, 2003 3:47 am

solved original code worked when i allowed select access

Post 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
Post Reply