0

After selecting the record with the current KEY and PROGRAM, I want to update the 'log_info' field for that CURRENT record, inputting the date/time. However, I keep getting the 'die error' for the update code.

ERROR CODE:

"Warning: mysql_query() expects parameter 1 to be string"
(for the "$log_info = mysql_query($query,"UPDATE..." code)

Snippet

$query = mysql_query("SELECT * 
                      FROM `product_keys` 
                      WHERE `serial_key` = '".$key."' 
                          AND `program` = '".$prog."' LIMIT 1") or die('error selecting');

// UPDATE 'log_info' value to the latest date and time
$time = time();
 $log_time = date('Y-m-d g:i:sa',$time);
 $log_info = mysql_query($query,"UPDATE 'product_keys' 
                                    SET 'log_info' = '".$log_time."' 
                                    WHERE `serial_key` = '".$key."' 
                                        AND `program` = '".$prog."' LIMIT 1") or die('log error');
Rajesh
  • 10,318
  • 16
  • 44
  • 64
James
  • 13
  • 1
  • 7
  • please stop using `mysql_*` commands as these are outdated, rather look more into thigns like mysqli – Azrael Sep 24 '14 at 06:44

3 Answers3

1

You have ' around the column name 'log_info' and the table name 'product_keys'. That should be backticks.

Jens
  • 67,715
  • 15
  • 98
  • 113
1

Try this line:

$log_info = mysql_query($query,"UPDATE `product_keys` SET `log_info` = '".$log_time."' WHERE `serial_key` = '".$key."' AND `program` = '".$prog."' LIMIT 1") or die(mysql_error());

Using mysql_error() you can catch specific error of query.

See The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead

Community
  • 1
  • 1
Manwal
  • 23,450
  • 12
  • 63
  • 93
0

update query will be like this

$log_info = mysql_query("UPDATE 'product_keys' 
                         SET 'log_info' = '".$log_time."' 
                         WHERE `serial_key` = '".$key."' 
                         AND `program` = '".$prog."' 
                         LIMIT 1") or die('log error');

because mysql_query function accept 2 Parameters, first Parameter should be sql query , second Parameter is optional that is MySQL connection.

Darshan Lila
  • 5,772
  • 2
  • 24
  • 34
  • Check your answer before posting here. As for me can't se any update in your query and OP's query.. – Manwal Sep 24 '14 at 07:04