sir i am doing my project and i am using session array to save some variables that can be accessed at any page but i am unable to access the values saved in session array

<html>
    <head><title>student home page</title></head>
    <body bgcolor="lightblue"><h1>well come to student login page</h1>
        <form name="f1" action="" method="post">
            <table border="1" bgcolor="silver">
                <tr><td>username:<input type="text" name="uname"/></td><td>plz enter your id as username</td></tr>
                <tr><td>password:<input type="password" name="pwd"/></td><td>use a_z and 1_9 as password</td><tr>
                 <tr><td colspan="2" align="center"><input type="submit" name="sub"/></td><tr>
            </table>    
        </form>
</html>
<?php

include "connection.php";
//now, let's register our session variables
//finally, let's store our posted values in the session variables
if(isset($_POST['sub']))
{
    $user=$_POST['uname'];
    $p=$_POST['pwd'];
    $sql="select count(*) from student where ( id='".$user."'and password='".$p."' and status='active' or 'unblock')";
    $qry=  mysql_query($sql);
    $result=  mysql_fetch_array($qry);
    if($result[0]>0)
        {
        session_start();
    $_SESSION['uname']=$user;
    header('location:radio.php');
    }
    else 
        echo "your user name or password is incorrect or you are blocked by your administrator";
}
?>




<?php
include "connection.php";
if(isset ($_SESSION['uname']));
echo $_SESSION['uname'];

?>

i get the error of $_session is undefined kindly guide me

sir i want to solve online quiz therefore i need a code snippet in php so that i acn fetch one record from table so that i can select one choice and save it into another table then get the next record from the first table as in online quizes goes on please help me in this regard

question:
A:
B:
C:
D:
save and next

Member Avatar for iamthwee

Are you saying question 2 depends on the answer to question 1. I don't think using sessions is the way to go if that is what you mean.

You can't call session_start() or header() after you've sent any part of the page itself. And you need to use mysql_real_escape_string() on the user form data to prevent hacking. So, your code should be something like:

<?php

include "connection.php";
session_start();

$errorMsg = '';

//now, let's register our session variables
//finally, let's store our posted values in the session variables
if(isset($_POST['sub'])) {
  $user=mysql_real_escape_string($_POST['uname']);
  $p=mysql_real_escape_string($_POST['pwd']);
  $sql="select count(*) from `student` where ( `id`='".$user."'and `password`='".$p."' and `status`='active' or 'unblock')";
  $qry= mysql_query($sql);
  $result= mysql_fetch_array($qry);
 if($result[0]>0) {
  $_SESSION['uname']=$user;
  header('location:radio.php');
   } else {
  $errorMsg = "Your user name or password is incorrect or you are blocked by your administrator";
 }
} endif isset($_POST['sub'])

?><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>student home page</title>
</head>
<body bgcolor="lightblue">
<?php
 if ($errorMsg == '') {

<h1>Welcome to Student Login Page</h1>
<form name="f1" action="" method="post">
<table border="1" bgcolor="silver">
<tr><td>username:<input type="text" name="uname"/></td><td>plz enter your id as username</td></tr>
<tr><td>password:<input type="password" name="pwd"/></td><td>use a_z and 1_9 as password</td><tr>
<tr><td colspan="2" align="center"><input type="submit" name="sub"/></td><tr>
</table>
</form><?php
  } else {
?><p><?php echo $errorMsg; ?></p><?php
 } // endif
?></body>
</html><?php
 } // endif isset($_POST['sub'])
?>

sir i want to get the values of session array at more than one pages so gve me the sollution with code snippet

code must be in php

i wnt to get one record from a database table after manuplating it i will get the next record so kindly give me the sollutiuon how can i get one record at a time

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.