Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
<?php
include 'connect.php';
$id = $_GET['updateid'];
if (isset($_POST['submit'])) {
    $name = $_POST['name'];
    $email = $_POST['email'];
    $phone = $_POST['phone'];
    $password = $_POST['password'];

    $sql = "UPDATE `personal info` SET id=$id, name='$name', email='$email', phone='$phone', password='$password' WHERE id=$id";
    $result = mysqli_query($con, $sql);

    if ($result) {
        echo "updated successfully";
        // header('location:display.php');
    } else {
        die(mysqli_error($con));
    }
}
?>


What I have tried:

i tried this one but also say "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1" idk what do to

<?php
include 'connect.php';
$id = $_GET['updateid'];
if (isset($_POST['submit'])) {
    $name = $_POST['name'];
    $email = $_POST['email'];
    $phone = $_POST['phone'];
    $password = $_POST['password'];

    $sql = "UPDATE `personal info` SET Name='$name', Email='$email', Phone='$phone', assword='$password' WHERE id=$id";
    $result = mysqli_query($con, $sql);

    if ($result) {
        echo "updated successfully";
        // header('location:display.php');
    } else {
        die(mysqli_error($con));
    }
}
?>
Posted
Updated 27-Dec-23 18:42pm
v2
Comments
Richard MacCutchan 28-Dec-23 4:26am    
Add an echo $sql; statement before the call to mysqli_query. That way you should be able to see what may be wrong.
0x01AA 28-Dec-23 7:12am    
What I have tried:

, assword='$password'
_Asif_ 28-Feb-24 6:17am    
Yes! this should be the issue. Correctly pointed. You should move your comments as Solution
Richard Deeming 2-Jan-24 8:46am    
In addition to the SQL Injection vulnerability, you are also storing your users' passwords in plain text. Don't do that!

Secure Password Authentication Explained Simply[^]
Salted Password Hashing - Doing it Right[^]

PHP even provides built-in functions to help you do the right thing:

PHP: password_hash[^]
PHP: password_verify[^]

Don't do it like that! Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Always use Parameterized queries instead.

When you concatenate strings, you cause problems because SQL receives commands like:
SQL
SELECT * FROM MyTable WHERE StreetAddress = 'Baker's Wood'
The quote the user added terminates the string as far as SQL is concerned and you get problems. But it could be worse. If I come along and type this instead: "x';DROP TABLE MyTable;--" Then SQL receives a very different command:
SQL
SELECT * FROM MyTable WHERE StreetAddress = 'x';DROP TABLE MyTable;--'
Which SQL sees as three separate commands:
SQL
SELECT * FROM MyTable WHERE StreetAddress = 'x';
A perfectly valid SELECT
SQL
DROP TABLE MyTable;
A perfectly valid "delete the table" command
SQL
--'
And everything else is a comment.
So it does: selects any matching rows, deletes the table from the DB, and ignores anything else.

So ALWAYS use parameterized queries! Or be prepared to restore your DB from backup frequently. You do take backups regularly, don't you?

PHP makes it easy to include parameters with queries: PHP: pg_query_params - Manual[^]
 
Share this answer
 
I feel it may be because your data table name contains spaces, because I have never used it like this before.
 
Share this answer
 
Comments
CHill60 28-Feb-24 3:54am    
The table name is surrounded by backticks `personal info` so the space is not a problem.
https://dev.mysql.com/doc/refman/8.0/en/identifiers.html[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900