cpharry Posted April 25, 2009 Share Posted April 25, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/155575-search-form/ Share on other sites More sharing options...
mikesta707 Posted April 25, 2009 Share Posted April 25, 2009 post the code? Quote Link to comment https://forums.phpfreaks.com/topic/155575-search-form/#findComment-818751 Share on other sites More sharing options...
cpharry Posted April 25, 2009 Author Share Posted April 25, 2009 <? $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> <? } ?> Quote Link to comment https://forums.phpfreaks.com/topic/155575-search-form/#findComment-818770 Share on other sites More sharing options...
mikesta707 Posted April 25, 2009 Share Posted April 25, 2009 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); Quote Link to comment https://forums.phpfreaks.com/topic/155575-search-form/#findComment-818774 Share on other sites More sharing options...
gffg4574fghsDSGDGKJYM Posted April 25, 2009 Share Posted April 25, 2009 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(); } ... ?> Quote Link to comment https://forums.phpfreaks.com/topic/155575-search-form/#findComment-818776 Share on other sites More sharing options...
cpharry Posted April 25, 2009 Author Share Posted April 25, 2009 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' Quote Link to comment https://forums.phpfreaks.com/topic/155575-search-form/#findComment-818937 Share on other sites More sharing options...
cpharry Posted April 25, 2009 Author Share Posted April 25, 2009 Just realised that if i put the 'name' like that instead of just name it doesnt give any errors but it also doesnt give any results which there are two. Quote Link to comment https://forums.phpfreaks.com/topic/155575-search-form/#findComment-818945 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.