Jump to content

I need help with this darn search!


brooklynboro

Recommended Posts

Hi. Trying to make a search page that displays list of results.

I'm getting this as the error "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/instantn/public_html/new_gold_site/yy.php on line 21"

 

<?php # Script 7.6 - search_users.php


$page_title = 'View the Current Users';

require_once ('mysql_connect.php'); // Connect to the db.

if (isset($_POST['submit'])){ //button pressed

$str = $_POST['searchstring'];
// Make the query.
$query="SELECT full_name, client_id FROM clients WHERE clients.full_name LIKE '%str%'";
$result = @mysql_query ($query); // Run the query.

// Table header.
echo '<table align="center" cellspacing="0" cellpadding="5">
<tr><td align="left"><b>Edit</b></td><td align="left"><b>Delete</b></td><td align="left"><b>name</b></td></tr>
';

// Fetch and print all the records.
$bg = '#eeeeee';
while ($row = mysql_fetch_array($result)) {
$bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee');
echo '<tr bgcolor="' . $bg . '">
<td align="left"><a href="edit_user.php?id=' . $row['client_id'] . ' ">Edit</a></td>
<td align="left"><a href="delete_user.php?id=' . $row['client_id'] . ' ">Delete</a></td>

<td align="left">' . $row['full_name'] . '</td></tr>
';
}
} else {

?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p><b>search:</b> <input type="text" name="searchstring" size="15" maxlength="15"/><br /></p>
<input type="submit" name="submit" value="submit" />

</form><!-- End of Form -->


<?php
} // end of else funtion

mysql_close(); // Close the database connection.

?>

 

Any help appreciated.

Isaac

 

MOD EDIT - code tags added. And don't shout.

Link to comment
https://forums.phpfreaks.com/topic/79172-i-need-help-with-this-darn-search/
Share on other sites

Change this:

$result = @mysql_query ($query); // Run the query.

to this:

$result = mysql_query($query) OR die(mysql_error());

And this:

$row = mysql_fetch_array($result)); 

To this:

$row = mysql_fetch_array($result, MYSQL_ASSOC);

That ought to do it. You were grabbing the data, but you weren't telling the db how you were (ie: $row could either be MYSQL_ASSOC (by the name of the row) or MYSQL_NUM (by the number of the row as it is in the table)).

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.