Jump to content

Insert Into Table


smithmr8

Recommended Posts

This is supposed to Add an update to a mysql Table called 'Updates'. The fields are 'date' and 'update'.

Update is filled with the update text from the $_POST

Date is filled with the time/date at that point.

 

My problem is that its not inserting anything into the table. It appears to work, yet doesn't insert anything.

 

Can you help ?

 

<b>Add Update</b><br>
<center><form method="POST" action="area1.php?step=add">
Update Content<br>
  <textarea rows="3" name="update" cols="40"></textarea><br>
<input type="submit" value="Add" name="B1">
</form></center>
<?php 
if($_GET['step'] == 'add'){
$updatecontent = $_POST['update'];
$date = date("d/m H:i:sA");


$sql = "INSERT INTO `updates` (date, update) VALUES ('$date', '$updatecontent')";
mysql_query($sql);
echo "<center>Update Added Successfully</center>";
}
?>

Link to comment
Share on other sites

I endeavour to say your date format is probably wrong. Default date format for MySQL is YYYY-MM-DD. If you are using a date or datetime or timestamp column this query will fail due to format. So i think you should be doing this:

 

$date = date("Y-m-d");

Link to comment
Share on other sites

<?php 
if($_GET['step'] == 'add'){
$updatecontent = $_POST['update'];
$thedate = date("d/m H:i:sA");


$sql = "INSERT INTO `updates` (`date`, update) VALUES ('$thedate', '$updatecontent')" or die(mysql_error());
mysql_query($sql);
echo "<center>Update Added Successfully</center>";
}
?>

 

I've got this now, but its still not working. Tried the backsticks. Tried changing the field name.

Link to comment
Share on other sites

Oh.. I see. I put that in and received this error.

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'update) VALUES ('18/02 18:18:23PM', '55')' at line 1

 

With Query

INSERT INTO `updates` (`thedate`, update) VALUES ('18/02 18:18:23PM', '55')

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.