Announcement

Collapse
No announcement yet.

MySQL driving me crazy - a server issue?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • MySQL driving me crazy - a server issue?

    I'm transferring some php scripts from one server to my new eukhost.

    However, for some reason the MySQL isn't working - and it's driving me mad!!

    Here's the PHP I'm using:

    PHP Code:
    $recent_sql mysql_query("SELECT id, 
                                title, 
                                type, 
                                price,
                                description, 
                                hire, 
                                age, 
                                adults, 
                                requirements, 
                                overnight, 
                                picture, 
                                dim, 
                                gallerypics
                                  FROM range 
                                WHERE type='
    $choice'
                                ORDER BY price ASC"
    ); 
    I keep being told though that that "supplied argument is not a valid MySQL result resource."

    Is there any reason behind the scenes why this wouldn't work? As I can't see anything wrong with it, and as I said it worked on my previous server.

    ANY help would be REALLY appreciated!!
    Online poker room ratings

  • #2
    Doesn't look wrong - are you sure it's the SQL Server that's the problem? The error suggests that the SQL Server call didn't return a result set. I assume if you have something like
    Code:
    $result = mysql_query($recent_sql, $link_id) or die('Query failed: ' . mysql_error().'<br>'.$query);
    $row = mysql_fetch_row($result) or die(mysql_error());
    that would tell you more about the problem - I'm guessing it's either a field/table name issue or the $link_id.
    David Allen - www.serina.co.uk

    Comment


    • #3
      Mmmmm - still having problems.

      It might have something to do with the way I'm reading the variable I'm passing in the header.

      The URL is something like this www.mydomain.com/view.php?id=1

      and the PHP I'm using is:

      PHP Code:
      $choice $_GET['id']; 
      Is that the problem?

      P.S. MASSIVELY appreciate your help here by the way ...
      Online poker room ratings

      Comment


      • #4
        that looks fine - you say you transfered scripts from another server - have you got the connection string right? - I presume the table and field names are the same - but what about the database name?
        David Allen - www.serina.co.uk

        Comment


        • #5
          Yeah, the database is being selected fine.

          The only error message I'm getting is:
          Code:
          Query failed: Unknown column 'castle' in 'where clause'
          I get that when I'm using the following MySQL:

          PHP Code:
          $recent_sql mysql_query("SELECT id, 
                                      title, 
                                      type, 
                                      price,
                                      description, 
                                      hire, 
                                      age, 
                                      adults, 
                                      requirements, 
                                      overnight, 
                                      picture, 
                                      dim, 
                                      gallerypics
                                        FROM range 
                                      WHERE type=
          $choice"); 
          The string 'castle' is what is passed in the header. It should be the value of the 'type' field rather than the name of the column
          Online poker room ratings

          Comment


          • #6
            Ah ok i see
            try mysql_query("SELECT id, blah, blah, etc FROM range WHERE type = '".$choice."'")

            trouble was where clause looked like - where type=castle rather than what you wanted which is WHERE type='castle'
            Last edited by DavidAllen; 27-02-2008, 23:39.
            David Allen - www.serina.co.uk

            Comment


            • #7
              Still no luck I'm afraid.

              I'm just getting "Query Failed:" without any further explanation now
              Online poker room ratings

              Comment


              • #8
                did you get the quote marks right - single double .$choice.double single double ?
                David Allen - www.serina.co.uk

                Comment


                • #9
                  Yup - I just don't get it :frown:

                  PHP Code:
                  $recent_sql mysql_query("SELECT
                                              type, 
                                              price,
                                              description, 
                                              hire, 
                                              age, 
                                              adults, 
                                              requirements, 
                                              overnight, 
                                              picture, 
                                              dim, 
                                              gallerypics
                                                FROM range 
                                              WHERE type='"
                  .$choice."'");


                  $result mysql_query($recent_sql$link_id) or die('Query failed: ' mysql_error().'<br>'.$query);
                  $row mysql_fetch_row($result) or die(mysql_error()); 
                  Online poker room ratings

                  Comment


                  • #10
                    OK sorry - thought you hadn't used my original code
                    just need to use $recent_sql="SELECT etc as above" ie don't need mysql_query - that is done on the line below $result=
                    Last edited by DavidAllen; 27-02-2008, 23:56.
                    David Allen - www.serina.co.uk

                    Comment


                    • #11
                      I'm sorry to be a pain.

                      I've now got my query looking like this:


                      PHP Code:
                      $recent_sql "SELECT type, price, description, hire, age, adults, requirements, overnight, picture, dim, gallerypics FROM range WHERE type='".$choice."'"
                      ... but still no luck
                      Online poker room ratings

                      Comment


                      • #12
                        I don't get what $link_id is ... could that have anything to do with it?
                        Online poker room ratings

                        Comment


                        • #13
                          that line should be ok now
                          that has put the SQL Server into a variable called recent_sql
                          Now need to do the actual call
                          so
                          $result=mysql_query($recent_sql);;
                          should give the data from the query into an object called $result
                          to get from the $result object holing all the data to individual rows we need the next line
                          $row = mysql_fetch_row($result);
                          which leaves us pointing at the first row and can access the fields in that row like :
                          echo $row['price'];
                          Only difference is that the $link_id optional paremeter has been removed from the mysql_query call - I use $link_id as the return from the module that does the database connection - you don't need it
                          David Allen - www.serina.co.uk

                          Comment


                          • #14
                            I don't get what $link_id is ... could that have anything to do with it?
                            we cross posted - yes - get rid of it
                            David Allen - www.serina.co.uk

                            Comment


                            • #15
                              So frustrating:

                              Code:
                              Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/bounce6/public_html/inf.php on line 37
                              Thank you very much for your time

                              I've gone through testing everything.

                              The script connects to the database, it finds the database ... and there's definitely a column called type in the table.
                              Online poker room ratings

                              Comment

                              Working...
                              X