Jump to content

Error inserting data into table


nloding

Recommended Posts

I'm just trying to insert some form data into my table.  I am successfully connection to the database.  The table name is "pieces".  It has the following fields in the following order:

id / title / auth / pages / genre / format / desc / time / filename

id is auto_incremented, time is using the NOW() feature, so I'm putting data into the other fields.  Here's my code:

[code]
//insert them variables into that there db
$query = "INSERT INTO pieces (title, auth, pages, genre, format, desc, filename) VALUES ('$title', '$author', '$pages', '$genre', '$format', '$desc', '$file')";
$result = $mysqli->query($query);

//check to make sure the result is true
if($result) {
echo "<p><span class=\"bold\"><u>Upload was successful!</u> ".$title." is now part of the library!</span></p>\n";
}
else {
echo "<p>Something went wrong: ".$mysqli->error."</p>";
exit;
}
[/code]

And here's the error I get:

[quote]Something went wrong: 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 'desc, filename) VALUES ('Test 4', 'Test 4', '4', 's_nonfiction', 'word', 'Test t' at line 1[/quote]

I've double-checked all the spellings, variable names, and usage of apostrophes, and all seems to be in order.  What am I missing?

PS: Why isn't my code all colorful and exciting!?
Link to comment
Share on other sites

[code]
<?php

//insert them variables into that there db
$result = mysql_query( "INSERT INTO pieces (title, auth, pages, genre, format, desc, filename) VALUES ('$title', '$author', '$pages', '$genre', '$format', '$desc', '$file')");


//check to make sure the result is true
if($result) {
echo "<p><span class=\"bold\"><u>Upload was successful!</u> ".$title." is now part of the library!</span></p>\n";
}
else {
echo "<p>Something went wrong: ".$mysqli->error."</p>";
exit;
}

?>
[/code]
Link to comment
Share on other sites

Thanks poco, but that doesn't help.  I'm using mysqli, and what you typed was the exact same thing I already had except not using mysqli.

So what's wrong with my query?

EDIT: Is it because I skip the id and time fields?  Would adding "NULL" and "NOW()" to the INSERT query itself fix this?  Let's try while I wait for a reply!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.