GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Mysql $query = Update $variable field quick php question (https://gfy.com/showthread.php?t=943887)

mkx 12-17-2009 02:47 AM

Mysql $query = Update $variable field quick php question
 
First time using the update command.

Basically trying to change the status from 1 to 2 which works with this query without the $id variable I inserted. Anyone know how I format the $id variable properly in this query?


mysql_select_db($mysql);
$query = 'UPDATE `sms`.`messages_import` SET `timestamp` = NOW(), `status` = \'2\' WHERE `messages_import`.`id` = `"$.id."` LIMIT 1;';


Again I tried a few common variations that I knew of like $id, '$id', etc but nothing seemed to work :(

Mucho appreciatedo

grumpy 12-17-2009 02:48 AM

Code:


mysql_select_db($mysql);
$query = 'UPDATE `sms`.`messages_import` SET `timestamp` = NOW(), `status` = \'2\' WHERE `messages_import.id` = `".$id."` LIMIT 1;';

its ".$id."

mkx 12-17-2009 03:17 AM

Quote:

Originally Posted by grumpy (Post 16655131)
Code:


mysql_select_db($mysql);
$query = 'UPDATE `sms`.`messages_import` SET `timestamp` = NOW(), `status` = \'2\' WHERE `messages_import.id` = `".$id."` LIMIT 1;';

its ".$id."

Thanks :) got it working with '.$id.'

darksoul 12-17-2009 03:30 AM

thats a pretty fugly style with all those escapes. The only escape you need is for timestamp which is a reserved keyword
Code:

$query = "UPDATE sms.messages_import SET `timestamp` = NOW, status=2 WHERE messages_import.id=$id";
You also don't need LIMIT 1, since the id is unique (in most cases anyway)

redwhiteandblue 12-17-2009 06:51 AM

When you are running queries you're not sure of, always use this format for the query call (assuming you're using the old style mysql calls):

$result = mysql_query($query) or die(mysql_error() . ", query was $query");

Then not only can you see what the error was, you can see why the query string caused it.


All times are GMT -7. The time now is 09:11 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2026, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123