Ron Piggott (PHP) wrote:
If I give this command through PHP to mySQL

@mysql_select_db($database) or die( "Unable to select database");
$query = "UPDATE `table` SET `last_activity_field` = '$current_date'
WHERE `reference` = '$account_reference' LIMIT 1;";

is there a way to know if it executed successfully?

Two ways.


$result = mysql_query($query);
if (!$result) {
  echo "Bad Query or something!: " . mysql_error() . "<br/>";

will tell you quickly whether the query worked at all.

Secondly will tell you how many rows that query changed.

Lastly I hope that's just an example otherwise you will have problems with sql injection.

You can either validate your data before (ie make sure current_date only contains what you expect) or change

$query = "UPDATE `table` SET `last_activity_field` = '$current_date'
WHERE `reference` = '$account_reference' LIMIT 1;";

to use either mysql_escape_string or mysql_real_escape_string:

$query = "UPDATE `table` SET `last_activity_field` = '" . mysql_escape_string($current_date) . "' WHERE `reference` = '" . mysql_escape_string($account_reference) . "' LIMIT 1;";

Depending on which version of php you have (RTM).

Postgresql & php tutorials

PHP Database Mailing List (
To unsubscribe, visit:

Reply via email to