ProcalX Posted October 27, 2009 Share Posted October 27, 2009 When trying to run $t_result and $a_t_result mysql queries I get errors: $a_result works fine. I get errors at line 17 for $a_t_result and at line 28 for $t_result. I am searching for either: Chemical Brothers (artist) & galvanize (title) together (error @ line 28) or no artist & galvanize (title) together (errors @ line 17) searching for just artist works fine. Error recieved on both lines is: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/though/public_html/searchresults.php on line 17 <?php $a = $_POST["artist"]; $t = $_POST["title"]; $conn = mysql_connect("localhost", "abcde", "abcde"); mysql_select_db("abcde"); $a_t_result = mysql_query ("select * from hits where artist='$a' and title='$t'"); $t_result = mysql_query ("select * from hits where title='$t'"); $a_result = mysql_query ("select * from hits where artist='$a'"); if($a !=""&&$t !="") { while($row = mysql_fetch_array($a_t_result)) { echo " Song Title: $row[song] <br/> " ; echo " Artist: $row[artist] <br/> " ; echo " Year: $row[year] <br/> " ; echo " Chart Position: $row[chart] <br/> " ; echo " Searching Artist and Title Worked! " ; } } elseif($t !="") { while($row = mysql_fetch_array($t_result)) { echo " Song Title: $row[song] <br/> " ; echo " Artist: $row[artist] <br/> " ; echo " Year: $row[year] <br/> " ; echo " Chart Position: $row[chart] <br/> " ; echo " Searching Title Only Worked! " ; } } elseif($a !="") { while($row = mysql_fetch_array($a_result)) { echo " Song Title: $row[song] <br/> " ; echo " Artist: $row[artist] <br/> " ; echo " Year: $row[year] <br/> " ; echo " Chart Position: $row[chart] <br/> " ; echo " Searching Artist Only Worked! " ; } } mysql_close($conn); ?> New to PHP, just building the foundations of the script at the moment, integrity will be brought in later on once its working. thanks for your help guys, majorly stumped by this? lol Quote Link to comment https://forums.phpfreaks.com/topic/179187-fetch-array-error/ Share on other sites More sharing options...
Daniel0 Posted October 27, 2009 Share Posted October 27, 2009 Your query failed for some reason. Use mysql_error to see what error message MySQL returned. Quote Link to comment https://forums.phpfreaks.com/topic/179187-fetch-array-error/#findComment-945392 Share on other sites More sharing options...
ProcalX Posted October 27, 2009 Author Share Posted October 27, 2009 Being new to PHP how would I write that into the code? I have put it after the line where I am getting the error and it makes no difference so suspect I am putting it in wrong. Quote Link to comment https://forums.phpfreaks.com/topic/179187-fetch-array-error/#findComment-945405 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.