7 Replies - 590 Views - Last Post: 26 April 2012 - 12:08 PM Rate Topic: -----

#1 rakesh00718  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 25-April 12

change password error

Posted 26 April 2012 - 04:46 AM

When I click on change password following error is shown but password changed successfully

Why This type of Problem is occured?

Quote

Notice: Undefined index: email in D:\xampp\htdocs\rakesh_work\rakesh_work_2\pract\change_password.php on line 5


Quote

Notice: Undefined index: password in D:\xampp\htdocs\rakesh_work\rakesh_work_2\pract\change_password.php on line 6


Quote

Notice: Undefined index: newpassword in D:\xampp\htdocs\rakesh_work\rakesh_work_2\pract\change_password.php on line 7


Quote

Notice: Undefined index: confirmpassword in D:\xampp\htdocs\rakesh_work\rakesh_work_2\pract\change_password.php on line 8


Quote

Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 5 in D:\xampp\htdocs\rakesh_work\rakesh_work_2\pract\change_password.php on line 16

New password and confirm password must be the same!
if($_POST['email']!="") { $email = $_POST['email']; } else die("No email was passed"); if($_POST['password']!="") { $password = $_POST['password']; } else die("No Password was passed"); if($_POST['newpassword']!="") { $newpassword = $_POST['newpassword']; } else die("No NewPassword was passed");

This post has been edited by Dormilich: 26 April 2012 - 05:14 AM
Reason for edit:: please use [code] [/code] tags when posting code


Is This A Good Question/Topic? 0
  • +

Replies To: change password error

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 2894
  • View blog
  • Posts: 7,544
  • Joined: 08-June 10

Re: change password error

Posted 26 April 2012 - 05:16 AM

you have that problem because the data you want to process are not there. and if you try to get an array value with a non-existent key, that’s the type of error you get.
Was This Post Helpful? 0
  • +
  • -

#3 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 934
  • View blog
  • Posts: 2,329
  • Joined: 15-February 11

Re: change password error

Posted 26 April 2012 - 05:17 AM

The undefined index simply means that you're trying to access a an index in an array that doesn't exist. Before using variables you should use empty() or isset() to verify that they actually exist.

For a more comprehensive answer you should post your source code.
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 2894
  • View blog
  • Posts: 7,544
  • Joined: 08-June 10

Re: change password error

Posted 26 April 2012 - 05:36 AM

View Postcodeprada, on 26 April 2012 - 02:17 PM, said:

Before using variables you should use empty() or isset() to verify that they actually exist.

either that or filter functions.
Was This Post Helpful? 0
  • +
  • -

#5 Cbeppe  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 31
  • View blog
  • Posts: 215
  • Joined: 16-September 09

Re: change password error

Posted 26 April 2012 - 11:41 AM

Also, this is gonna make your life 10x easier. Trust me!

<?php

if (isset($_POST['email'])) { 
    $email = $_POST['email']; 
} else {
    die("No email was passed"); 
}

if (isset($_POST['password'])) { 
    $password = $_POST['password']; 
} else {
    die("No password was passed"); 
}

if (isset($_POST['newpassword'])) { 
    $newpassword = $_POST['newpassword']; 
} else {
    die("No new password was passed");
}

?>


Was This Post Helpful? 0
  • +
  • -

#6 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 2894
  • View blog
  • Posts: 7,544
  • Joined: 08-June 10

Re: change password error

Posted 26 April 2012 - 11:49 AM

you can condense that even more:
$email = filter_input(INPUT_POST, "email", FILTER_VALIDATE_EMAIL);
if (!isset($email, $_POST['password'], $_POST['newpassword']) or !$email)
{
    throw new InvalidArgumentException("Invalid Mail or Password encountered.");
}

Was This Post Helpful? 1
  • +
  • -

#7 Cbeppe  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 31
  • View blog
  • Posts: 215
  • Joined: 16-September 09

Re: change password error

Posted 26 April 2012 - 12:06 PM

^ ^ ^ -- Filter functions are great, but I was actually referring to the code readability :D. Having all that on one line is very impractical. But I forgot that isset() takes several arguments...

This post has been edited by Cbeppe: 26 April 2012 - 12:06 PM

Was This Post Helpful? 0
  • +
  • -

#8 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 2894
  • View blog
  • Posts: 7,544
  • Joined: 08-June 10

Re: change password error

Posted 26 April 2012 - 12:08 PM

btw. I wouldn’t die() in an error case, that usually breaks your HTML code.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1