attempting to insert row into file

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
hipgecko
Forum Newbie
Posts: 2
Joined: Fri Sep 27, 2002 12:21 am

attempting to insert row into file

Post by hipgecko »

here's my code

Code: Select all

$query = "INSERT INSERT INTO 'calendar' ('number', 'date', 'time', 'title', 'details', 'user', 'timestamp') VALUES ('0', '".$date."', '".$time."', '".$title."', '".$details."', '".$user."', '".$timestamp."')";
    $result = mysql_query($query) or die("Attempt to add record to calendar file failed.");
all i get when attempting to execute the statement is the die error message...

this is my first attempt at using php to process forms... does my syntax look correct?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Firstly try changing your die statement to:

Code: Select all

die(mysql_error().'<p>'.$query.'</p>');
this will give you a more useful error message. As for your syntax, take a look at this:
http://www.mysql.com/doc/en/INSERT.html

Without looking too hard I can see that you have INSERT written twice so if that isn't a typo from when you posted in the forum I'd reduce it down to one.

Mac
User avatar
hipgecko
Forum Newbie
Posts: 2
Joined: Fri Sep 27, 2002 12:21 am

ooops

Post by hipgecko »

after readying the reply, then checking my code, all i could do is go :o

thanks for pointing out the extra INSERT statement... i was so focused on the double quotes, single quotes, etc... that i completely missed that!

it's working now, and the error message thingy helped too! thanks a bunch!!!

fyi... new code that works:

Code: Select all

$query = "INSERT INTO calendar (number, date, time, title, details, user, timestamp) VALUES ('0', '".$date."', '".$time."', '".$title."', '".$details."', '".$user."', '".$timestamp."')";
    mysql_query($query) or die(mysql_error().'<p>'.$query.'</p>');
Post Reply