SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    Stockholm, Sweden
    Posts
    52
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    parse error, please help

    I get this error:
    Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /home3/badpills/public_html/newpoll2.php on line 109

    with this code:

    PHP Code:
        $query "INSERT INTO questions SET question = $exploded[0], date = CURDATE();";
        
    mysql_query($query);
        
        
    $id mysql_query("SELECT ID FROM questions ORDER BY ID ASC;");

        if (!
    $id
        {  
            echo(
    "<p>Error performing query: " mysql_error() . "</p>");  
            exit();
        }
        
        
    $row mysql_fetch_array($id);
        
    $i 1;
        
    $c count($exploded) - 1;
        
        while(
    $c)
        {
            
    $query "INSERT INTO alternatives SET alternative = $exploded[$i], date = CURDATE(), votes = 0, question = $row['ID'];";
            
    mysql_query($query);
            
    $i++;
            
    $c--;
        } 
    the error line is this:

    PHP Code:
            $query "INSERT INTO alternatives SET alternative = $exploded[$i], date = CURDATE(), votes = 0, question = $row['ID'];"
    i cant figure out the problem, please help.

  2. #2
    That's Right. notepad_coder's Avatar
    Join Date
    Apr 2002
    Location
    Colorado
    Posts
    835
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well the only thing I can see. but I don't know if I'm right or not but shouldn't you use
    PHP Code:
    $query "INSERT INTO alternatives (alternative, date, votes, question) VALUES ('$exploded[$i]', CURDATE(), 0, '" .$row['ID']. "'";
    // and not
    $query "INSERT INTO alternatives SET alternative = $exploded[$i], date = CURDATE(), votes = 0, question = $row['ID'];"
    I think it was the ';' you had at the end near $row['ID']
    PHP Code:
    $row['ID'];"; 
    There shouldn't be one there and you should use '$something' in queries if it is not a number.
    - the lid is off the maple syrup again!

  3. #3
    gingham dress, army boots... silver trophy redux's Avatar
    Join Date
    Apr 2002
    Location
    Salford / Manchester / UK
    Posts
    4,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try changing it to this:
    PHP Code:
    $query "INSERT INTO alternatives SET alternative = {$exploded[$i]}, date = CURDATE(), votes = 0, question = {$row['ID']}"
    or this:
    PHP Code:
    $query "INSERT INTO alternatives SET alternative = " $exploded[$i] . ", date = CURDATE(), votes = 0, question = " $row['ID']; 
    ps: no need to have the ; at the end of your query when you send it like this
    re·dux (adj.): brought back; returned. used postpositively
    [latin : re-, re- + dux, leader; see duke.]
    WaSP Accessibility Task Force Member
    splintered.co.uk | photographia.co.uk | redux.deviantart.com

  4. #4
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just change the line with the error


    PHP Code:
    $query "INSERT INTO alternatives SET alternative = $exploded[$i], date = CURDATE(), votes = 0, question = $row['ID'];"
    to this

    PHP Code:
    $query "INSERT INTO alternatives SET alternative = $exploded[$i], date = CURDATE(), votes = 0, question = $row[ID]"
    or this

    PHP Code:
    $query "INSERT INTO alternatives SET alternative = $exploded[$i], date = CURDATE(), votes = 0, question = {$row['ID']}"
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR


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
  •