我试图让它自动将文本插入到SQL表行

时间:2015-06-05 06:46:50

标签: php mysql mysqli

它一直显示此错误

错误:UPDATE帐户SET basic = WHERE username ='Admin'; 您的SQL语法有错误;检查与MySQL服务器版本对应的手册,以便在第1行的'WHERE username ='Admin''附近使用正确的语法

<?
session_start();
?>

<?php
$servername = "xxx";
$username = "xxx";
$password = "xxx";
$dbname = "xxx";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$user = $_SESSION["sess_user"];
$sql = "UPDATE accounts SET basic = WHERE username = $user ";

if ($conn->query($sql) === TRUE) {
    header("Location: member.php");
} 
else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?>

1 个答案:

答案 0 :(得分:1)

$sql = "UPDATE accounts SET basic = WHERE username = $user ";

将此更改为

$sql = "UPDATE accounts SET basic="value"  WHERE username = $user ";

在=

之后你没有给出任何价值

<强>编辑

$sql="update accounts set fraternity='basic' where username = '".$user."'";