By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,776 Members | 1,397 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,776 IT Pros & Developers. It's quick & easy.

weird problem with mysql_fetch_array

P: n/a
Hey Okay so i have a page that lists a bunch of clients... then another
page that would limit it to a specific chosen client.... the one that
lists all the clients is working just fine, however when i limit the
mysql query with "WHERE 1 AND last_name LIKE Harder" it gives me these
errors

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
result resource in
/home/content/s/i/t/siteadmin/html/clientmanager/searchClients.php on
line 61

Warning: mysql_free_result(): supplied argument is not a valid MySQL
result resource in
/home/content/s/i/t/siteadmin/html/clientmanager/searchClients.php on
line 70

Here is the code in case you see anything you see that neeeds to be
changed.

<?php
require_once ('#############.php');

$result = mysql_query("SELECT last_name, first_name, email, client_id,
company FROM client_info WHERE 1 AND last_name LIKE Harder ");

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
printf("
<tr>
<td class='cd_data'>%s, %s</td>
<td class='cd_data'><a href='mailto:%s' class='cd_link'>%s</a></td>
<td class='cd_data'><form action='viewClientMain.php'
method='post'><input type='hidden' name='client_id' value='%s'><input
type='image' border='0' name='submitgif' src='images/view_client.gif'
onclick='submitform()'></form></td>
</tr>", $row["last_name"], $row["first_name"], $row["email"],
$row["email"], $row["client_id"]);
}

mysql_free_result($result);
?>

Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
wrw[three] (wi***@avantd.biz) decided we needed to hear...
Hey Okay so i have a page that lists a bunch of clients... then another
page that would limit it to a specific chosen client.... the one that
lists all the clients is working just fine, however when i limit the
mysql query with "WHERE 1 AND last_name LIKE Harder" it gives me these
errors

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
result resource in
/home/content/s/i/t/siteadmin/html/clientmanager/searchClients.php on
line 61 Above error is because your SQL statement has an error in it and you
don't check if it worked or not before your script continues

Warning: mysql_free_result(): supplied argument is not a valid MySQL
result resource in
/home/content/s/i/t/siteadmin/html/clientmanager/searchClients.php on
line 70 Same reason as above.

Here is the code in case you see anything you see that neeeds to be
changed.

<?php
require_once ('#############.php');

$result = mysql_query("SELECT last_name, first_name, email, client_id,
company FROM client_info WHERE 1 AND last_name LIKE Harder ");

You need to check if the above statement worked or not by testing
$result. The statement didn't work in your case which is why you get
the two error's above. If $result is false, you should check the error
message returned from mysql_error.
Best guess - your main problem is you should have single quotes around
the word 'Harder' - I'm assuming its a literal and not a column name.
As an aside, the '1 AND' part can be removed - it doesn't serve any
purpose.

--
Dave <da**@REMOVEbundook.com>
(Remove REMOVE for email address)
Jul 17 '05 #2

P: n/a
And see the manual for an example on how to do some simple error
checking (making sure $result is a valid resource, and that rows
exist):

http://php.net/mysql-fetch-assoc

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.