Jump to content

why php is not carrying student ID from one page to 2nd and showing student id o


Recommended Posts

Hi All

I am kinda new to php.... I disparately need help with php coding. I am entering in the website using student id. If student id does not exist in mysql database, it gives me error. That works fine.

But If I try to echo StudentID on 2nd page, it is not displaying anything. Second problem is I want to display student first and last name using StudentID. But it is not displaying anything using StudentID. Why? I have been trying to solve it, but no success  :(

Following is the code for both problems -

 

if(!$db_selected)

{

  die("Can not use".DB_NAME.':'.mysql_err());

}   

@$Stud_ID = $_POST['Stud_ID'];

?>

 

 

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

    <link rel="stylesheet" type="text/css" href="ACSDP.css" />

<title>Student Main Page</title>

<head><h1>Welcome to Undergraduate Student Main Page</h1>

</head>

<body>

<form name ="mainpage" method='POST'>

    <table> 

        <tr>

        <td><label id="Stud_ID2" for="Stud_ID"> Student ID <?php echo "is:" ." ". @$Stud_ID; ?> </label></td>                       

            <td> <label  id="degree">Degree: Computer Science</label></td>

        </tr>

        <tr>

            <td> <label  id="name"> Student Name:  <?php               

              $query2 =mysql_query("SELECT Stud_Lastname, Stud_Firstname FROM Student WHERE Stud_ID='$Stud_ID'") or die('wrong query'.mysql_error());

              while($row = mysql_fetch_array($query2))

              {

              echo $row['Stud_Lastname'] . " " . $row['Stud_Firstname'];

              }     

 

If have made those statements bold. please help me...... 

can you show code from page 1, and code from page 2...

 

wrap it in code blocks please :)

 

as scoot said, you can use Sessions, but if page 1 is the form page, and page 2 is the Action page, then you CAN use $_POST or $_GET to transmit data..

 

I can give you some hints, however, you must be sure the form elements are named  properly.. You must be sure that the elements' names are used appropriately in your code as $_REQUEST['theFormInputName'] or you can get specific and use $_GET or $_POST, $_REQUEST holds all of the request parameters, parsed ofcourse..

 

if you ARE looking to collect this data, THEN redirect a user to a better place to DISPLAY this data, then you could do this 1 of 2 ways..

 

header('Location: theNewPage.php?id='.$theStudentId);

 

and then pull the information from the database, using this new student ID.. this is the ugly way..

 

OR you can use Sessions.. like this:

 

<?php
session_start();
$_SESSION['id'] = $student_id;
$_SESSION['first_name'] = $student_first_name;
$_SESSION['last_name'] = $student_last_name;
$_SESSION['major'] = $student_major;
$_SESSION['minor'] = $student_minor;
header('Location: theNewPage.php');
?>

 

then:

 

theNewPage.php

<?php
session_start();
var_dump($_SESSION);
?>

Code form first page is -

<?php

@$Stud_ID = $_POST['Stud_ID'];

if (isset($_POST['BUTTON']))

    {

$query2 =mysql_query("SELECT Stud_ID FROM Student WHERE Stud_ID ='$Stud_ID'") or die('wrong query'.mysql_error());

?>

 

code from Second page is -

 

.....

@$Stud_ID = $_GET['Stud_ID'];

.....

 

<table> 

        <tr>

        <td><label id="Stud_ID2" for="Stud_ID"> Student ID <?php echo "is:" ." ". @$Stud_ID; ?> </label></td>                       

            <td> <label  id="degree">Degree: Computer Science</label></td>

        </tr>

        <tr>

            <td> <label  id="name"> Student Name:  <?php               

              $query2 =mysql_query("SELECT Stud_Lastname, Stud_Firstname FROM Student WHERE Stud_ID='$Stud_ID'") or die('wrong query'.mysql_error());

              while($row = mysql_fetch_array($query2))

              {

              echo $row['Stud_Lastname'] . " " . $row['Stud_Firstname'];

              }       

              ?></label></td>

           

            <td><label  id="advior">Advisor: Dr. H. Lee</label> </td>

        </tr>

    </table><br/>

.........................

 

Sorry for trouble understanding it .... I have changed some names here. I have given dummy hostname, user name, password, database name...

First page code is -

 

 

<?php

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

define ('DB_HOST','204.158.159.41'); // Host name

define('DB_USER','akash'); // Mysql username

define('DB_PASSWORD','raje'); // Mysql password

define('DB_NAME','check'); // Database name

// Connect to server and select database.

$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);

if(!$link)

{

    die("Could not connect:".mysql_error());

}

$db_selected = mysql_select_db(DB_NAME, $link);

if(!$db_selected)

{

  die('Can not use'.DB_NAME.':'.mysql_err());

}

?>

 

<html>

<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Check it</title>

</head>

<link rel="stylesheet" type="text/css" href="atrm.css"/>

<form method="POST">

<table width="100%" border="0" cellpadding="3" cellspacing="1" align="center">

<tr>

<td colspan="3"><h1>Welcome </h1><hr width="100%"></hr></td>

</tr>

<br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/><br/>

<tr><td><h3>

<p><center>

  <label  id="stud_ID1" for="ID">Enter Student ID:</label>

  <input type="text"  maxlength="30" name="Stud_ID"/>

</center></p>

        </h3></td></tr>

<td><center><input type="submit" style="height: 25px; width: 100px" name="BUTTON"

<?php

@$Stud_ID = $_POST['Stud_ID'];

if (isset($_POST['BUTTON']))

    {

$query2 =mysql_query("SELECT Stud_ID FROM Student WHERE Stud_ID ='$Stud_ID'") or die('wrong query'.mysql_error()); 

$count=mysql_num_rows($query2);

if ($count==1)

{

                    header("location:http://204.158.159.41/../Student_Mainpage.php?id='.$Stud_ID");

}

else

{

                    header("location:http://204.158.159.41/../Errorpage.php");

}               

if ($Stud_ID =="")

header("location:http://204.158.159.41/../BlankIDpage.php");             

}

?>value="Submit">

</center></td>

</tr>

</table>

</form>

</html>

 

 

 

Second page where it is going is -

 

<?php

define ('DB_HOST','204.158.159.41'); // Host name

define('DB_USER','akash'); // Mysql username

define('DB_PASSWORD','raje'); // Mysql password

define('DB_NAME','check'); // Database name

// Connect to server and select database.

$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);

if(!$link)

{

    die("Could not connect");

}

$db_selected = mysql_select_db(DB_NAME, $link);

 

if(!$db_selected)

{

  die("Can not use".DB_NAME.':'.mysql_err());

}   

@$Stud_ID = $_POST['Stud_ID'];

?>

 

 

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

    <link rel="stylesheet" type="text/css" href="atrm.css" />

<title>Student Main Page</title>

<head><h1>Welcome to Main Page</h1>

</head>

<body>

<form name ="mainpage" method='POST'>

    <table> 

        <tr>

        <td><label id="Stud_ID2" for="Stud_ID"> Student ID <?php echo "is:" ." ". @$Stud_ID; ?> </label></td>                       

            <td> <label  id="degree">Degree</label></td>

        </tr>

        <tr>

            <td> <label  id="name"> Student Name:  <?php               

              $query2 =mysql_query("SELECT Stud_Lastname, Stud_Firstname FROM Student WHERE Stud_ID='.$Stud_ID'") or die('wrong query'.mysql_error());

              while($row = mysql_fetch_array($query2))

              {

              echo $row['Stud_Lastname'] . " " . $row['Stud_Firstname'];

              }       

              ?></label></td>

           

            <td><label  id="advior">Advisor</label> </td>

        </tr>

    </table><br/>

</form>

</body>

</html>

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.