我想插入' Uurloon'在我的数据库中...但我收到了错误
会话已启动,我包含了启动会话的header.php
<?php
// UREN
$con=mysqli_connect("d","d","d","d");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// escape variables for security
$omschrijving = mysqli_real_escape_string($con, $_POST['omschrijving']);
$sql=("UPDATE users (uurloon,)
VALUES ( '$omschrijving') WHERE user_id = ".$_SESSION['user_id']." ");
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
echo '<script type="text/javascript">
<!--
window.location = "index.php"
//-->
</script>';
mysqli_close($con);
?>
我收到以下错误:
错误:您的SQL语法出错;检查与您的MySQL服务器版本相对应的手册,以便在&#39;(uurloon,)VALUES(&#39; haa&#39;,)WHERE user_id = 1&#39;附近使用正确的语法。在第1行
有人能告诉我我做错了吗?
我无法看到我的错误或其他什么
连接很好但是插件......我遇到了麻烦
答案 0 :(得分:1)
<?php
if($_POST) {
if(!empty($_POST['omschrijving']) {
//uren
$connect = mysqli_connect("d","d","d","d");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// escape variables for security
$omschrijving = mysqli_real_escape_string($connect, $_POST['omschrijving']);
$user_id = $_SESSION['user_id'];
$query = "UPDATE `users` SET `uurloon` = '$omschrijving' WHERE `user_id` = '$user_id'"; //Update query
$query = "INSERT INTO `users` (`uurloon`) VALUES ('$omschrijving')"; //Insert query
if (!mysqli_query($con, $sql)) {
die('Error: ' . mysqli_error($con));
}
echo '<script type="text/javascript">
<!--
window.location = "index.php"
//-->
</script>';
}}
mysqli_close($con);
?>
Je haalt een 更新 查询 插入 查询门elkaar。 Ik ga ervan uit dat je hier een update query nodig bent。
您正在混合更新和插入查询。我想你需要一个更新查询
更新 探针dit eens(试试这个):
$query = "UPDATE `users` SET `some_column` = 'uurloon' WHERE `user_id` = '$user_id'"; //This will put the word "uurloon" in some_column
转到另一页的更好方法:
header('Location: index.php');
exit();
在一个功能中:
to($url) {
header('Location: ' . $url);
exit();
}
答案 1 :(得分:0)
$sql=("UPDATE users (uurloon,)
删除uurloon后的逗号
答案 2 :(得分:0)
因此,如果你想 INSERT ,你需要使用 INSERT 命令,而不是UPDATE:
$sql=("INSERT INTO users (uurloon) VALUES ('$omschrijving')");