Urg, I will so happy when I'm finished this project, I feel like I'm spamming you guys every couple of days.

So I have a couple date values in my tables. And I'm trying to do some calculations with them. Which are working fine. But I'm retuning the number of days between two dates and I need to insert that into a table. The value in the table is an interger and I think this is why I'm getting a syntax error. My syntax is correct if I copy the query over to the console and replace the php variables with arbitrary values so I know it the query is structured correct at least.

$curDate = new DateTime();
$query = "SELECT * FROM checkout WHERE dueDate < CURDATE() and cardNumber = '$cardNumber'";
$result = mysql_query($query) or die(mysql_error());
$lateBooks=mysql_numrows($result);
if($lateBooks == 0){
	echo "There are no fines on this account";
}
if($lateBooks > 0){
	$i=0;
	while($i<$lateBooks){
		$finePerDay = 0.15;
		$dueDate = mysql_result($result, $i, "dueDate");
		$bookDue = new DateTime($dueDate);
		$libraryID = mysql_result($result, $i, "libraryID");
		$interval = $bookDue->diff($curDate);
		$daysLate = $interval->d;
		$fines = "INSERT INTO fines VALUES('$libraryID','$cardNumber','$daysLate'";
		$result = mysql_query($fines) or die(mysql_error());
		$fine = $daysLate * $finePerDay;
		$i++;
	}
}

It craps out on the $fines query and I believe it has to do with the $daysLate variable not matching with the int(64) value it should be passed. I've tried casting $daysLate as an int but that doesn't seem to help.

It might be that that's not the problem, but there's a missing ) at the end of the query.
What does var_dump($daysLate); say?

commented: nice spot +15

oh lololol. Clearly I have been looking at this stuff for far too long today to not have noticed that. Having added in the offending bracket it now works fine. Thanks so much.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.