Jump to content

Fetch Array Error


ProcalX

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/179187-fetch-array-error/
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.