Jump to content


Photo

Weird Insert Query


  • Please log in to reply
3 replies to this topic

#1 EmperorDoom

EmperorDoom
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 08 August 2006 - 11:17 PM

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?

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 09 August 2006 - 12:06 AM

You need to quote the date string -- otherwise, you get math.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 EmperorDoom

EmperorDoom
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 09 August 2006 - 12:51 AM

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?

#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 09 August 2006 - 01:18 AM

I'm not familiar with PHP at all, but the logic would require comparing the submitted value to the previously stored value.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users