James
James

Reputation: 13

MYSQL - How to update a value?

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');

Upvotes: 0

Views: 43

Answers (3)

user2256291
user2256291

Reputation:

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.

Upvotes: 0

Manwal
Manwal

Reputation: 23816

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

Upvotes: 1

Jens
Jens

Reputation: 69440

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

Upvotes: 1

Related Questions