我有一个表格应该检查发布的字段并逐步更新sql表中的相关行,即每次都应该增加该数字。我已经尝试了几种不同的方法,但无法让这个工作 - 任何帮助赞赏。
if(!empty($_POST['username']))
{
$username =($_POST['username']);
mysql_query("
UPDATE users
SET refer = refer +1
WHERE Username = '".$username."'
");
}
答案 0 :(得分:0)
我建议你使用php 7和PDO,mysql_query已经过时了:
做类似的事情:
$pdo = new PDO('mysql:host=localhost;dbname=database', 'user', 'password');
if (!empty($_POST['username'])) {
$stmt = $pdo->prepare("UPDATE users SET refer = :refer WHERE Username = :username");
$stmt->execute([
'refer' => refer + 1,
'username' => $_POST['username']
]);
}