SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict stu567blue's Avatar
    Join Date
    Aug 2007
    Posts
    316
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    MYSQL Query Problem

    Hi There, I have a problem with my MYSQL query, I keep getting this message:

    mysql error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1 in query: 1
    Shown below is the script can anyone tell me what the problem is:

    PHP Code:
    <?php
        $cid 
    = (int)($_GET['cid']);
        
    $pid = (int)($_GET['pid']);
        
        
    // Connects to your Database
        
    mysql_connect("localhost""##""") or die(mysql_error());
        
    mysql_select_db("###") or die(mysql_error()); 
        
        
    // Get the radio button values 
            
        
        // Insert record 
            
        // What if the don't like yours
        
    if (!isset($_POST['vote'])) {
        
    $sql mysql_query("UPDATE co_rate SET votes = votes +1, total = total +1 WHERE photo_id= $pid");
          
    $update_idy mysql_query($sql) or die ("mysql error: " mysql_error() . " in query: " .  $sql);
            
    $nr mysql_num_rows$sql );
            
    mysql_free_result$sql );    
            
        } elseif (!isset(
    $_POST['idly'])) { 
        
            
    // Update the data
        
    $sqla mysql_query("UPDATE co_rate SET dly = dly +1, total = total +1 WHERE photo_id= $pid");
              
    $update_idy mysql_query($sqla) or die ("mysql error: " mysql_error() . " in query: " .  $sqla);
            
    $nr mysql_num_rows$sqla );
            
    mysql_free_result$sqla );    
        }

        
    // Put it into an array 
        
    $array mysql_query("SELECT * FROM co_rate "
        or die (
    mysql_error());
        
        
        
    // Loop Through the data 
        
    while ($rate mysql_fetch_array($array)) {
                                          
                                          
    //This calculates the sites ranking and then outputs it - rounded to 1 decimal
                                            
    $current =  $rate[votes] / $rate[total] * 100
                                            echo 
    "Current Rating: " round($current1) . "% <br>"

                                          }

    ?>

  2. #2
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    your sql looks okay.

    you might want to try;
    UPDATE co_rate SET co_rate.votes = co_rate.votes +1, co_rate.total = co_rate.total +1 WHERE photo_id= $pid

    or;
    UPDATE co_rate SET votes = $votesplusone, total = $totalplusone WHERE photo_id= $pid

  3. #3
    SitePoint Addict stu567blue's Avatar
    Join Date
    Aug 2007
    Posts
    316
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by blogtactic View Post
    your sql looks okay.

    you might want to try;
    UPDATE co_rate SET co_rate.votes = co_rate.votes +1, co_rate.total = co_rate.total +1 WHERE photo_id= $pid

    or;
    UPDATE co_rate SET votes = $votesplusone, total = $totalplusone WHERE photo_id= $pid
    I keep getting this error when I choose the bottom radio button any ideas?

    mysql error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1 in query: 1

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,336
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    please echo the sql string
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Addict stu567blue's Avatar
    Join Date
    Aug 2007
    Posts
    316
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    please echo the sql string
    SQL


    PHP Code:
        if (isset($_POST['vote'])) {
        
    $sql mysql_query("UPDATE co_rate SET co_rate.votes = co_rate.votes +1, co_rate.total = co_rate.total +1 WHERE photo_id= $pid");
          
    $update_idy mysql_query($sql) or die ("mysql error: " mysql_error() . " in query: " .  $sql);
            
    $nr mysql_num_rows$sql );
            
    mysql_free_result$sql );    
            
        } elseif (!isset(
    $_POST['idly'])) { 
        
            
    // Update the data
        
    $sqla mysql_query("UPDATE co_rate SET co_rate.dly = co_rate.dly +1, co_rate.total = co_rate.total +1 WHERE photo_id= $pid");
              
    $update_idy mysql_query($sqla) or die ("mysql error: " mysql_error() . " in query: " .  $sqla);
            
    $nr mysql_num_rows$sqla );
            
    mysql_free_result$sqla );    
        } 

  6. #6
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,336
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    i can't believe i'm debugging php code, i don't even do php!!

    Code:
    $sql = mysql_query("UPDATE ... ");
    $update_idy = mysql_query($sql)
    mysql_query() executes a query, and assigns a "handle" (whatever that is)

    you cannot then execute the handle as though it were another query
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  7. #7
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,068
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    This loop will read each row of the results set in turn into a php array:

    PHP Code:
    while ($row=$this->db->dbFetchArray($result)) {
        
    $database_result_output[]=$row;

    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •