Jump to content

Archived

This topic is now archived and is closed to further replies.

EmperorDoom

Weird Insert Query

Recommended Posts

Hey all, I'm using PHP 5.something and I've dealt with many debugging issues by myself before, but this problem I just don't see the solution. Hopefully you can help.
I'm trying to write a variable to a new row in a mysql table only if that variable doesn't already exist. (pretty simplistic)
I've written the part that checks an array returned from the table to see if the variable exists, this part works fine :)
Now I have an else statement that looks like this
else {
$doquery = "INSERT into $table(date,Per1,Per2,Per3,Per4,Per5,Per6,Per7,Per8) VALUES($wheredate,0,0,0,0,0,0,0,0)";
$result=mysql_query($doquery) or die("INSERT FAILED");
$updatequery = "UPDATE $table SET Per1=1 WHERE date=$wheredate";
$result = mysql_query($updatequery) or die("UPDATE FAILED");
$centre .= $periodone[$i]." is not in the array with ".$wheredate."|| ";
}
$periodone is an array with different dates (format yyyy-mm-dd)
$wheredate is the current date the program is working with it is set to $year."-".$month."-".$periodone[$i]
BTW I know I could do the whole INSERT and UPDATE in one query but i broke it up on purpose.
The weird thing is: the output ($centre) displays 24 is not in the array with 2006-08-24 so i know the variable $wheredate is correct but when I check the DB the value in the date field is: "1974" without quotes. where the heck is this number coming from? and what's wrong with my script? Thanks for any input on this.

*EDIT*
Umm.. i just checked it using a different date, the 11 of august and the value in the date field was 1987 which leads me to believe that the $wheredate is somehow subtracting 08 and 11 from 2006 but why? it's a string right?

Share this post


Link to post
Share on other sites
You need to quote the date string -- otherwise, you get math.

Share this post


Link to post
Share on other sites
Thanks! that worked. I now have a second question which is actually more PHP than mysql but any idea how to get an array of checkboxes from a form that were unchecked? not just left unchecked but actually have the check removed before the form submitted?

Share this post


Link to post
Share on other sites
I'm not familiar with PHP at all, but the logic would require comparing the submitted value to the previously stored value.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.