简体   繁体   中英

Php/html/mysql User updating not working

I'm having a problem. I'm working on a custom cms for my site and for some reason the users will not update in the admin panel. It pulls there ID and displays there information in the proper fields, but it will not update and I have no clue why. It just refreshes with the same info, doesn't update my the database or anything. I've tried to fix this, but it won't work. I did different alterations, but all were fails so I decided to just post the original one with a few bug fixes not relating to the updating process.

Heres the whole code:

<?php
$id = $_GET['id'];
$result = $db->query("SELECT * FROM users WHERE Id = '".$id."'");

if(isset($_POST['submit']))
{
  $username1 = $_POST['Username'];
  $email1 = $_POST['Email'];
  $password1 = $_POST['Password'];
  $f_name = $_POST['FName'];
  $l_name = $_POST['LName'];
  $rank1 = $_POST['Rank'];
  $skype1 = $_POST['SkypeID'];

  $db->query("UPDATE users SET (Email, Username, FName, LName, Rank, SkypeID) VALUES(''.$email1.'', ''.$username1.'', ''.$f_name.'', ''.$l_name.'', ''.$rank1.'', ''.$skype1.'') WHERE Id = ".$id."");
}

?>
<b>Update User</b>


<?php
$id = $_GET['id'];
$result = $db->query("SELECT * FROM users WHERE id='$id'");
while($row = $result->fetch_assoc())
{
  $username = $row['Username'];
  $email = $row['Email'];
  $fname = $row['FName'];
  $lname = $row['LName'];
  $rank = $row['Rank'];
  $skype = $row['SkypeID'];
}
?>
<form method="POST">
  Username: <input type="text" name="username" value="<?php echo($username); ?>"><br>
  Email: <input type="email" name="email" value="<?php echo($email);?>"><br>
  Passowrd: <input type="password" name="password"><br>
  First Name: <input type="text" name="f_name" value="<?php echo($fname);?>"><br>
  Last Name: <input type="text" name="l_name" value="<?php echo($lname); ?>"><br>
  Rank: <input type="text" name="rank" value="<?php echo($rank); ?>"><br>
  Skype: <input type="text" name="rank" value="<?php echo($skype); ?>">
  <button type="submit" name="submit">Update User</button>
</form>

Config file/$db:

<?php

$db = new mysqli('localhost', 'user', 'pass', 'database');

function registerSession($name, $value)
{
    $_SESSION[$name] = $value;
}
?>

UPDATE

I have fixed the problem, I changed the query to this

$db->query("UPDATE users SET Email= '$email1' , Username= '$username1' , FName= '$f_name' , LName= '$l_name', Rank= '$rank1' , SkypeID= '$skype1' WHERE Id = ".$id."") or die (mysql_error());

I cringed when I saw this...

$id = $_GET['id'];
$result = $db->query("SELECT * FROM users WHERE id='$id'");

Because you have yet to tell us what $db is, based on the looks of things I'm going to guess its a mysql_* function? I would enjoy watching someone SQL injecting this! Show us how $db is created (It better be at least mysqli , if not PDO ! If not, Google "mysqli" or "PDO") please?

It's hard to tell what your problem is.

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