Adding to SQL 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
eludlow
Forum Newbie
Posts: 13
Joined: Thu Jan 22, 2004 3:48 pm

Adding to SQL DB

Post by eludlow »

I've got a VERY simply script with which I wish to add some data to a DB. As far as I can see, it should work - any ideas why it's not?!

<?php
$connection = mysql_connect ("myhost", "ed", "mypassword");
$date = date("F j, Y");
$confirmednewtoadd = $_POST['confirmednewtoadd'];
$table = "xanews";

$addToDB = "Insert into $table(date, newsitem) values('$date', '$confirmnewtoadd')";


mysql_query($addToDB, $connection);

?>

Thanks,
Ed Ludlow
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Add some debugging/error checking ...

Code: Select all

<?php
error_reporting(E_ALL); 
$connection = mysql_connect ('myhost', 'ed', 'mypassword') or die(mysql_error()); 
$date = date('F j, Y'); 
$confirmednewtoadd = $_POST['confirmednewtoadd']; 
$table = "xanews"; 

$addToDB = "Insert into $table(date, newsitem) values('$date', '$confirmnewtoadd')"; 

echo $addToDB; //to check it's what you expect it to be
mysql_query($addToDB, $connection) or die(mysql_error()); 

?>
eludlow
Forum Newbie
Posts: 13
Joined: Thu Jan 22, 2004 3:48 pm

Post by eludlow »

Sorted it - MANY thanks.

Ed
Post Reply