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 />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ffffff;">Username &nbsp;:</span> &nbsp;<input id="username" maxlength="9" name="mystdusername" type="text" />&nbsp;&nbsp; &nbsp;<span style="font-size: 14px; color: #ff0000;"><em>(use your roll no as the username)</em>&nbsp;</span><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span style="white-space: pre;"> </span><span style="color: #ffffff;">Password &nbsp;: &nbsp;</span>&nbsp;<input id="password" maxlength="10" name="mystdpassword" type="password" />&nbsp;&nbsp; <br /><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&nbsp;[ Note: Login only for registered ACMIT students ]</span>&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<input name="Submit" type="submit" value="Login" />&nbsp;&nbsp; ---&nbsp;&nbsp; &nbsp;<input type="reset" value="Reset" />&nbsp;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ______________________________________<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br /><br /><br /><br /><br />&nbsp;</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:&nbsp;</strong>$add</td>";      
 
 
       echo "</tr>";     
       echo "</tbody>";
       echo "</table>\n";
       $i++;  
   }
?>

Recommended Answers

All 21 Replies

Nothing special.. You did not used the opening tag (<?php ) and closing tag (?>) properly...

See in your code at this place in body section...

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> 
?>   // This is the error...
echo mysql_error(); 
echo "<hr>";

You used closing tag rather using opening tag.. So only it all gets displayed as it is.. Check it.. If still any probs, pls let me know...

Thanks for checking it out, yes I figured there was something wrong with the tags, but unfortunately it's still not outputting the required data, although the extra codes aren't showing no more.

Please if you can help to direct me to where i can place the codes in the appropriate places. Even if it doesn't show a feedback, at least if the tables along with the attributes can get shown, that is more than enough, i can finish the rest from there.

Many thanks,
DragonBaki

Try replacing

print '<script>';
print " self.location='viewstdprofile.php';"; // Comment this line if you don't want to redirect
print '</script>';

in your loginstdchk.php with

include('viewstdprofile2.php'};

hi..

you have not start the session at the starting of the page.so before head start the session

Thanks

He has started the session on each PHP page.

Yes I have replaced it, before I checked the code, and yes I have put it in the startsession() at the beginning of each page.

Did the include() carry your session values over ?

1. Yes i suppose so, I have placed somewhere that the session values equal to their corresponding userid and pwd values.
But for using include it gave an error but with header it worked.

I've tried with the code and have re-checked all the attribute/value names but with what I've done so far, i don't know if it's a problem with the code or it's a problem with connecting to the db.
I've renamed it to 'viewstdprofile' and the code and page output is below.
Once again, thanks !

2. And another thing I wanted to know, if I have 2 separate input forms, each with a text box with name 'userid' and value for the pwd box as 'password'.
Once these values are passed for the sessions, will it have any issues with regards to updating based on those values?
I mean, is it better I just unique names to both the 'id' and 'pwd' values instead?

CODING
___________________________________________________________________________________

<?php
//must always start the session first
session_start();
  $dbusername="";
  $dbpassword="";
  $database="";
  $localhost="";
 
  mysql_connect($localhost,$dbusername,$dbpassword);
  @mysql_select_db($database) or die( "Unable to select database");
?>


<html>
<head>
<title>Welcome ACMIT student!</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head> 
<body bgcolor="#f8f19f">

<table border="1" cellpadding="4" cellspacing="0">
<tr valign="top">
<td>
<!--<div style="text-align: right;"><input onclick="window.print()" type="button" value="Print this page" /></div>-->
      <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>
 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> 
<b><center>[    Student Profile Output    ]</center></b><br>  
</form>

<?php
echo "<hr>";
 echo "<u><b>Today's date is: </b></center>" .date("d/m/Y"). "</u><br />";
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(); 
      $query="SELECT * FROM student where rollno= '$userid'";
      $result=mysql_query($query);
      $num=mysql_numrows($result); 
      mysql_close();
      $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");  
        $i++;  
       }
   }
 }
        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>$rollno</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:&nbsp;</strong>$add</td>"; 
 
        echo "</tr>";     
        echo "</tbody>";
        echo "</table>\n";   
?>
</table>
</body>
</html>

________________________________________________________________________________
[OUTPUT SCREEN PAGE]

Try this:

<?php
echo "<hr>";
echo "<u><b>Today's date is: </b></center>" .date("d/m/Y"). "</u><br />";
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();
$query="SELECT * FROM student where rollno=$userid";
$result=mysql_query($query);
$num=mysql_numrows($result);
$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");
$i++;
}
}
}
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>$rollno</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:&nbsp;</strong>$add</td>";

echo "</tr>";
echo "</tbody>";
echo "</table>\n";
?>
</table>
</body>
</html>

Yes I have used this code, altered it and entered the POST for id and pwd and also the db details, I get the format of the table with the td entries but not the tr entries.
I am checking the codes again, will double check as well.

Did you use the code I altered ? It removed the mysql_close() tag and took your $user_id variable out of ' '. And integer should not be introduced into the database with quotes wrapping it or it will not be found.

Yes I tried that, and after putting in the right info, it worked
but it seems in the orginal, it's not accepting userid.

Here's the link:
In the table format, it works perfectly but as soon as it starts to run the query based on an input, it doesn't work.

Yes I did try that, and the code works perfectly ! But as soon as I alter it to display based on a query, it doesn't work that way.
I've attached the recent screen output here, I want to understand what is the problem in the coding below?
Is it because the html part should be before/after the php or vice versa?

Because I've noticed the while loop should work like this:
1. save the info from the db to the variables and display, after each iteration
But instead if the echos for (table) till (table/newline) are not a part of it, it works and displays.

and 2. If I comment the two IFs for checking the username and password, display the query as a 'select for all' - it displays the info, otherwise it doesn't.

Any suggestion or feedback will be of great help !

CODE#1
________________________________________________________________________________________

<?php
//must always start the session first
session_start();
  $dbusername="";
  $dbpassword="";
  $database="";
  $localhost="";
 
  mysql_connect($localhost,$dbusername,$dbpassword);
  @mysql_select_db($database) or die( "Unable to select database");

  $stduserid=$_POST['stduserid'];
  $stdpassword=$_POST['stdpassword'];
?>


<html>
<head>
<title>Welcome ACMIT student!</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head> 
<body bgcolor="#f8f19f">

<table border="1" cellpadding="4" cellspacing="0">
<tr valign="top">
<td>
<!--<div style="text-align: right;"><input onclick="window.print()" type="button" value="Print this page" /></div>-->
      <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>
 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> 
<b><center>[    Student Profile Output    ]</center></b><br>  
</form>

<?
echo "<hr>";
 echo "<u><b>Today's date is: </b></center>" .date("d/m/Y"). "</u><br />";
$stduserid=mysql_real_escape_string($stduserid);
$stdpassword=mysql_real_escape_string($stdpassword);

if($rec=mysql_fetch_array(mysql_query("SELECT * FROM student WHERE rollno='$stduserid' AND password ='$stdpassword'")))
  {
   if(($rec['rollno']==$stduserid)&&($rec['password']==$stdpassword))
    {  
      echo mysql_error(); 
      $query="SELECT * FROM student where rollno= '$stduserid'";
      $result=mysql_query($query);
      $num=mysql_num_rows($result);       
      $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,"address");  
        $i++;  
       }
   }
 }
        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>$rollno</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:&nbsp;</strong>$address</td>"; 
 
        echo "</tr>";     
        echo "</tbody>";
        echo "</table>\n";   
?>
</table>
</body>
</html>

----------------------------------------------------------------------------------------
And the code that works fine is as follows:-
(Note: I noticed in this coding - the while loop starts, assigns the values then displays it in echo, but doing this is in the code#1 doesn't work out
The output of the follwing code is here )
CODE#2
________________________________________________________________________________________

<?
$dbusername="";
$dbpassword="";
$database="";
 
mysql_connect("sql100.mezoka.com",$dbusername,$dbpassword);
@mysql_select_db($database) or die( "Unable to select database");
 
$qy="SELECT * FROM student";
$result=mysql_query($qy);
 
$num=mysql_num_rows($result);
 
//mysql_close();
 
echo "<b><center>Student Output</center></b><br><br>";
 
$i=0;
if($num==0){
echo "The database contains no records yet!";}else{
 
while ($i < $num) {
 
$rollno=mysql_result($result,$i,"rollno");
$fname=mysql_result($result,$i,"fname");
$lname=mysql_result($result,$i,"lname");
$ccode=mysql_result($result,$i,"ccode");
$mobileno=mysql_result($result,$i,"mobileno");
$sem=mysql_result($result,$i,"sem");
$state=mysql_result($result,$i,"state");
$address=mysql_result($result,$i,"address");
$city=mysql_result($result,$i,"city");
$country=mysql_result($result,$i,"country");
$email=mysql_result($result,$i,"email");
$course=mysql_result($result,$i,"course");
 
echo "<b>$fname $lname</b><br>Center Code: $ccode<br>Moible number: $mobileno<br>Semester: $sem<br>Address: $address<br>City: $city<br>Country: $country<br>State: $state<br>Email: $email<br>Course: $course<br><hr><br>";
 
$i++;
 
}
 
}
?>

I believe your problem lies in querying for the Roll No. If this is an integer, then it must not be wrapped in 'single quotes'. Integers are, well integers. Not strings. You wrap 'words' in 'single quotes' because they must be read as a string. Integers CANNOT be read as strings. Because they're not.

Try changing these lines

f($rec=mysql_fetch_array(mysql_query("SELECT * FROM student WHERE rollno='$stduserid' AND password ='$stdpassword'")))
{
if(($rec['rollno']==$stduserid)&&($rec['password']==$stdpassword))
{
echo mysql_error();
$query="SELECT * FROM student where rollno= '$stduserid'";
$result=mysql_query($query);
$num=mysql_num_rows($result);

To this:

f($rec=mysql_fetch_array(mysql_query("SELECT * FROM student WHERE rollno=$stduserid AND password ='$stdpassword'")))
{
if(($rec['rollno']==$stduserid)&&($rec['password']==$stdpassword))
{
echo mysql_error();
$query="SELECT * FROM student where rollno= $stduserid";
$result=mysql_query($query);
$num=mysql_num_rows($result);

Yes I have changed that line, the message it gives is:- Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/vol7/mezoka.com/mezok_6586286/htdocs/viewstdprofile.php on line 43

And I read and understand your post, the rollno fieldname is VARCHAR, not integer.
I'll re-check the codings again.

Dont use "&nbsp;" that much. Slows down the YPage speed, just a tip, nothing special.

Thanks for the tip, i'll keep that in mind :)

use Smarty

the smarty let you avoid mix your html code and php code...it's very convinient.
mixing html and php is a very bad practice. Separating storage of php and html is a standart de factо

I'll check that out too, it's called smarty eh? Yeah it can be a bit confusing when the two get mixed and then having to work with inner codes of each !

I've worked around the code,seems it's just connecting to one database, instead of two separate ones simultaneously.
Thanks everyone that's helped and gave their suggestions: Syncupsolutions,Dragonbaki and to Bogdan for the tip.

Once again, thank you all !

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.