Jump to content

Search Form


cpharry

Recommended Posts

Hi,

 

I have a search form, i need it to search upto 4 different tables in the same database for whatever the person is searching for. At current whenever i put the tables like `char`, location its comes up with.... Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/wowbasec/public_html/search.php on line 13

 

I need some help if anyone can do that

 

Thanks

 

Link to comment
https://forums.phpfreaks.com/topic/155575-search-form/
Share on other sites

<? 
$search = $_POST["search"];
$db = "`char`";

$connection = mysql_connect("localhost","wowbasec","PASSWORD REMOVED");

mysql_select_db("wowbasec_class", $connection);

$query = "select * from `char`, location WHERE name='$search'"; 

$result = mysql_db_query("wowbasec_class", $query); 

while ($r = mysql_fetch_assoc($result)) { // Begin while 
$ts = $r["name"]; 
$ts1 = $r["id"]; 
?>
<table width="1000" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><a href="viewchar.php?id=<?php echo $ts1['id'];
									$ts1 = $_POST['id']; ?>"> <? echo $ts ?></td>
  </tr>
</table>
<? 
}
?>

Link to comment
https://forums.phpfreaks.com/topic/155575-search-form/#findComment-818770
Share on other sites

well since you already selected the database you were going to access with the following line:

mysql_select_db("wowbasec_class", $connection);

 

it is kind of redundant to use mysql_db_query. You might want to try just using mysql_query, IE


$query = "select * from `char`, location WHERE name='$search'";

$result = mysql_=query($query, $connection); 

Link to comment
https://forums.phpfreaks.com/topic/155575-search-form/#findComment-818774
Share on other sites

 

mysql_db_query

4.0.6 This function is deprecated, do not use this function. Use mysql_select_db() and mysql_query() instead.

http://www.php.net/manual/en/function.mysql-db-query.php

 

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/wowbasec/public_html/search.php on line 13

Told you that the SQL query didn't work, you can add this to see what happen :

 

<?php
...
$result = mysql_query($query);
if (!$result) {
    echo 'Invalid query: ' . mysql_error(). "<br>";
    echo  'SQL Query: ' . $query. "<br>";
    die();
}
...
?>

Link to comment
https://forums.phpfreaks.com/topic/155575-search-form/#findComment-818776
Share on other sites

This is the code now...

<? 
$search = $_POST["search"];
$db = "`char`";

$connection = mysql_connect("localhost","wowbasec","PASSWORD REMOVED");

mysql_select_db("wowbasec_class", $connection);

$query = "select * from `char`, location WHERE name='$search'";

$result = mysql_query($query, $connection); 

if (!$result) {
    echo 'Invalid query: ' . mysql_error(). "<br>";
    echo  'SQL Query: ' . $query. "<br>";
    die();
}

while ($r = mysql_fetch_assoc($result)) { // Begin while 
$ts = $r["name"]; 
$ts1 = $r["id"]; 
?>
<table width="1000" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><a href="viewchar.php?id=<?php echo $ts1['id'];
									$ts1 = $_POST['id']; ?>"> <? echo $ts ?></td>
  </tr>
</table>
<? 
}
?>

 

But i get this...

 

Invalid query: Column 'name' in where clause is ambiguous

SQL Query: select * from `char`, location WHERE name='harry'

 

 

Link to comment
https://forums.phpfreaks.com/topic/155575-search-form/#findComment-818937
Share on other sites

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.