passing variables to a different page

Talk about working with different database types

Moderators: ne_moj, zewa, vadimako, ne_moj, zewa, vadimako

vinaykr
Newbie
Newbie
Posts: 1
Joined: Apr 8th, '12, 13:20

passing variables to a different page

Postby vinaykr » Apr 8th, '12, 13:27

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??

administrator
Site Admin
Site Admin
Posts: 5992
Joined: Jan 7th, '09, 23:18
Contact:

Re: passing variables to a different page

Postby administrator » Apr 9th, '12, 10:05

What variable do you speak about?
The scope of PHP variable is a current page only.


Return to “Databases: different types implementation”