Click here to Skip to main content
14,638,900 members

Update in PHP get an eror

Member 14861771 asked:

Open original thread
well i am new in php... for now i learn database in php and i build a form that i can want to input username and password value pick the id and when i click submit it will update my table in my database

this is the eror i get:
Query failedYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

when i try to debugg i figure that the problem is with the id veriable, it get nothing from the select element

What I have tried:

include "db.php";
include "functions.php";
    $username= $_POST['username'];
    $password= $_POST['password'];
    $id= $_POST['id'];
    $query="UPDATE users SET password='$password',username='$username' WHERE id= $id ";
    $result=mysqli_query($connection,$query);//this function return true or false!
        die("Query failed".mysqli_error($connection));

<!DOCTYPE html>
<link rel="stylesheet" href="" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<script src="" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
<div class="container">
    <div class="col-sm-6">
        <form action="Page1.php" method="post">
            <div class="form-group">
                <label for="username">Username</label>
                <input type="text" class="form-control" name="username">
            <div class="form-group">
                <label for="password">Password</label>
                <input type="password" class="form-control" name="password">
            <div  class="form-group">
                <select name="id" id="" >
                    global $connection;
                    $query="SELECT * FROM users";
                        die('Query failed'. mysqli_error());
                    while ($row = mysqli_fetch_assoc($result)) {
                        $id = $row['id'];
                        echo "<option value=''>$id</option>";
            <input class="btn btn-primary" type="submit" name="submit" value="Update" >

Tags: PHP, MySQL, database


When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100