doyrte8419 2012-10-09 21:37
浏览 36
已采纳

通过php表单更新SQL表

Query is running however not being sent to SQL server. My Current Register Script.

$link = mysqli_connect("$server", "$user", "$pass", "$webdb");
$username = mysqli_real_escape_string($link, (string) $_POST['username']);
$displayname = mysqli_real_escape_string($link, (string) $_POST['display_name']);
$email = mysqli_real_escape_string($link, (string) $_POST['email']);
$password = sha1((string) $_POST['password']);
$query="INSERT INTO user (`username`, `nicename`, `email`, `password`)
VALUES ('$username', '$displayname', '$email', '$password', '1')";
mysqli_query($link, $query);
mysqli_close($link);
echo $query;
?>

The output I recieve from the Query:

INSERT INTO user (username, nicename, email, password) VALUES ('orion5814', 'Orion5814', 'my@abc.com', '72f2ac484bee398758e769530dd56228d905884d', '1')

I've checked all my link variables and they're all set correctly as far as having the right information in place, so I don't know where else to go from here. Sorry for all the questions; you can view it at doxramos.org if you think it would help at all.

  • 写回答

3条回答 默认 最新

  • duanhan7001 2012-10-09 21:41
    关注

    The query is flawed. You name 4 columns (username, nicename, email, password), but you list 5 values ('orion5814','Orion5814','my@abc.com','72f2ac484bee398758e769530dd56228d905884d','1') If you remove the last value, the query should work.

    Also, you could simplify your code by using the object oriented interface to mysqli like this:

    $username = $link->real_escape_string($_POST['username']);
    

    and

    $link->query($query);
    $link->close();
    

    You also don't need to explicitly cast the variables as strings since that is done automatically if needed for your code.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 请问如何在openpcdet上对KITTI数据集的测试集进行结果评估?
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错