Page 1 of 1

Something stopping data entering mysql db

Posted: Mon Jan 17, 2011 2:55 pm
by blade_922
Hi,

I cant seem to find what it is, I've tried everything but the data is echo'ing out okay on the page but it wont insert into my db. I've checked the db connection, that is fine also no typo's that i can see.

HELP :banghead: :banghead:

Code: Select all

<?php include('db.php'); ?>


<?php
$title=$_POST['title'];
$date=$_POST['date'];
$content=$_post['content'];

$date = date('M j, Y H:i', strtotime($date));

?>

<?php
$query="INSERT INTO ccms_news (title, date, content, timestamp) VALUES ('$title', '$date', '$content', 'UNIX_TIMESTAMP($date)')";
mysql_query($query);
echo "Record Updated";

echo $id;
echo '</br>';
echo $title;
echo '</br>';
echo $date;
echo '</br>';
echo '<a href="index.php">CLICK TO CONTINUE</a>';
?>

Re: Something stopping data entering mysql db

Posted: Mon Jan 17, 2011 3:22 pm
by spedula
Try doing this:

Code: Select all

$result= mysql_query($query)or die(mysql_error());
It should tell you if there is something wrong with your SQL syntax. If you can't figure it our, post the results.

Re: Something stopping data entering mysql db

Posted: Mon Jan 17, 2011 3:27 pm
by bigjoe11a
Blade, Since you lack in giving code to just what your doing, Try this below. It's a small sample and should help, I use this same code and have been for the last 4 years,

Code: Select all

$con = mysql_connect("localhost","root","rootwdp");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("my_db", $con);

$sql="INSERT INTO person (FirstName, LastName, Age)
 VALUES ('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";

mysql_close($con);
This code has been testing and it does work.