I know this is a long one but I've been trying to work around the coding for days, any help will be of great help.
______________________________________________________________________________________
I have a bit of a problem, I have three pages: student_login.htm(to take in id and pwd),loginstdck.php(to check if the values match with those in the table and display a 3rd page) which is viewstdprofile2.php
( I have uploaded with this post the print screen of how the 3rd page looks )
The first two pages work perfectly,but in the 3rd page, half of the html code is generated but the rest shows as code and doesn't get processed.
]
- In the coding for viewstdprofile.php, is it not working because it can't access the $_SESSION from loginstdck.php ? But isn't that already a global variable?
Or
- is the coding not working because i've missed some tags after the ---- line i marked in the 3rd php file?
The coding for the pages are below:-
1.student_login.htm (the background and the position of the labels didn't match so i had to use many spaces to make it all align, sorry )
<form action="loginstdck.php" method="post">
<table cellspacing="1" cellpadding="0" width="800" height="350" align="center" bgcolor="#CCCCCC">
<tbody>
<tr>
<td>
<h2><span style="font-weight: normal; font-size: 12px;">
<table style="width: 95%; background-color: #ffffff;" border="5" cellspacing="1" cellpadding="3">
<tbody>
<tr>
<td style="text-align: left;" colspan="3"><span style="font-size: 16px;"><strong><span style="text-decoration: underline; color: #ffffff;">Student Login Page</span><br /><br /><br /><br /><br /><br /><br /> <span style="color: #ffffff;">Username :</span> <input id="username" maxlength="9" name="mystdusername" type="text" /> <span style="font-size: 14px; color: #ff0000;"><em>(use your roll no as the username)</em> </span><br /> <br /> <span style="white-space: pre;"> </span><span style="color: #ffffff;">Password : </span> <input id="password" maxlength="10" name="mystdpassword" type="password" /> <br /><br /> <span style="color: #000000;"> [ Note: Login only for registered ACMIT students ]</span> <br /> <br /> <input name="Submit" type="submit" value="Login" /> --- <input type="reset" value="Reset" /> <br /> ______________________________________<br /> <br /><br /><br /><br /><br /> </strong></span></td>
</tr>
</tbody>
</table>
<br /> </span></h2>
</td>
</tr>
</tbody>
</table>
</form>
2.loginstdck.php
<?
//***************************************
session_start();
//session_register("session");
$host=""; // Host name
$dbusername=""; // Mysql username
$dbpassword=""; // Mysql password
$db_name=""; // Database name
$tbl_name=""; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$dbusername", "$dbpassword")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
//////////////////////////////
// username and password sent from form
$userid=$_POST['stdusername'];
$password=$_POST['stdpassword'];
?>
<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
<title>(Welcome ACMIT student!)</title>
<meta name="GENERATOR" content="Arachnophilia 4.0">
<meta name="FORMATTER" content="Arachnophilia 4.0">
</head>
<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
<?
$userid=mysql_real_escape_string($userid);
$password=mysql_real_escape_string($password);
if($rec=mysql_fetch_array(mysql_query("SELECT * FROM student WHERE rollno='$userid' AND password ='$password'")))
{
if(($rec['rollno']==$userid)&&($rec['password']==$password))
{
//error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR);
$_SESSION['id']=session_id();
$_SESSION['userid']=$userid;
$tm=date("Y-m-d H:i:s");
//$ip=@$REMOTE_ADDR;
// The above line is commented and the line below is used for the servers where register_global=Off
$ip=$_SERVER['REMOTE_ADDR'];
//echo $ip;
$rt=mysql_query("insert into plus_login(id,userid,ip,tm)values('$_SESSION[id]','$_SESSION[userid]','$ip','$tm')");
echo mysql_error();
echo "<p class=data> <center>Successfully,Logged in<br><br><a href='logout.php'> Log OUT</a><br><br><a href='viewstdprofile.php'>Click here if your browser is not redirecting automatically or you don't want to wait.</a><br></center>";
print "<script>";
print " self.location='viewstdprofile.php';"; // Comment this line if you don't want to redirect
print "</script>";
}
}
else
{
session_unset();
echo "<font face='Verdana' size='2' color=red>Wrong Login. Use your correct Userid and Password and Try <br><center><input type='button' value='Retry' onClick='history.go(-1)'></center>";
}
?>
</body>
</html>
3rd page: viewstdprofile2.php
<?php
//******************* SESSION START
session_start();
//session_register("session");
$host=""; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name=""; // 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");
///////////////////////////////////
?>
<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
<title>Welcome ACMIT student!</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#f8f19f">
<table border="1" cellpadding="4" cellspacing="0">
<tr valign="top">
<td>
<h1>************** Successfully logged in !*******************</h1>
<form method="post" action ="updatestd.php">
<div style="text-align: left;"><input type="submit" name="Submit" value="Update your student profile"></div>
</form>
<br />
Click here to: <a href='logout.php'>Log OUT</a><div style="text-align:right;"><input type="button" value="Print this page" onClick="window.print()"></div>
?>
echo mysql_error();
echo "<hr>";
echo "<u><b>Today's date: </b></center>" .date("d/m/Y"). "</u><br />";
$query="SELECT * FROM student where rollno= '$_SESSION['userid']'";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
echo "<b><center>[ Student Profile Output ]</center></b><br>";
$i=0;
while ($i < $num)
{
$rollno=mysql_result($result,$i,"rollno");
$firstname=mysql_result($result,$i,"fname");
$lastname=mysql_result($result,$i,"lname");
$centercode=mysql_result($result,$i,"ccode");
$course=mysql_result($result,$i,"course");
$sem=mysql_result($result,$i,"sem");
$mobile=mysql_result($result,$i,"mobileno");
$email=mysql_result($result,$i,"email");
$state=mysql_result($result,$i,"state");
$city=mysql_result($result,$i,"city");
$add=mysql_result($result,$i,"add");
echo "<hr>";
echo "<p>Record count = $num</p>\n";
echo "<table border=\"1\" cellpadding=\"4\" border=\"1\" cellspacing=\"0\">\n";
echo "<tbody>";
echo "<tr>";
echo "<td><strong>Roll no: </strong>$username</td>";
echo "<td><strong>Name :</strong>$firstname $lastname</td>";
echo "</tr>";
echo "<tr>";
echo "<td><strong>Centre Code:</strong>$centercode</td>";
echo "<td><strong>State : </strong>$state</td>";
echo "</tr>";
echo "<tr>";
echo "<td><strong>City:</strong>$city</td>";
echo "<td><strong>Mobile no:</strong>$mobile</td>";
echo "</tr>";
echo "<tr>";
echo "<td><strong>Email: </strong>$email</td>";
echo "<td><strong>Address: </strong>$add</td>";
echo "</tr>";
echo "</tbody>";
echo "</table>\n";
$i++;
}
?>