#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Norcross, GA
    Posts
    458
    Rep Power
    15
    $addnewbike = "INSERT INTO spec (model, year), VALUES ('$model','$year')";

    $result = mysql_query($addnewbike,$db);

    if (!$result) { print notice of insertion failure }

    For the last hour and a half I've looked at this code and can't seem to see what is wrong. Am I missing something here?

  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    Canada
    Posts
    35
    Rep Power
    15
    how many columns do you have in your database "spec"?
    if you only have two (model, year):
    $addnewbike = "INSERT INTO spec, VALUES ('$model','$year')";

    if you have more than two and want to insert only two values you have to declare the others as NULL:
    for ex, if "spec" has 4 columns (color, model, year, price):
    $addnewbike = "INSERT INTO spec, VALUES ('NULL, '$model', 'NULL', '$year')";

    when i run into some similar problems I always check my query in SQL directly to figure out whether the error comes from SQL or PHP...
    Hope this helps!
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    Canada
    Posts
    35
    Rep Power
    15
    I made one typo:
    remove the comma ',' after 'spec':

    $addnewbike = "INSERT INTO spec VALUES ('$model','$year')";

    (same for the other statement)
  6. #4
  7. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    Perth West Australia
    Posts
    757
    Rep Power
    15
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>$addnewbike = "INSERT INTO spec (model, year), VALUES ('$model','$year')";[/quote]

    The only thing wrong with the above statement is the extra comma ...year),< here

    Your SQL query will work without quotes and you do not need to specify NULL values.

    You do not say if you get an error message or if the insert just does not insert anything? -

    If you receive no errors but the insert appears to fail then you probably are submitting the wrong data types to the DB, ie an string value into an Integer field.

    ------------------
    Simon Wheeler
    FirePages -DHTML/PHP/MySQL
  8. #5
  9. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    Simon is correct. gac and Ryan P are pointing you in the wrong direction.

    As an addendum to Simon's post, if you aren't getting errors but the data isn't inserting, you may have a required field in the table other than model and year for which you'll need to specify a value as well.

Similar Threads

  1. Nested insert help
    By mrras25 in forum MySQL Help
    Replies: 2
    Last Post: February 4th, 2004, 04:00 PM
  2. Replies: 1
    Last Post: January 30th, 2004, 06:04 PM
  3. Question about the WHERE statement
    By layz d in forum MS SQL Development
    Replies: 5
    Last Post: January 28th, 2004, 11:58 AM
  4. wildcard in grant statement
    By emeraldstudio in forum MySQL Help
    Replies: 4
    Last Post: January 23rd, 2004, 01:26 PM
  5. insert statement problem IMPORTANT
    By corillio in forum Oracle Development
    Replies: 2
    Last Post: January 22nd, 2004, 02:35 PM

IMN logo majestic logo threadwatch logo seochat tools logo