I have a mysql db i'm trying to post a form to and can't seem to get past my validation code. I've checked over the $insertQuery and don't see any errors that stand out in that code.db name is correct, field names are correct and in the same order as my table. But this is where the problem has to be. I am connecting to my db and posting fine with other forms on the site. Anyone have any ideas?
Heres my //REVISED// code
Code: Select all
<?php
error_reporting(E_ALL);
// Get the PHP file containing the DbConnector class
require_once('includes/DbConnector.php');
require_once('includes/Validator.php');
// Create an instance of DbConnector
$connector = new DbConnector();
// Check whether a form has been submitted. If so, carry on
if ($HTTP_POST_VARS){
// Validate the entries
$validator = new Validator();
$validator->validateGeneral($HTTP_POST_VARSї'title'],'title');
$validator->validateTextOnly($HTTP_POST_VARSї'affiliate_name'],'affiliate_name');
$validator->validateGeneral($HTTP_POST_VARSї'pkg_type'],'pkg_type');
$validator->validateTextOnly($HTTP_POST_VARSї'departure'],'departure');
$validator->validateTextOnly($HTTP_POST_VARSї'destination'],'destination');
$validator->validateTextOnly($HTTP_POST_VARSї'hotel'],'hotel');
$validator->validateGeneral($HTTP_POST_VARSї'nights'],'nights');
$validator->validateGeneral($HTTP_POST_VARSї'price'],'price');
$validator->validateGeneral($HTTP_POST_VARSї'desc'],'desc');
// Check whether the validator found any problems
if ( $validator->foundErrors() ){
echo 'There was a problem with: <br>'.$validator->listErrors('<br>'); // Show the errors, with a line between each
}else{
// Create an SQL query (MySQL version)
// The 'addslashes' command is used 5 lines below for added security
// Remember to use 'stripslashes' later to remove them (they are inserted in front of any
// special characters
$insertQuery = "INSERT INTO cmshotdeals (title,affiliate_name,pkg_type,departure,destination,hotel,nights,price,desc) VALUES (".
"'".addslashes($HTTP_POST_VARSї'title'])."', ".
"'".$HTTP_POST_VARSї'affiliate_name']."', ".
"'".addslashes($HTTP_POST_VARSї'pkg_type'])."', ".
"'".$HTTP_POST_VARSї'departure']."', ".
"'".$HTTP_POST_VARSї'destination']."', ".
"'".$HTTP_POST_VARSї'hotel']."', ".
"'".$HTTP_POST_VARSї'nights']."', ".
"'".addslashes($HTTP_POST_VARSї'price'])."', ".
"'".addslashes($HTTP_POST_VARSї'desc'])."')";
echo $insertQuery;
// Save the form data into the database
if ($result = $connector->query($insertQuery)){
// It worked, give confirmation
echo '<center><b>Hot Deal added to the database</b></center><br>';
}else{
// It hasn't worked so stop. Better error handling code would be good here!
exit('<center>Sorry, there was an error saving to the database</center>');
}
}
}
?>