Forum Moderators: coopster

Message Too Old, No Replies

mysql fetch array() errors?

         

ToxinMan

10:52 am on Jan 26, 2008 (gmt 0)

10+ Year Member



Hey there guys i just have one more question lol

here is a piece of code where i want to store the users information from the database to valuables!
but the thing is that it generates this error instead

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/rickyb/public_html/up/toxinhead.html on line 15

here is my code..

PHP Code:
$result = mysql_query("SELECT * FROM users where username = $username");
while($data = mysql_fetch_array($result)){
$firstname = $data['firstname'];
$lastname = $data['lastname'];
$password1 = $data['password1'];
$email = $data['email'];
$gender= $data['gender'];
}

Thanks again
ricky

phparion

11:54 am on Jan 26, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



you got to put single quotes around string values,

"SELECT * FROM users where username = '$username'"

always print your query when you get this error because it means your query has not been executed as desired.

ToxinMan

9:52 pm on Jan 26, 2008 (gmt 0)

10+ Year Member



Yer thanks , i added in those quotes but now im getting this error?

Parse error: syntax error, unexpected T_VARIABLE in /home/rickyb/public_html/up/toxinhead.html on line 14

Here is my code :

PHP Code:
<?php
//1. creating a connection
$connect = mysql_connect(localhost,user,pass);
if(!$connect){
die ("1. failed connecting ".mysql_error());}

//2. selting a database
$db = mysql_select_db("rickyb_bbs",$connect);
if(!$db){
die("2. failed connecting to database ".mysql_error());}

/////converting Username to a valuble, This cannot be changed
$placeholders = array("{username}");
$username = $placeholders[0];

//Finding out the other users information!
$result = mysql_query("SELECT * FROM users where username = '". $username ."' ");
while($data = mysql_fetch_array($result)){
$firstname = $data['firstname'];
$lastname = $data['lastname'];
$password1 = $data['password1'];
$email = $data['email'];
$gender= $data['gender'];
}
?>

Thanks

ToxinMan

9:54 pm on Jan 26, 2008 (gmt 0)

10+ Year Member



Dont worry , Its working now :):):):) Thanks!