Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.