dongzen2675 2016-09-08 02:52
浏览 17

从PHP表单更新MYSQL中的行

Outline of what I'm trying to do: I have a table in my db called agents , one of the columns in the table is called activated. I want to be able to enter the agents username (row 1 in the agents table) and then have the row within the column for activated update to a 1 (instead of the default of 0 which identifies the user as not activated). I'm clearly going wrong, can someone point out where?? Thank you all for your time.

<?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条回答 默认 最新

  • dph58509 2016-09-08 03:01
    关注

    you have an extra comma(,) in your select query

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

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题