forumnz Posted January 3, 2007 Share Posted January 3, 2007 I just added a code to validate the password but its not working.I had just one field for the password before and I managed to make them encrypted.Then I thought about adding another field to validate the password but it just keeps saying the passwords do not match.I think it may have something to do with the encryption?Here it is anyway:[code]<?php session_start(); $con = mysql_connect("localhost","###","###"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("my_db", $con);if( isset($_POST['Submit']) ) { //Store/validate/escape $password = base64_encode($_POST['password']); $email = $_POST['email']; $area = $_POST['area']; $phone = $_POST['phone']; $age = $_POST['age']; $message = $_POST['message']; //Reset unset($_POST); $id = $_SESSION['userid']; //Validate Password if($password != $confirm_password){echo "Your passwords did not match.";}else{ $query = "UPDATE members SET password='$password', email='$email', area='$area', phone='$phone', age='$age', message='$message' WHERE id='$id'"; mysql_query($query); } //echo "$query\n\n"; if( mysql_errno() ) { echo "\n\nERROR: " . mysql_error(); }} $valid = false; if( isset($_SESSION['userid']) ) { //do whatever appropriate validation is necessary on id //if we encounter errors abort? $id = $_SESSION['userid']; //No errors... proceed //connect to database $query = "SELECT password, email, area, phone, age, message FROM members WHERE id = '$id'"; //echo "$query\n\n"; $result = mysql_query($query); if( mysql_errno() ) { echo "\n\nERROR: " . mysql_error(); } $row = mysql_fetch_row($result); $password = ""; //echo "PASSWORD: $password\n"; $email = ""; //echo "EMAIL: $email\n"; $area = ""; //echo "AREA: $area\n"; $phone = ""; //echo "PHONE: $phone\n"; $age = ""; //echo "AGE: $age\n"; $message = ""; //echo "MESSAGE: $message\n"; if( $row ) { $valid = true; //$password = $row[0]; $email = $row[1]; $area = $row[2]; $phone = $row[3]; $age = $row[4]; $message = $row[5]; } else { //Invalid username... handle error appropriately $valid = false; } //disconnect from database } else { //ERROR - Not logged in.... //Redirect to login page? $valid = false; } if( !$valid ) { //Errors, redirect.... }?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Page to test</title></head><body><p>Edit Profile</p><form id="form1" name="form1" method="post" action="edit.php"><p>Password : <?php echo "<input name=\"password\" type=\"password\" id=\"password\" value=\"$password\" />\n"; ?> Confirm Password : <?php echo "<input name=\"confirm_password\" type=\"password\" id=\"confirm_password\" value=\"$confirm_password\" />\n"; ?></p><p>Email Address : <?php echo "<input name=\"email\" type=\"text\" id=\"email\" value=\"$email\" />\n"; ?></p><p>Area : <?php echo "<input name=\"area\" type=\"text\" id=\"area\" value=\"$area\" />\n"; ?></p><p>Phone Number :<?php echo "<input name=\"phone\" type=\"text\" id=\"phone\" value=\"$phone\" />\n"; ?> </p><p>Age : <?php echo "<input name=\"age\" type=\"text\" id=\"age\" value=\"$age\" />\n";?></p><p>Personal Message : <?php echo "<textarea name=\"message\" id=\"message\">$message</textarea>\n"; ?></p><p> <label> <input type="submit" name="Submit" value="Go!" /> </label></p></form><p> </p></body></html>[/code] Link to comment https://forums.phpfreaks.com/topic/32650-solved-im-having-a-bit-of-trouble-with-this-script/ Share on other sites More sharing options...
ted_chou12 Posted January 3, 2007 Share Posted January 3, 2007 this: $confirm_passwordI dont see where you have set it at all, i cannot find it defined anywhere on the script, is that the problem?Ted Link to comment https://forums.phpfreaks.com/topic/32650-solved-im-having-a-bit-of-trouble-with-this-script/#findComment-151929 Share on other sites More sharing options...
forumnz Posted January 3, 2007 Author Share Posted January 3, 2007 I have in the HTML havent i? Link to comment https://forums.phpfreaks.com/topic/32650-solved-im-having-a-bit-of-trouble-with-this-script/#findComment-151935 Share on other sites More sharing options...
ted_chou12 Posted January 3, 2007 Share Posted January 3, 2007 nope thats the problem 8), here, you need to add this in as well:$confirmpassword = base64_encode($_POST['confirm_password']);you have to set the variables before you use them, if you dont believe me, try:echo "$confirmpassword";it will come out blank.Ted Link to comment https://forums.phpfreaks.com/topic/32650-solved-im-having-a-bit-of-trouble-with-this-script/#findComment-151944 Share on other sites More sharing options...
forumnz Posted January 3, 2007 Author Share Posted January 3, 2007 But where would that go? In my database table there is no space for a confirm password?? Link to comment https://forums.phpfreaks.com/topic/32650-solved-im-having-a-bit-of-trouble-with-this-script/#findComment-151948 Share on other sites More sharing options...
ted_chou12 Posted January 3, 2007 Share Posted January 3, 2007 put it under this:$password = base64_encode($_POST['password']);or simply do this:if($password != base64_encode($_POST['confirm_password'])){blah..blah... Link to comment https://forums.phpfreaks.com/topic/32650-solved-im-having-a-bit-of-trouble-with-this-script/#findComment-151950 Share on other sites More sharing options...
forumnz Posted January 3, 2007 Author Share Posted January 3, 2007 It keeps saying that passwords do not match? Link to comment https://forums.phpfreaks.com/topic/32650-solved-im-having-a-bit-of-trouble-with-this-script/#findComment-151956 Share on other sites More sharing options...
ted_chou12 Posted January 3, 2007 Share Posted January 3, 2007 solved already? or still not match? Link to comment https://forums.phpfreaks.com/topic/32650-solved-im-having-a-bit-of-trouble-with-this-script/#findComment-151964 Share on other sites More sharing options...
forumnz Posted January 3, 2007 Author Share Posted January 3, 2007 no match - i just took out the whole match thing Link to comment https://forums.phpfreaks.com/topic/32650-solved-im-having-a-bit-of-trouble-with-this-script/#findComment-151965 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.