Chris par
Chris par

Reputation: 65

sql update not working dont know how to fix

I am lost here please help

my data base table will not update when I use this code

$sqlpassword = "UPDATE login SET password='$hashedP' WHERE id='$id' LIMIT 1";
$querypass = mysqli_query($db_x, $sqlpassword);

I have tried to look around maybe i'm not seeing it but im sure its right

Upvotes: 0

Views: 54

Answers (4)

Mina Tadros
Mina Tadros

Reputation: 634

Check the following:

  1. You are making commit after this update statement.
  2. Check why you need the limit keyword, else remove it.
  3. Check if the id is a number in your table structure or string, since in this update you are dealing with it as string.

Upvotes: 0

Chris par
Chris par

Reputation: 65

I worked it out sorry for wasting your time

<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>

was not putting in

edit.php?c=<?php echo $log_company ?>

so form was going to edit.php not edit.php?c=truestory

Upvotes: 0

Reactgular
Reactgular

Reputation: 54821

password is a reserved word in MySQL. You have to wrap fieldnames in backticks so that MySQL doesn't see it as a SQL command.

$sqlpassword = "UPDATE `login` SET `password`='$hashedP' WHERE `id`='$id' LIMIT 1";
$querypass = mysqli_query($db_x, $sqlpassword);

Upvotes: 2

Don't use the LIMIT keyword on UPDATE Statement.

Just use

$sqlpassword = "UPDATE `login` SET `password`='$hashedP' WHERE `id`='$id'";

Disclaimer: Make use of Prepared Statements to avoid SQL Injection Attacks.

Upvotes: 0

Related Questions