brooklynboro Posted November 28, 2007 Share Posted November 28, 2007 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. Quote Link to comment Share on other sites More sharing options...
Hybride Posted December 3, 2007 Share Posted December 3, 2007 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)). Quote Link to comment Share on other sites More sharing options...
revraz Posted December 3, 2007 Share Posted December 3, 2007 What is str? You want it hardcoded to search on str or do you mean $str? $query="SELECT full_name, client_id FROM clients WHERE clients.full_name LIKE '%str%'"; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.