Jump to content

Weird Insert Query


EmperorDoom

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?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.