Question

I'm working on a prepared statement that continuously returns false.

$db = dblogin();
$stmt = $db->prepare("INSERT INTO `tor_request` `name`,`sdate`,`edate,`reason`,`comment` VALUES (?,?,?,?,?)");

echo var_export($stmt,true);
//$stmt->bind_param('siiss',$_POST['name'],$_POST['sdate'],$_POST['edate'],$_POST['reason'],$_POST['comment']);
//$result = $stmt->execute();

The dblogin works everywhere, and it has been EXTENSIVELY tested. I just can not find the error in this one statement. It keeps returning false over and over and over. I've commented out the bind_param and the $result because I can't get past the prepare. It's not an Object. Any ideas? Been stuck at this one line for HOURS

Was it helpful?

Solution

You are not wrapping your columns inside brackets, plus you're missing a backtick around edate

$db = dblogin();
$stmt = $db->prepare("INSERT INTO `tor_request` (`name`,`sdate`,`edate`,`reason`,`comment`) VALUES (?,?,?,?,?)");

echo var_export($stmt,true);

Add error reporting to the top of your file(s) which will help during production testing.

error_reporting(E_ALL);
ini_set('display_errors', 1);

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

Error reporting related links:

OTHER TIPS

"INSERT INTO `tor_request` (`name`,`sdate`,`edate`,`reason`,`comment`) 
VALUES (?,?,?,?,?)"

PS: Named parameters are so much easier to read. The more text you have THE BETTER.

"INSERT INTO `tor_request` (`name`,`sdate`,`edate`,`reason`,`comment`) 
VALUES (:name,:startDate,:endDate,:reason,:comment)"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top