SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    The Jellophonic Autobrain CHeeSeBLiND's Avatar
    Join Date
    Jul 2001
    Location
    Bolton, England
    Posts
    584
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SQL syntax error

    why do i keep getting this error:

    You have an error in your SQL syntax near 'replace=jamie' at line 3

    for this bit of code:

    PHP Code:
    // Add

    if ($action == "add") {

    $link "<a href=bio.php?name=$name>$name</a>";

    $sql "INSERT INTO replacer SET
    search=
    $name,
    replace=
    $link";

    if ( 
    mysql_query($sql) )
    { echo(
    "Friend Added"); } else 
    { echo(
    "Error adding friend: " mysql_error() . ""); }


    The $name variable is passed from a form filled on the previous page...
    hmm...

  2. #2
    SitePoint Evangelist ucahg's Avatar
    Join Date
    Apr 2001
    Location
    Sarnia, Ontario, Canada
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to have quotes around the variable (just like if you were typing the sql in through shell.

    PHP Code:
    // Add

    if ($action == "add") {

      
    $link "<a href=bio.php?name=$name>$name</a>";

      
    $sql "INSERT INTO replacer SET search='$name',   replace='$link'";

      if ( 
    mysql_query($sql) ) {
        echo(
    "Friend Added");
      }
      else  {
         echo(
    "Error adding friend: " mysql_error() . "");
      }



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
  •