Jump to content

Archived

This topic is now archived and is closed to further replies.

Gruzin

Problem with update *SOLVED*

Recommended Posts

Hi guys, please check this script, if it won't take u long and tell me what am I doing wrong?
Actually, I want the password to be updated... Script gives NO error just doesn't update db. any help will be greatly appreciated. Thank you.

[code]<?php
require ("config.php");
$query = "SELECT * FROM sec";
$result = mysql_query($query) or die("Error: " . mysql_error());
while($row = mysql_fetch_array($result))
$db_pass = $row['pass']; // password from db
?>
<?php
$pass = $_POST['pass']; // old password
$pass2 = $_POST['pass2']; // new pass 1
$pass3 = $_POST['pass3']; // new pass2 - confirm
if($pass != $db_pass){
  echo "Old Password is incorrect";
  exit();
  }
else if($pass2 != $pass3){
  echo "New Passwords didn't match";
  exit();
  }
else if(empty($pass2)){
  echo "Please enter the new password";
  exit();
  }
else{
$update = "UPDATE sec SET pass = '$pass2'";
if(!$update){
  die('Could not update: '.mysql_error());
  }
header ('location: edit_pass.php');
}
?>[/code]

Share this post


Link to post
Share on other sites
Try:

[code]
<?php
require ("config.php");
$query = "SELECT * FROM sec";
$result = mysql_query($query) or die("Error: " . mysql_error());
while($row = mysql_fetch_array($result))
$db_pass = $row['pass']; // password from db
?>
<?php
$pass = $_POST['pass']; // old password
$pass2 = $_POST['pass2']; // new pass 1
$pass3 = $_POST['pass3']; // new pass2 - confirm
if($pass != $db_pass){
  echo "Old Password is incorrect";
  exit();
  }
else if($pass2 != $pass3){
  echo "New Passwords didn't match";
  exit();
  }
else if(empty($pass2)){
  echo "Please enter the new password";
  exit();
  }
else{
$update = "UPDATE sec SET pass = '$pass2'";
$result = mysql_query($update);
if(!$result){
  die('Could not update: '.mysql_error());
  } else {
header ('location: edit_pass.php');
}
}
?>
[/code]

Share this post


Link to post
Share on other sites
GOD, that query is killing me! Hostfreak, Thanks freind  :)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.