Why does this while loop not update my mysql query?
I'm still new to writing querys to mysql, so I'm sure it is a newbie mistake, but I can't figure it out.
Here is the code (with lots of echos so I can show my output):
while($row = mysql_fetch_array($tempresult, MYSQL_ASSOC)){
$tempStartDate = $StartDate;
$tempEventID = $row['EventID'];
$tempDaysFromEvent = $row['DaysFromEvent'];
echo "Main Event Start Date: ".$tempStartDate."<br>";
echo "EventID: ".$tempEventID.", Start Date: ".$tempStartDate.", Days From Event: ".$tempDaysFromEvent.", Parent Event ID: ".$tempParentEventID."<br>";
$newtempStartDate = explode(" ", $tempStartDate);
echo "New Temp Start Date: ".$newtempStartDate[0];
echo "<br>";
list($year, $month, $day) = explode("-", $newtempStartDate[0]);
echo $year." ". $month. " ". $day;
echo "<br>";
$tempStartDate = $tempEndDate = date("Y-m-d", mktime(0,0,0,$month,($day+$tempDaysFromEvent),$year)) . " 00:00:00";
echo "TempStart Date:".$tempStartDate."<br>";
mysql_query("UPDATE".$eventDatabase." SET StartDate='$tempStartDate',EndDate开发者_开发问答='$tempEndDate'where EventID ='$tempEventID'");
error_reporting(E_ALL);
}
Here is my output:
Main Event Start Date: 2011-07-04 15:00:00
EventID: 4876, Start Date: 2011-07-04 15:00:00, Days From Event: 4, Parent Event ID: 4865
New Temp Start Date: 2011-07-04
2011 07 04
TempStart Date:2011-07-08 00:00:00
The output looks correct to me-it looks like I want it to look in the db. I don't know if the issue is because $tempStartDate is a string? It is a datetime in mysql, but that shouldn't matter I don't think??
As noted in the comment above, it appears that you are missing spaces in your SQL statement. Replace your mysql_query()
call with this:
mysql_query("UPDATE $eventDatabase SET StartDate='$tempStartDate', EndDate='$tempEndDate' WHERE EventID='$tempEventID'");
When in doubt, you can always assign the SQL query to a string variable first, and echo the string so that you can see the full SQL statement, including variable values.
Try echoing the actual sql command. Looks like you need a space there after the "UPDATE" and before 'where EventID= xxx";
Try and execute the actual output from echo in SQL admin page.
精彩评论