Jump to content

Problem with update *SOLVED*


Gruzin

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]
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.