Ok, I'm not sure why it's creating a new row in the db. I thought maybe you had the id column set to auto-increment, but I think the query would actually fail if you did that. It might be something to check first anyway...
I tried to mimic what you are trying to do, and below is what I did. It seems to work ok for me.
I set up a test db / table with the following parameters:
--
-- Database: `_test`
--
-- --------------------------------------------------------
--
-- Table structure for table `test_table`
--
CREATE TABLE `test_table` (
`id` int(8) unsigned zerofill NOT NULL auto_increment,
`user_id` varchar(30) NOT NULL default '',
`fm` varchar(50) NOT NULL default '',
`mg` blob NOT NULL,
`last_login` varchar(50) NOT NULL default '',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
(If you're not familiar with this syntax, it can be copied and saved as a text file, then imported into mysql. If you're using phpmyadmin, you would create the database called _test , click the SQL tab and then select the file to import.)
I then drafted test.php page with the following code:
[php]
<?php
//you'll need to modify this line
require '../db_control.php';
echo "Enter some text and then click Insert...
";
?>
User ID:
From:
Message:
<?
if ($_POST['submit']=='Insert') {
$user_id=$_POST['user_id'];
$fm=$_POST['fm'];
$last_login=time();
//clean up the message text
$mg = htmlentities($_POST['mg'],ENT_QUOTES);
$query="INSERT INTO test_table (user_id,fm,mg,last_login) VALUES ('$user_id','$fm','$mg','$last_login')";
echo "This is the query string that would be performed on the db:
".$query."";
echo "Now performing query...
";
mysql_select_db('_test');
$result=mysql_query($query);
if (!$result) {
"There was a problem with your query.";
}
else {
echo "Query performed successfully.
";
echo "This is the last row that was entered in the db:
";
$query2="SELECT * FROM test_table ORDER BY id DESC LIMIT 1";
$result2=mysql_query($query2);
$row = mysql_fetch_assoc($result2);
echo ""; print_r($row); echo "";
}
}
?>
[/php]
I know this code is ugly, but it does the trick for now. I like to get things working first and then pretty up the code later.
The php code will allow you to enter some text, submit the form, and then it will show you the results. If you use the code, remember to change the database name, etc. if needed.