简体   繁体   中英

Error in php script insert don't work

I want to insert the word 'Uurloon' in my database... But I got an error

Session is started, I included header.php where session is started

<?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);
?>

I receive the following error:

Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(uurloon,) VALUES ( 'haa',) WHERE user_id =1' at line 1

Can someone tell me what I am doing wrong?

I cant see my mistake or something

Connecting is fine but the insert... I got troubles

<?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 update query en een insert query door elkaar. Ik ga ervan uit dat je hier een update query nodig bent.

You are mixing an update and insert query. I guess you need an update query for this

UPDATE probeer dit eens (try this):

$query = "UPDATE `users` SET `some_column` = 'uurloon' WHERE `user_id` = '$user_id'"; //This will put the word "uurloon" in some_column

A beter way to go to another page:

header('Location: index.php');
exit();

In a function:

to($url) {
   header('Location: ' . $url);
   exit();
}

$sql=("UPDATE users (uurloon,)去掉 uurloon 后的逗号

所以如果你想INSERT你需要使用INSERT命令,而不是 UPDATE:

$sql=("INSERT INTO users (uurloon) VALUES ('$omschrijving')");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM