Reputation: 1601
I want to get the value of specified field(it's INT) then increment this value and then update this in mysql. I tried this but it doesn't work. I'am completely green in MySQL.
$attempts = mysql_fetch_array(mysql_query("SELECT attempts FROM employees WHERE lastname='$lastname'"));
mysql_query("UPDATE employees SET attetmps='$attemtps++' WHERE lastname='$lastname'");
Upvotes: 0
Views: 744
Reputation: 809
if you want to use mysql_fetch_array
you should know it returns an array and not one value
so try this
<?php
$query = mysql_query("SELECT attempts FROM employees WHERE lastname='$lastname'");
$row = mysql_fetch_array($query, MYSQL_ASSOC);
$attempts = $row['attempts'] + 1;
mysql_query("UPDATE employees SET attempts='$attempts' WHERE lastname='$lastname'");
?>
or use one query.. you do not need to do two queries
mysql_query("
UPDATE employees
SET attempts = attempts + 1
WHERE lastname = '".$lastname."'
");
Upvotes: 3
Reputation: 1539
UPDATE employees SET attempts = attempts + 1 WHERE lastname = '$lastname'
Upvotes: 2
Reputation: 540
I suggest:
mysql_query("UPDATE employees SET attempts = attempts + 1 WHERE lastname = '".$lastname."'");
Upvotes: 3