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
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)).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.