View unanswered posts | View active topics It is currently Mon Dec 18, 2017 8:04 am



Reply to topic  [ 2 posts ] 
 Mysql_Fetch_array Wrong? 
Author Message
Junior Member

Joined: Sun Nov 07, 2004 12:22 am
Posts: 8
Post 
My server says mysql_fetch_array has no info, not sure why.

Code:
$link_id = mysql_connect ($dbhost, $dbusername, $dbuserpass);
mysql_select_db("$dbname", $link_id);
$username = "Testfirst12";
$result = mysql_query("SELECT * WHERE first_name=".$username." FROM address_book", $link_id);
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row
echo $row['first_name']." - ".$row['last_name']. "<br />";
}
mysql_close($link_id);

_________________
[url=\'http://www.zerographics.org/forums\']http://www.zerographics.org/forums[/url]


Sat Mar 26, 2005 12:18 pm
Report this post
Profile
Junior Member

Joined: Thu Jul 21, 2005 5:26 am
Posts: 2
Post 
I'm not sure if this isthe cause of your problem, but it seems to me you used the wrong quotes in your MySQL query.
I would do it like this:

Code:
$link_id = mysql_connect ($dbhost, $dbusername, $dbuserpass);
mysql_select_db("$dbname", $link_id);
$username = "Testfirst12";
$result = mysql_query('SELECT * WHERE first_name = ' . $username . ' FROM address_book', $link_id);
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row
echo $row['first_name']." - ".$row['last_name']. "<br />";
}
mysql_close($link_id);


Another option is to not concatenate at all, like this:
Code:
$result = mysql_query("SELECT * WHERE first_name = '$username' FROM address_book", $link_id);


Since you're using double quotes inside your query, you don't need to do the " . $username . " part.


Thu Jul 21, 2005 5:32 am
Report this post
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.