Something stopping data entering mysql db

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
blade_922
Forum Contributor
Posts: 132
Joined: Wed Jul 12, 2006 4:57 pm

Something stopping data entering mysql db

Post 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>';
?>
User avatar
spedula
Forum Commoner
Posts: 81
Joined: Mon Mar 29, 2010 5:24 pm

Re: Something stopping data entering mysql db

Post 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.
bigjoe11a
Forum Newbie
Posts: 9
Joined: Mon Jan 17, 2011 2:57 pm
Location: Ohio, USA
Contact:

Re: Something stopping data entering mysql db

Post 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.
Last edited by Benjamin on Mon Jan 17, 2011 4:16 pm, edited 1 time in total.
Reason: Added [syntax=php] tags.
Post Reply