SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Feb 2003
    Location
    NL
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help me: UPDATE MySQL script in PHP

    Okay, this is what i've got:

    PHP Code:
    $sql "UPDATE dealers SET provincie='$provincie' WHERE id='$dealerID'"
    i tried about everything with the ' and the " quotes, but SQL keeps telling me:

    You have an error in your SQL syntax near 'sql' at line 1
    UPDATE dealers SET provincie='NLdre' WHERE id='5'


    However, when i copy-paste that into MySQL it works perfectly.

    I checked the MySQL.com manual, and the code there is exactly the same.

    I use PhP 4.0.6 and MySQL 3.23.38 (Sun Cobalt default)

    Thanks in advance!
    Last edited by Zilverdael; Feb 17, 2003 at 07:33.

  2. #2
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The sql seems ok to me.

    Could post the part of the code that is executing the query?

    -Helge

  3. #3
    SitePoint Member
    Join Date
    Feb 2003
    Location
    NL
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sure, no problem.

    I found a new one aswell

    i wont paste all 675 lines from my script, but only the 'vital' parts

    The initialisation:
    PHP Code:
    <?
    // MySQL Init
    include('mysqlinit.php');
    // Check if we can enter the DataBase
        
    if (! mysql_select_db("$db") ) {
          echo 
    "unable to access database";
          exit();
        }
    // Lets do a query
        
    $result mysql_query "SELECT * FROM dealers" );
    // Does it work ??
        
    if (!$result) {
          echo(
    "Error getting data from the database");
          exit();
        }
    ?>
    mysqlinit.php:
    PHP Code:
    <?
    // SESSION Init
      
    session_start();
      
    session_register(SESSION);

    // MySQL initialisation
      
    $server "localhost";
      
    $dbuser "********";
      
    $dbpass "********";
      
    $db "dealers";
      
    $connection mysql_connect($server$dbuser$dbpass);
    ?>
    One of the update functions:
    PHP Code:
    if ( $land != 'NULL' ) {
      
    $sql "UPDATE dealers SET " .
             
    "land='$land' WHERE id='$dealerID' ";
      if ( 
    mysql_query(sql) ) {
        echo 
    "Land changed OK ...<BR>";
      }
      else {
        echo 
    "Land aanpassen FAILURE ...<BR>";
        echo 
    "<B>Error:</B> " mysql_error() . "<BR>" $sql;
        exit();
      }

    And the new bugging remove function:
    PHP Code:
      if ($act == remove) {
        
    $sql "DELETE FROM dealers WHERE id=$dealerID";
        if ( 
    mysql_query(sql) ) {
          echo 
    "Dealer Deleted OK!<P>";
          exit();
        }
        else {
          echo 
    "Error deleting dealer ... <BR>";
          echo 
    mysql_error() . "<BR>$sql";
          exit();
        }
      } 
    Once more: the error codes typed directy into MySQL works perfectly.
    All give about the same error as above,
    You have an error in your SQL syntax near 'sql' at line 1
    DELETE FROM dealers WHERE id=5


    Once more, thanks in advance

  4. #4
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You just forgot the "dollarsign".
    PHP Code:
    // You need $sql and not just sql.
    // That's because $sql is a variable
    if ( mysql_query($sql) ) { 
    Hope this solves it.

    -Helge

  5. #5
    SitePoint Member
    Join Date
    Feb 2003
    Location
    NL
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    my ... GOD ... i feel horrible!!

    I checked the script at least 20 times, and simply forgot the friggen dollarsign!!!

    I feel sick and im going home.
    Ill never forgive myself


    THANKS A LOT FOR HELPING ME!!

  6. #6
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Those are the mistakes that could drive anyone crazy

    -Helge


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
  •