View Full Version : INSERT INTO not working??

08-12-2007, 09:08 AM
hello all.
I have this mySQL/php code that basicly inserts a textarea in a mySQL table:

<form name="write" method="post" action="<?php echo $_SERVER['PHP_SELF']."?t=".$_GET['t']."&u=".$_GET['u']; ?>">
<label> write new<br>
<table border="0" cellspacing="0" cellpadding="0">
<?php if($_SESSION['logged'] !== true){echo'<tr>
<td><label>Name </label></td>
<input type="text" name="name" id="name">
<td><textarea name="writearea" id="writearea" cols="45" rows="5"></textarea></td>
<input type="submit" name="submit" id="submit" value="Submit">
$datetime = date("y-m-d h:i:s");
if($_SESSION['logged'] !== true){
if(!isset($_POST['name'])){ $_POST['name'] = 'Anonymous';}
mysql_query("INSERT INTO replies (SecretID, Name, User, Reply, DateTime)
VALUES ('$user', '$_POST[name]', '$_SESSION[username]', '$_POST[writearea]', '$datetime',)");
echo"$user - $_POST[name] - $_SESSION[username] - $_POST[writearea] - $datetime<br />";

theres gotta be something wrong! I mean, the variables work as well as the arrays, but nothing is inserted into the database.

By the way, the mySQL connection lines are in the script, I just didn't post them here.

And this form is inclued in this code (as form_msg.php ):

if($_GET['t'] == staff){
$user = $_GET['u'];
$checkuser = mysql_query("SELECT * FROM users WHERE ID='$user' and IsStaff=1 ;");
$userfetch = mysql_fetch_array($checkuser);
$queryreplies = mysql_query("SELECT * FROM replies WHERE SecretID='$user' ;");
if($_SESSION['isstaff'] == true)
if ($userfetch !== false){
echo 'Welcome on '.$userfetch['Name'].'\'s page<br />';
while($fetchreplies = mysql_fetch_array($queryreplies)){
echo $fetchreplies['Name'].", on ".$fetchreplies['DateTime'].".<br />";
echo "wrote".$fetchreplies['Reply']."<br />";

08-12-2007, 09:19 AM
There is an extra coma at the end of the list of values. If you had some error checking and error reporting on your mysql_query() function call, PHP/mysql would have alerted you about this syntax error.

08-12-2007, 08:00 PM
arf, thanks, pretty stupid error I did.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum