Page 1 of 1

Information won't insert into mysql! Eeeeeeeeek!

Posted: Sat Oct 26, 2002 2:56 pm
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

query

Posted: Sat Oct 26, 2002 3:35 pm
by phpScott
Try echo ing out your query
<?php
echo $Insert;
?>
To see what your query is? It could be an empy query.

phpScott

~!~#@~#!

Posted: Sat Oct 26, 2002 3:45 pm
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

Re: ~!~#@~#!

Posted: Sat Oct 26, 2002 4:55 pm
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'";

...?

Posted: Sat Oct 26, 2002 5:05 pm
by Tom
Still doesn't work!

Ahhhhhh!

if query is right

Posted: Sat Oct 26, 2002 6:55 pm
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

Posted: Sat Oct 26, 2002 9:42 pm
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)

Posted: Sat Oct 26, 2002 9:47 pm
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.