Page 1 of 1

Adding to SQL DB

Posted: Thu Jan 22, 2004 3:48 pm
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

Posted: Thu Jan 22, 2004 3:51 pm
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()); 

?>

Posted: Thu Jan 22, 2004 4:01 pm
by eludlow
Sorted it - MANY thanks.

Ed