SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Zealot 容d席m L鷦i's Avatar
    Join Date
    Jan 2005
    Location
    Washington
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs down MYSQL error Line 1???

    I just added this bit of code to my site:
    PHP Code:
    echo "<form action=\"mb1.php?action=addtopic\" method=\"post\">";
              echo 
    "<center>Subject: <input type=\"text\" name=\"subject\" size=\"25\" style=\"border: 1px solid #FFFFFF; background-color: black; color: white\"></font><br>";
              echo 
    "<textarea rows=\"5\" cols=\"26\" name=\"tdescription\" style=\"border: 1px solid #FFFFFF; background-color: black; color: white\"></textarea></font><br>";
              echo 
    "<input type=\"submit\" value=\"Submit\" style=\"border: 1px solid #FFFFFF; background-color: black; color: white\"></font></form></center>";
              }
              if(
    $action == "addtopic")
              {
              
              
    $date date("Y-m-d g:i:s T");
              
    $insert_topic mysql_query("INSERT INTO mb_topics (id, name, username, boardid, lastpost, message, locked, postedon, sticky) VALUES ('', '$subject', '$playerinfo[username]', '$id', '-', '$tdescription', 'N', '$date', 'N')");
              
    $result2 mysql_query($insert_topic) or die("Bad query2: " mysql_error());
              echo 
    "Topic Created!! <br><br>
               <center>[ <a href=\"javascript:history.back(1)\">Back</a> ]</center>"
    ;
        } 
    But when I do the action (Sumbit the topic) I get this error:

    Bad query2: 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.

    Can someone please explain why that is...

    Thanks,
    David
    "'I earned political capital during this campaign and
    now I intend to spend it'-George Bush
    translation: if you thought i was a reckless moron
    these last four years, you aint seen nothing yet"-Lakai.com

  2. #2
    SitePoint Addict toggg's Avatar
    Join Date
    Jan 2005
    Location
    Auvergne/France
    Posts
    253
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    say
    {$playerinfo['username']} within the "" to get the index interpreted
    with '' and {} (generally all variables with brackets)
    +
    bertrand Gugger toggg.com linux, PHP, Auvergne/France open source

  3. #3
    SitePoint Zealot 容d席m L鷦i's Avatar
    Join Date
    Jan 2005
    Location
    Washington
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nope that didn't work. Same error
    "'I earned political capital during this campaign and
    now I intend to spend it'-George Bush
    translation: if you thought i was a reckless moron
    these last four years, you aint seen nothing yet"-Lakai.com

  4. #4
    SitePoint Addict toggg's Avatar
    Join Date
    Jan 2005
    Location
    Auvergne/France
    Posts
    253
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    You should
    PHP Code:
        // somewhere, somehow connect() ...
        
    $insert_request "INSERT INTO mb_topics
          (id, name, username, boardid, lastpost, message, locked, postedon, sticky)
          VALUES
          ('', '
    {$subject}', '{$playerinfo['username']}', '{$id}', '-',
                '
    {$tdescription}', 'N', '{$date]', 'N')";
        $result2 = mysql_query($insert_request) or die("Bad query2: " . mysql_error()); 
    +
    bertrand Gugger toggg.com linux, PHP, Auvergne/France open source

  5. #5
    SitePoint Zealot 容d席m L鷦i's Avatar
    Join Date
    Jan 2005
    Location
    Washington
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nope that doesn't work either it just displays nothing then...
    "'I earned political capital during this campaign and
    now I intend to spend it'-George Bush
    translation: if you thought i was a reckless moron
    these last four years, you aint seen nothing yet"-Lakai.com

  6. #6
    ********* Genius Mike's Avatar
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    5,458
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Assuming "id" is an auto increment column, try this:

    PHP Code:
    echo '<form action="mb1.php?action=addtopic" method="post">' .
              
    '<center>Subject: <input type="text" name="subject" size="25" style="border: 1px solid #FFFFFF; background-color: black; color: white"></font><br>' .
              
    '<textarea rows="5" cols="26" name="tdescription" style="border: 1px solid #FFFFFF; background-color: black; color: white"></textarea></font><br>' .
              
    '<input type="submit" value="Submit" style="border: 1px solid #FFFFFF; background-color: black; color: white"></font></form></center>'
              } 
              if(
    $action == "addtopic"
              { 
               
              
    $date date("Y-m-d g:i:s T"); 
              
    $insert_topic "INSERT INTO mb_topics (name, username, boardid, lastpost, message, locked, postedon, sticky) VALUES ('$subject', '$playerinfo[username]', '$id', '-', '$tdescription', 'N', '$date', 'N')"
              
    $result2 mysql_query($insert_topic) or die("Bad query2: " mysql_error()); 
              echo 
    "Topic Created!! <br><br> 
               <center>[ <a href=\"javascript:history.back(1)\">Back</a> ]</center>"

        } 
    Mike
    It's not who I am underneath, but what I do that defines me.

  7. #7
    SitePoint Zealot 容d席m L鷦i's Avatar
    Join Date
    Jan 2005
    Location
    Washington
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok that worked... Thanks a million that script has been killing me all day today at school...
    "'I earned political capital during this campaign and
    now I intend to spend it'-George Bush
    translation: if you thought i was a reckless moron
    these last four years, you aint seen nothing yet"-Lakai.com

  8. #8
    ********* Genius Mike's Avatar
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    5,458
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    No problem. Just for your notes, I removed the "id" from the query as it was not needed, and the problem was that you were trying to run a function from within a function, eg:

    $insert_topic = mysql_query("...data...");
    $result2 = mysql_query($insert_topic);

    You had to remove the first instance of mysql_query()

    Mike
    It's not who I am underneath, but what I do that defines me.


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
  •