Jump to content

Passing arguments to new page


vinaykr

Recommended Posts

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

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' ) ;
}
?>

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

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>

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  :wtf:

 

I will later post the result here

 

 

It should be schoolID=21, but it is displaying as 15..

 

 

:o>:( :'( :wtf:

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.