php - Undefined index for updating database -


i cant seem find wrong code.

i want have not bias opinion since me perfect not xd.

<?php     require("common.php");     if(empty($_session['user']))     {         header("location: login.php");         die("redirecting login.php");     }     if(!empty($_post))     {          if($_post['eid'] != $_session['user']['eid'])         {            $query = "             select                 1             users                             eid = :eid         ";          $query_params = array(             ':eid' => $_post['eid']         );               try         {             $stmt = $db->prepare($query);             $result = $stmt->execute($query_params);         }         catch(pdoexception $ex)         {             die("failed run query: " . $ex->getmessage());         }          $row = $stmt->fetch();          if($row)         {             die("this employee id registered");         }         }         if(!empty($_post['password']))         {             $salt = dechex(mt_rand(0, 2147483647)) . dechex(mt_rand(0, 2147483647));             $password = hash('sha256', $_post['password'] . $salt);             for($round = 0; $round < 65536; $round++)             {                 $password = hash('sha256', $password . $salt);             }         }         else         {             $password = null;             $salt = null;         }         $query_params = array(             ':eid' => $_post['eid'],             ':user_id' => $_session['user']['id'],         );         if($password !== null)         {             $query_params[':password'] = $password;             $query_params[':salt'] = $salt;         }         $query = "             update users             set                 eid = :eid         ";         if($password !== null)         {             $query .= "                 , password = :password                 , salt = :salt             ";         }         $query .= "                             id = :user_id         ";          try         {             $stmt = $db->prepare($query);             $result = $stmt->execute($query_params);         }         catch(pdoexception $ex)         {             die("failed run query: " . $ex->getmessage());         }         $_session['user']['eid'] = $_post['eid'];         header("location: private.php");         die("redirecting private.php");     }  ?> <h1>edit account</h1> <form action="edit_account.php" method="post">     username:<br />     <b><?php echo htmlentities($_session['user']['username'], ent_quotes, 'utf-8'); ?></b>     <br /><br />     employeeid:<br />     <input type="text" name="eid" value="<?php echo htmlentities($_post['eid'], ent_quotes, 'utf-8'); ?>" />     <br /><br />     password:<br />     <input type="password" name="password" value="" /><br />     <i>(leave blank if not want change password)</i>     <br /><br />     <input type="submit" value="update account" /> </form>   

its code wherein alter data in database.it seems have error "eid"

this should rid of error:

  if($_post['eid'] != $_session['user']['eid'])         {            $query = "             select                 1             users                             eid = ".$_post['eid'];    } 

if eid string value replace:

eid = ".$_post['eid'];  

with

eid = '".$_post['eid']."'"; 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -