|
Posted by strawberry on 11/30/06 00:37
Dan wrote:
> I've been getting this error below:
>
> mysql_fetch_array(): supplied argument is not a valid MySQL result
> resource
>
> When running this code, I can't seem to figure out what is wrong.
>
> <?php
> require_once('functions.php');
>
> $search = $_POST['term'];
> $field = $_POST['field'];
>
> do_html_header();
>
> //query
> $conn = db_connect();
> $result = $conn->query("SELECT city, restaurant FROM massachusetts
> WHERE $field LIKE '%$search%'");
> if (!$result)
> return false;
>
>
> //And we display the results
> while($data = mysql_fetch_array($result))
> {
> echo $data['city'];
> echo " ";
> echo $data['restaurant'];
> echo "<br>";
> echo "<br>";
> }
>
> do_html_sidebar();
> do_html_footer();
>
> ?>
>
> my db_connect(); function is below (with the login information
> changed):
>
> function db_connect()
> {
> $result = new mysqli('localhost', 'user', 'password', 'database');
> if (!$result)
> throw new Exception('Could not connect to database server');
> else
> return $result;
> }
>
> And this is my search form where it gets the post variables:
>
> <form method='post' action='performsearch.php'>
> <table bgcolor='#cccccc'>
> <tr>
> <td>Search here:</td>
> <td><input type='text' name='term'></td>
> <td><Select NAME="field">
> <Option VALUE="college">college</option>
> <Option VALUE="restaurant">restaurant</option>
> <Option VALUE="phone1">phone</option>
> </Select></td></tr>
> <tr>
> <td colspan=2 align='center'>
> <input type='submit' value='Search'></td></tr>
> </table></form>
>
>
> Can anybody help? Thanks
is 'query' a valid function? perhaps that should be 'mysql_query'?
Navigation:
[Reply to this message]
|