| | |
PHP IF statement - getting a varible to show on another page
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Aug 2009
Posts: 12
Reputation:
Solved Threads: 1
Hi all,
Ive created a pretty simple user system its all working well users can sign up and so on. Though i wanted to add extra security to this system so when the user wants to modify their password it asks for their old password otherwise they cant sign up for a new password.
Im using two files for this the modify.php file where the user can fill in their password and old password. And the User.php containing the if statement.
I think ive done the IF statement but im not sure because the variable which will show the error message i cant seem to get working so that it displays the message on the other page.
Heres the code which powers the form(sorry for the messy coding its late and i just really want to get this finished!):
The $errorpass varible is what i want to display on the form page, so that the error is displayed on the form.
I have tried using using the echo function to display the varible but its not picking it up from the otherpage
I hope you can help, thanks for your time.
Ive created a pretty simple user system its all working well users can sign up and so on. Though i wanted to add extra security to this system so when the user wants to modify their password it asks for their old password otherwise they cant sign up for a new password.
Im using two files for this the modify.php file where the user can fill in their password and old password. And the User.php containing the if statement.
I think ive done the IF statement but im not sure because the variable which will show the error message i cant seem to get working so that it displays the message on the other page.
Heres the code which powers the form(sorry for the messy coding its late and i just really want to get this finished!):
PHP Syntax (Toggle Plain Text)
function modifyUser() { $userId = (int)$_POST['hidUserId']; $password = md5($_POST['txtPassword']); $oldpass = md5($_POST['txtOldPass']); $oldpassdata = mysql_query("SELECT user_password FROM tbl_user WHERE user_id = '$userId'"); if ($oldpass==$oldpassdata) $sql = "UPDATE tbl_user SET user_password = '$password' WHERE user_id = '$userId'"; dbQuery($sql); header('Location: index.php'); else $errorpass= "Oldpassword does not match!"; }
The $errorpass varible is what i want to display on the form page, so that the error is displayed on the form.
I have tried using using the echo function to display the varible but its not picking it up from the otherpage
PHP Syntax (Toggle Plain Text)
<td class="content"> <input name="txtOldPass" type="password" class="box" id="txtOldPass" size="20" maxlength="20"><?php echo $errorpass; ?></td></tr>
I hope you can help, thanks for your time.
There are a few ways you can do this, but the simplest is probably to pass the variable via GET. To do this add the following line of code after you set $errorpas:
Then at the top of your User.php script add the following lines:
If you google $_GET for php, you will get a better understanding of how to pass variables between php pages.
EDIT: I have assumed that you are trying to display the error message on the page User.php. If you are trying to display on Modify.php, change where I have written User.php to Modify.php.
php Syntax (Toggle Plain Text)
header("Location: User.php?errorpas=$errorpas");
Then at the top of your User.php script add the following lines:
php Syntax (Toggle Plain Text)
if(isset($_GET["errorpas"])) $errorpas = $_GET["errorpas"]; else $errorpas = ""; // may need to perform some validation of what has been passed before you use it
If you google $_GET for php, you will get a better understanding of how to pass variables between php pages.
EDIT: I have assumed that you are trying to display the error message on the page User.php. If you are trying to display on Modify.php, change where I have written User.php to Modify.php.
Last edited by darkagn; Sep 3rd, 2009 at 12:19 am.
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend. •
•
Join Date: Aug 2009
Posts: 49
Reputation:
Solved Threads: 8
I'm not sure if I completely understand your problem, but I'm gonna put this out there and hope it helps.
If you want to keep your form method as POST, and "Oldpassword does not match!" is the only possible value that
If you want to keep your form method as POST, and "Oldpassword does not match!" is the only possible value that
$errorpass can have, you can just add a hidden field to your HTML form: HTML Syntax (Toggle Plain Text)
<input type="hidden" name="errorpass" value="Oldpassword does not match!" />
Last edited by EvolutionFallen; Sep 3rd, 2009 at 5:34 am.
![]() |
Similar Threads
- [ask[PHP quiz script] how to show 1 question per page ?? (PHP)
- is it possible to retrieve manufacturer information using javascript? (JavaScript / DHTML / AJAX)
- PHP If Statement question (PHP)
- deleting of a record through php on mysql (PHP)
- Execute PHP file in the background from html page (PHP)
- PHP Statement ? (PHP)
- PHP Login Help? (PHP)
- problem with select statement filter thru GET url... (PHP)
- Feature Posts on Index ? (PHP)
Other Threads in the PHP Forum
- Previous Thread: Where does PHP work ?
- Next Thread: Blank php pages that have mysql connections
| Thread Tools | Search this Thread |
.htaccess action ajax apache api array auto beginner binary bounce broken cakephp checkbox class cms code cron curl database date display dynamic echo email error errorlog file files folder form format forms function functions google href htaccess html image include insert integration interactive ip java javascript joomla limit link login loop mail malfunctioning masterthesis menu mlm mod_rewrite multiple mysql nodes oop paypal pdf php popup problem query radio ram random recursion reference regex remote return script search server sessions sms soap source space sql syntax system table tutorial unset update upload url validation validator variable video web websitecontactform xml youtube





