vinaykr Posted April 8, 2012 Share Posted April 8, 2012 Hi, I am trying to display a variable that is supposedly created in a different page. Here is the code. But it is not displaying in the next page: ADMIN_login.PHP - Page URL <form name="form2" action="admin_login_success.php" method="post"> <?php $host="localhost"; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name="test"; // Database name $tbl_name="masterschoolinfo"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // username and password sent from form $myusername=$_POST['adminusername']; $mypassword=$_POST['adminpassword']; // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM $tbl_name WHERE school_username='$myusername' and school_password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" session_register("myusername"); session_register("mypassword"); header("location:Admin_login_success.php"); } else { header( 'Location: Adminportal.PHP' ) ; } ?> </form> admin_login_success.php - Next page where the variable is to be displayed based on the username provided in the above page: <html><body> <?php include 'mysql-connect.php'; $schoolID=mysql_query("select SCHOOLID from masterschoolinfo WHERE school_username='$myusername' and school_password='$mypassword'") or die(mysql_error()); while($row = mysql_fetch_array( $schoolID )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['SCHOOLID']; echo "</td></tr>"; } ?> </body></html> CAN SOMEONE HELP ME?? Link to comment https://forums.phpfreaks.com/topic/260567-passing-arguments-to-new-page/ Share on other sites More sharing options...
Drummin Posted April 8, 2012 Share Posted April 8, 2012 The structure of the page is off. I would also NEVER store password in session. <?php session_start(); $host="localhost"; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name="test"; // Database name $tbl_name="masterschoolinfo"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // username and password sent from form $myusername=$_POST['adminusername']; $mypassword=$_POST['adminpassword']; // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM $tbl_name WHERE school_username='$myusername' and school_password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" $_SESSION['myusername']=$myusername; //I would NOT EVER use passwords as a variable or session outside of login. //session_register("mypassword"); header("location:Admin_login_success.php"); } else { header( 'Location: Adminportal.PHP' ) ; } ?> Link to comment https://forums.phpfreaks.com/topic/260567-passing-arguments-to-new-page/#findComment-1335405 Share on other sites More sharing options...
vinaykr Posted April 8, 2012 Author Share Posted April 8, 2012 Sorry, the code dint helped. Deprecated: Function session_is_registered() is deprecated in C:\wamp\www\Admin_login_success.php on line 7 Call Stack # Time Memory Function Location 1 0.0006 370424 {main}( ) ..\Admin_login_success.php:0 session not regisetered Link to comment https://forums.phpfreaks.com/topic/260567-passing-arguments-to-new-page/#findComment-1335408 Share on other sites More sharing options...
Drummin Posted April 8, 2012 Share Posted April 8, 2012 Where's the code for Admin_login_success.php Link to comment https://forums.phpfreaks.com/topic/260567-passing-arguments-to-new-page/#findComment-1335411 Share on other sites More sharing options...
vinaykr Posted April 8, 2012 Author Share Posted April 8, 2012 admin_login_success.php - Next page where the variable is to be displayed based on the username provided in the above page: <html><body> <?php include 'mysql-connect.php'; $schoolID=mysql_query("select SCHOOLID from masterschoolinfo WHERE school_username='$myusername' and school_password='$mypassword'") or die(mysql_error()); while($row = mysql_fetch_array( $schoolID )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['SCHOOLID']; echo "</td></tr>"; } ?> </body></html> Link to comment https://forums.phpfreaks.com/topic/260567-passing-arguments-to-new-page/#findComment-1335413 Share on other sites More sharing options...
Drummin Posted April 8, 2012 Share Posted April 8, 2012 Can you post code for include 'mysql-connect.php'; ? Somewhere you are using session_is_registered() Link to comment https://forums.phpfreaks.com/topic/260567-passing-arguments-to-new-page/#findComment-1335416 Share on other sites More sharing options...
vinaykr Posted April 8, 2012 Author Share Posted April 8, 2012 Drummin, I am totally freaked out here!... Can we be on skype so that I can share my screen with you. I am getting the answer but it is wrong school ID. If this is not against this forum. I dont want to break rules. But I am really really freaked out by looking at my code I will later post the result here It should be schoolID=21, but it is displaying as 15.. :'( Link to comment https://forums.phpfreaks.com/topic/260567-passing-arguments-to-new-page/#findComment-1335421 Share on other sites More sharing options...
Drummin Posted April 8, 2012 Share Posted April 8, 2012 See PM message. Link to comment https://forums.phpfreaks.com/topic/260567-passing-arguments-to-new-page/#findComment-1335422 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.