SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Guru
    Join Date
    Sep 2001
    Location
    Vancouver
    Posts
    809
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    problem with INSERT INTO script

    Ok here is the error I'm getting:
    Notice: Undefined variable: from in /home/foodsfo/public_html/manufacturers/temp_process.php on line 45


    An error occured while updating the db: You have an error in your SQL syntax near 'to, from, subject, message, companyname, title, firstname, lastname, jobtitle, a' at line 1
    And here is what is on line 45:
    PHP Code:
    $Query "INSERT INTO inquiry_tracking (id, to, from, subject, message, companyname, title, firstname, lastname, jobtitle, address, city, zipcode, state, country, website, date, ipaddress) VALUES ('0', '$to', '$from', '$subject', '$message', '$companyname', '$contact_detail_title', '$firstname', '$lastname', '$jobtitle', '$address', '$city', '$zipcode', '$state', '$country', '$website', '$date', '$ipaddress')"
    And finally here is my table structure:
    PHP Code:
    CREATE TABLE inquiry_tracking (
      
    id int(11NOT NULL auto_increment,
      
    to varchar(255NOT NULL default '',
      
    from varchar(255NOT NULL default '',
      
    subject varchar(255NOT NULL default '',
      
    message longtext NOT NULL,
      
    companyname varchar(255NOT NULL default '',
      
    title varchar(255NOT NULL default '',
      
    firstname varchar(255NOT NULL default '',
      
    lastname varchar(255NOT NULL default '',
      
    jobtitle varchar(255NOT NULL default '',
      
    address varchar(255NOT NULL default '',
      
    city varchar(255NOT NULL default '',
      
    zipcode varchar(255NOT NULL default '',
      
    state varchar(255NOT NULL default '',
      
    country varchar(255NOT NULL default '',
      
    website varchar(255NOT NULL default '',
      
    date varchar(255NOT NULL default '',
      
    ipaddress varchar(255NOT NULL default '',
      
    PRIMARY KEY  (id)
    TYPE=MyISAM
    I can't figure out what is wrong. Any help would be greatly appreciated.

    Want to see the script in action? Visit: http://www.foodsfortrade.com/manufac...iry.php?id=680. Feel free to mess around with the forms and click submit to see what happens.

  2. #2
    + platinum's Avatar
    Join Date
    Jun 2001
    Location
    Adelaide, Australia
    Posts
    6,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    not sure if it's the problem, but you've got an auto increment on the id column, yet you're inserting the value "0" into it

  3. #3
    SitePoint Guru
    Join Date
    Sep 2001
    Location
    Vancouver
    Posts
    809
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That increases it automatically to the next logical number, so that's not the problem.

  4. #4
    + platinum's Avatar
    Join Date
    Jun 2001
    Location
    Adelaide, Australia
    Posts
    6,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If it increases automatically then why are you telling it to equel "0" (which you're also saying is a string by quoting it)

    just try this:

    PHP Code:
     $Query "INSERT INTO inquiry_tracking (to, from, subject, message, companyname, title, firstname, lastname, jobtitle, address, city, zipcode, state, country, website, date, ipaddress) VALUES ('$to', '$from', '$subject', '$message', '$companyname', '$contact_detail_title', '$firstname', '$lastname', '$jobtitle', '$address', '$city', '$zipcode', '$state', '$country', '$website', '$date', '$ipaddress')"

  5. #5
    Non-Member Icheb's Avatar
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    1,474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by platinum
    not sure if it's the problem, but you've got an auto increment on the id column, yet you're inserting the value "0" into it [img]images/smilies/smile.gif[/img]
    That isn't the problem, because the part of the query stated in the error message is located somewhere else.

    The problem is: "to" is a reserved word in MySQL.
    You either have to enclose it in backticks ( ` ) or look for a different column name.

    But still, as mentioned by platinum, if "id" is set to "auto increment", you shouldn't define it at all in the query. Either do '' or leave it out in the first place.

  6. #6
    SitePoint Guru
    Join Date
    Sep 2001
    Location
    Vancouver
    Posts
    809
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is the error I'm getting now:
    Notice: Undefined variable: address in /home/foodsfo/public_html/manufacturers/inquirysuccess.php on line 25

    Notice: Undefined variable: from in /home/foodsfo/public_html/manufacturers/inquirysuccess.php on line 45


    An error occured while updating the db: You have an error in your SQL syntax near 'from, subject, message, companyname, title, firstname, lastname, jobtitle, addre' at line 1
    Here is the entire script:
    PHP Code:
    <?php
    error_reporting
    (E_ALL);
    /* This page receives and handles the data generated by "editname.php". */

    // Trim the incoming data.

    $toname trim($toname);
    $toname addslashes($toname);
    $emailaddress trim($emailaddress);
    $emailaddress addslashes($emailaddress);
    $subject trim($subject);
    $subject addslashes($subject);
    $date trim($date);
    $message trim($message);
    $message addslashes($message);
    $companyname trim($companyname);
    $companyname addslashes($companyname);
    $contact_detail_title trim($contact_detail_title);
    $firstname trim($firstname);
    $firstname addslashes($firstname);
    $lastname trim($lastname);
    $lastname addslashes($lastname);
    $jobtitle trim($jobtitle);
    $jobtitle addslashes($jobtitle);
    $address trim($address);
    $address addslashes($address);
    $city trim($city);
    $city addslashes($city);
    $zipcode trim($zipcode);
    $zipcode addslashes($zipcode);
    $state trim($state);
    $state addslashes($state);
    $country trim($country);
    $website trim($website);
    $ipaddress trim($ipaddress);

    // Set the variables for the database.

    $Host "localhost";
    $User "";
    $Password "";
    $DBName "";

    $Link mysql_connect ($Host$User$Password);
    $Query "INSERT INTO inquiry_tracking (toname, from, subject, message, companyname, title, firstname, lastname, jobtitle, address, city, zipcode, state, country, website, date, ipaddress) VALUES ('$toname', '$from', '$subject', '$message', '$companyname', '$contact_detail_title', '$firstname', '$lastname', '$jobtitle', '$address', '$city', '$zipcode', '$state', '$country', '$website', '$date', '$ipaddress')";
    echo 
    "<p></p>";

    if (
    mysql_db_query ($DBName$Query$Link)) {
        echo 
    "Success\n";
    } else {
        echo 
    'An error occured while updating the db: ' mysql_error();
    }

    mysql_close ($Link);

    ?>
    Line 25:
    PHP Code:
    $address trim($address); 
    Line 45:
    PHP Code:
    $Query "INSERT INTO inquiry_tracking (toname, from, subject, message, companyname, title, firstname, lastname, jobtitle, address, city, zipcode, state, country, website, date, ipaddress) VALUES ('$toname', '$from', '$subject', '$message', '$companyname', '$contact_detail_title', '$firstname', '$lastname', '$jobtitle', '$address', '$city', '$zipcode', '$state', '$country', '$website', '$date', '$ipaddress')"

  7. #7
    Non-Member Icheb's Avatar
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    1,474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Let's play happy "What is a MySQL reserved word?"-guessing.
    Next word: "from".

  8. #8
    SitePoint Guru
    Join Date
    Sep 2001
    Location
    Vancouver
    Posts
    809
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Icheb
    Let's play happy "What is a MySQL reserved word?"-guessing.
    Next word: "from".
    Geez... and I thought I took a good look at that page. Thank you all!!


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
  •