Information won't insert into mysql! Eeeeeeeeek!

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
Tom
Forum Newbie
Posts: 20
Joined: Sat Oct 05, 2002 5:24 pm
Location: Southwest FL

Information won't insert into mysql! Eeeeeeeeek!

Post by Tom »

Hey all,
I made a form that with the "action" set to post.php.

Here's post.php:

Code: Select all

<?PHP
MySQL_Connect("localhost","Tom","tom") or die("Can''t connect to MySQL Server");
MySQL_Select_Db("news") or die("Can''t select specified database");
$Insert = "INSERT INTO posts VALUES $user, $date, $time, $entry, $title, $id";
MySQL_Query($Insert);
MySQL_Close();
Echo "Information entered into the database";
?>
My problem is when i fill out the form on form.php and click submit, post.php always says "Information entered into the database". So I go over to the command prompt and make sure it's in there by typing "select * from posts;" and it tells me the set it empty. So PHP is telling me it was put into the table, but mysql says it isn't there.

Pleasssseeee Help!

Thanks in advance, - Tom
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

query

Post by phpScott »

Try echo ing out your query
<?php
echo $Insert;
?>
To see what your query is? It could be an empy query.

phpScott
Tom
Forum Newbie
Posts: 20
Joined: Sat Oct 05, 2002 5:24 pm
Location: Southwest FL

~!~#@~#!

Post by Tom »

When i echo the variable $Insert, I get this:

INSERT INTO posts VALUES Tom, Saturday, October 26, 2002, 4:43 PM, asasasasasas, sasasas, null

So i guess that $Insert isn't an empty query.

Thanks anyway 8)

// Edit

Maybe it's the commas in the "Saturday, October 26, 2002" part of the query...what do you think?

-Tom
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Re: ~!~#@~#!

Post by hob_goblin »

Tom wrote:
Maybe it's the commas in the "Saturday, October 26, 2002" part of the query...what do you think?
definantly,
change

Code: Select all

$Insert = "INSERT INTO posts VALUES $user, $date, $time, $entry, $title, $id";
to

Code: Select all

$Insert = "INSERT INTO posts VALUES '$user', '$date', '$time', '$entry', '$title', '$id'";
Tom
Forum Newbie
Posts: 20
Joined: Sat Oct 05, 2002 5:24 pm
Location: Southwest FL

...?

Post by Tom »

Still doesn't work!

Ahhhhhh!
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

if query is right

Post by phpScott »

try doing something like the following

Code: Select all

$result=mysql_query($sql);
 if(!$result)
 &#123;
        $msg=mysql_error();
        echo $msg."error no 111";
  &#125;
if the query doesn' go through correctly then you should see the mysql error as to why.

phpScott
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

http://www.mysql.com/documentation/mysql/bychapter/manual_Reference.html#INSERT
INSERT [LOW_PRIORITY | DELAYED] [IGNORE]
[INTO] tbl_name [(col_name,...)]
VALUES ((expression | DEFAULT),...),(...),...
or INSERT [LOW_PRIORITY | DELAYED] [IGNORE]
[INTO] tbl_name [(col_name,...)]
SELECT ...
or INSERT [LOW_PRIORITY | DELAYED] [IGNORE]
[INTO] tbl_name
SET col_name=(expression | DEFAULT), ...
the brackets are not optional
:arrow: INSERT INTO posts VALUES ('Tom', 'Saturday', 'October 26, 2002', '4:43 PM', 'asasasasasas', 'sasasas', null)
User avatar
cheatboy00
Forum Contributor
Posts: 151
Joined: Sat Jun 29, 2002 10:36 am
Location: canada
Contact:

Post by cheatboy00 »

try something like this

Code: Select all

mysql_query("INSERT INTO `posts` (`user`, `date`, `time`, `entry`, `title`, `id`) VALUES (`$user`, `$date`, `$time`, `$entry`, `$title`, `$id`)");
where (`user`, `date`, `time`, `entry`, `title`, `id`) is your columns in the posts table, that corrispond to the values....

note: you should put the values and columns in the same order they are in in the table.
Post Reply