alvinchua Posted May 15, 2007 Share Posted May 15, 2007 if you notice there is 2 echo.. one is before if and another is inside if statement .. the before if statement will echo the $Username2 value and ...the echo inside the if statement will not echo the $Username2 value ... the $Username2 is pass from a .php to this .php form how to make the value is available inside the IF statement ? pls advice <?php $Username2=$_POST['username']; //echo $Username2; if (isset($_POST['enter'])) { echo $Username2; $year = $_POST['select']; echo $year; echo $myrow["Year"]; $Year = $myrow["Year"]; $query2="SELECT * FROM transaction where Year = $year"; Quote Link to comment https://forums.phpfreaks.com/topic/51475-solved-inside-outside-if-statement-problem/ Share on other sites More sharing options...
clown[NOR] Posted May 15, 2007 Share Posted May 15, 2007 do you have a input in the form called enter? Quote Link to comment https://forums.phpfreaks.com/topic/51475-solved-inside-outside-if-statement-problem/#findComment-253501 Share on other sites More sharing options...
alvinchua Posted May 15, 2007 Author Share Posted May 15, 2007 enter is an input button <th></th><td height="50"><input name = "enter" id = "enter" type ="submit" align ="center" value = "Submit"> Quote Link to comment https://forums.phpfreaks.com/topic/51475-solved-inside-outside-if-statement-problem/#findComment-253692 Share on other sites More sharing options...
Trium918 Posted May 15, 2007 Share Posted May 15, 2007 Try this! Variable needs to set after the if. <?php $Username2=$_POST['username']; //echo $Username2; if (isset($_POST['enter'])) { $Username2=$_POST['username']; echo $Username2; ?> Quote Link to comment https://forums.phpfreaks.com/topic/51475-solved-inside-outside-if-statement-problem/#findComment-253915 Share on other sites More sharing options...
alvinchua Posted May 16, 2007 Author Share Posted May 16, 2007 cant also .. the variable only can be display outside the if ... this is some code from login if (mysql_num_rows($result) == 1) { // the user id and password match, // set the session $_SESSION['db_is_logged_in'] = true; // after login we move to the main page header('Location: transaction.php'); exit; } else { $errorMessage = 'Sorry, wrong user id / password'; } include 'library/closedb.php'; } ?> <html> <head> <title>Basic Login</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php if ($errorMessage != ' ') { ?> <p align="center"><strong><font color="#990000"><?php echo $errorMessage; ?></font></strong></p> <?php } ?> <form action="transaction.php" method="post" name="frmLogin" id="frmLogin"> <table width="400" border="1" align="center" cellpadding="2" cellspacing="2"> <tr> <td width="150">Username</td> <td><input name="username" type="text" id="username"></td> </tr> Quote Link to comment https://forums.phpfreaks.com/topic/51475-solved-inside-outside-if-statement-problem/#findComment-254307 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.