从PHP表单更新MYSQL中的行

时间:2016-09-08 02:52:33

标签: php mysql

我想要做的事情的概述:我的数据库中有一个名为代理的表,表中的一列称为activated。我希望能够输入代理用户名(代理表中的第1行),然后将activated列中的行更新为1 (instead of the default of 0 which identifies the user as not activated)。我明显错了,有人可以指出哪里?谢谢大家的时间。

<?php
error_reporting(E_ALL & ~E_NOTICE);
session_start();
if (isset($_SESSION['id'])){
$userId = $_SESSION['id'];
$username = $_SESSION['username'];
} else {
header('Location: home.php');
die();
}
?>
<?php
if($_POST['submit']){
include_once("connection.php");
$username = strip_tags($_POST['username']);
$sql = "SELECT username, FROM agents WHERE username = '$username'";
$query = mysqli_query($dbCon, $sql);
if ($query) {
$row = mysqli_fetch_row($query);
$dbUsername = $row[1];
}
?>
<?php
$dbUsername = $row[1];
if ($username == $dbUsername){
$sql2 = "UPDATE agents SET activated ='1' WHERE $username = username";
$query2 = mysqli_query($dbCon, $sql2);
header('Location: userstaff.php');
} else {
echo "Problem detected.";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Activate agent</title>
</head>
<body>
<h1> Activate agent </h1>
<form method="post" action="activateagent.php">
<input type="text" placeholder="Username" name="username" />
<input type="submit" name="submit" value="activate" />
</form>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

您的选择查询中有额外的逗号(,)

$sql = "SELECT username, FROM agents WHERE username = '$username'";