PHP Warning: mysql_num_rows(): supplied argument is not a valid MySQL

Discussion in 'MySQL' started by coun_vincent, Mar 14, 2011.

  1. #1
    hello ,

    i hope i get some help for this :

    apache_error_logs

    here is the PHP code :
    i don't know why the scripte can't update the data in my database and get it again to show it as result .

    feel free to ask if you didn't understand anything

    waiting anyone to help

    thanks
     
    coun_vincent, Mar 14, 2011 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Try replacing with this:

    
    
    //query the database
    if(!$query = mysql_query("SELECT * FROM results")) {
        die(mysql_error());
    }
    
    //loop through and return results
    while($row = mysql_fetch_assoc($query)) {
    
    //make array
    $json[$x] = array("choice" => $row["choices"], "votes" => $row["votes"]);
    }
    
    
    PHP:
     
    jestep, Mar 14, 2011 IP
    coun_vincent likes this.
  3. coun_vincent

    coun_vincent Well-Known Member

    Messages:
    803
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    130
    #3
    [Mon Mar 14 15:25:46 2011] [error] [client .18.35] PHP Notice: Undefined variable: x in /home/**********/public_html/poll/poll.php on line 28, referer: http://*******.com/


    i got this error on apache logs and still nothing happend on the result
     
    coun_vincent, Mar 14, 2011 IP
  4. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #4
    That wouldn't break the script, but it would prevent setting the json array. Have you confirmed that there is data in the table using phpmyadmin or another direct method? Also, as for the json[] array, what are you trying to use for the key?
     
    jestep, Mar 14, 2011 IP
  5. coun_vincent

    coun_vincent Well-Known Member

    Messages:
    803
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    130
    #5
    yes , i checked the database table and they are empty also here is the json code :
     
    coun_vincent, Mar 14, 2011 IP
  6. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #6
    I see. Using the code I did above, try:

    
    //query the database
    if(!$query = mysql_query("SELECT * FROM results")) {
        die(mysql_error());
    }
    
    //loop through and return results
    $x = 0;
    while($row = mysql_fetch_assoc($query)) {
    
    //make array
    $json[$x] = array("choice" => $row["choices"], "votes" => $row["votes"]);
    $x++;
    }
    
    PHP:
     
    jestep, Mar 14, 2011 IP
  7. coun_vincent

    coun_vincent Well-Known Member

    Messages:
    803
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    130
    #7
    i did and there's no error on apache error logs , also i see that the result affichage had some littel change . but after i voted and click send the result didn't add my vote (+1) and i go to see if there's anychange on database table and i see they are still 0 .

    there's one thing left and i think it's the only one i missed .... this msg : Data in this table cannot be edited because it has no primary key.

    i'm using webmin not phpmyadmin thats why i found some prob to managed my DBs .
     
    coun_vincent, Mar 14, 2011 IP
  8. coun_vincent

    coun_vincent Well-Known Member

    Messages:
    803
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    130
    #8
    i fixed it by change the form in json code , thanks
     
    coun_vincent, Mar 15, 2011 IP