Problem with PHP and SQL query!<

liunx

Guest
Hi, im trying to check whether a username already exits in my database when a user goes to create a username... and Im getting a "Resource id #4" value when I do mysql_query

Any ideas why???


Here's my code:




...

} else {
$sql = "SELECT * FROM users WHERE username1 LIKE '" . $username78 . "'";
$result = mysql_query($sql) or die("Error: " . mysql_error() );

echo "$result";/** THIS PRINTS OUT Resource id #4 EVERYTIME.. WHY?!?!? =-) */

if (!$result2) { // Username already selected code...

} else { //GETS EXCECUTED EVERYTIME

$now = (time() - 5*3600);
$now = date("g:i a, F jS, Y ", $now);
$sql = "insert into users
(username1, password1, userEmail1, useripadress1, timecreated1 )
values
('$username78', '$pass178', '$Email78', '$REMOTE_ADDR', '$now')";
$result = mysql_query($sql) or die("Error: " . mysql_error() );

// this works fine and is done the same way as the other one...

if (!$result) {
echo "Error adding username to database";
die();

} else echo "submitted";
}
}I'm not sure what happened with the forums but I've deleted the other 2 threads for you as requested. Also, since this is PHP I will moce it to the PHP section for you.
Thanks,
Paulyou can't echo $result

you have to this first


$rows = mysql_fetch_array($result);

echo $rows['username'];


$rows[''] is an array so put the field name of whatever you want to spit out between ''

hthactually PlyWooD, this is teh second or third one moved for you, please start posting in the correct forum.For easier programming, most sites that allow people to have a username don't just assign a username to each person, they actually give each person a unique number, starting from 0001, and then attach a user name to that number. This also allows a person to change their username but still be attached to the same (hidden) user number.
 
Back
Top