Can't insert data with PDO [Branched from: Insert and Update Server Behaviors in the Same Form]
I feel as if I'm fighting my way around a paper bag trying to insert a record. I've recently converted from MySQL to PDO, which may not be relevant. I'm not trying to write some data update routines, and have started with insert. I've tried the example in your PHP Solutions Edition Two, pp 361-363 but I can't get a record written.
This is a database I've maintained from the host server using phpMyAdmin. I'm displaying the data on the site just fine, so I assume my connection script is ok. However, nothing I've tried has gotten an insert recorded. I've tried going back to basics, and it still doesn't work. This is my current code. Something is wrong with my $sql= statement, and I can't identify the problem. Please help!
if (isset($_POST['insert'])) {
try {
// create SQL
$sql = "INSERT INTO Homepage_text (textpage, h_date, h_seq, h_col, p_heading, p_text, h_hide) VALUES ($_POST['textpage'], $_POST['h_date'], $_POST['h_seq'], $_POST['h_col'], $_POST['p_heading'], $_POST['p_text'], $_POST['h_hide'])";
$sainttim->execute($sql);
echo 'New record created successfully';
}
catch(PDOException ($e)
{
echo $sql. "<br />". $e->getMessage();
}
}
