Jump to content

Notice: Undefined variable: idstud in c:\program files\eas.....


pontiac007

Recommended Posts

guys, why did i keep seeing this error?

Notice: Undefined variable: idstud in c:\program files\easyphp1-8\www\dcs\welcome_stud.php on line  153 //these appears in my login_stud page

 

ok, these are my codes in welcome_stud:

 

codes:

 

<?php 
session_start();

include "conn.php";
@$_SESSION['idstud']=$_SESSION['idstud'];

if(isset($_SESSION['idstud']))
{
$idstud=$_SESSION['idstud'];
}?>

<?php

//$idstud=$_POST['idstud'];
//$studname=$_POST['noic'];

echo "<center><font face='Verdana' size='2' color='white' ><strong>Welcome";
echo  $_SESSION['idstud'];
echo "To Online Teaching Assessment System. \nYou are now an authorised student to evaluate your lecturer.</strong>";

$dbservertype='mysql';
$servername='localhost';
$dbusername='root';
$dbpassword='';
$dbname='tesco';
$cariseksyen='';

connecttodb($servername,$dbname,$dbusername,$dbpassword);
function connecttodb($servername,$dbname,$dbuser,$dbpassword)
{
	global $link;
	$link=mysql_connect ("$servername","$dbuser","$dbpassword");
	if(!$link){die("Could not connect to MySQL");}
	mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error());
}
$Studentname = mysql_query("SELECT * FROM student WHERE idstud='idstud'") 
or die(mysql_error()); 

while($name = mysql_fetch_array( $Studentname ))
{
echo "<br />Thank You "; echo $name['studname']." for Your Co-operation.<br />";
} 
?>

<?php			
$query = ("select studname from student where idstud='$idstud'");
$result = mysql_query($query);

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$studname= $row['studname'];

echo "<font face='Verdana' color ='blue' size='2' >{$row['studname']} <br>";
}
	  ?> 

 

i intend to do session to bring informations of the person who log in to other pages in the system so that the system able to recognizes him. i've succeed on that but above arror keep poppin up.

 

How to define variables??

 

help me please.

 

 

 

 

 

 

 

Link to comment
Share on other sites

You need to tell PHP which session values to take as well as to set, so You'd go

 

session_start();
session_register("idstud");

 

session_register() will "tell" the computer that you are going to allow reading and writing of a session value of whatever you input. Otherwise it doesn't know that. After that you can set and access it from the public field

 

$_SESSION["idstud"];

 

Hope that helps

Link to comment
Share on other sites

<?php
session_start();

include "conn.php";
@$_SESSION['idstud']=$_SESSION['idstud'];

// define variables to avoid notice
$idstud = "";

if(isset($_SESSION['idstud']))
{
$idstud=$_SESSION['idstud'];
}?>

<?php

//$idstud=$_POST['idstud'];
//$studname=$_POST['noic'];

echo "<center><font face='Verdana' size='2' color='white' ><strong>Welcome";
echo  $_SESSION['idstud'];
echo "To Online Teaching Assessment System. \nYou are now an authorised student to evaluate your lecturer.</strong>";
   
   $dbservertype='mysql';
   $servername='localhost';
   $dbusername='root';
   $dbpassword='';
   $dbname='tesco';
   $cariseksyen='';

   connecttodb($servername,$dbname,$dbusername,$dbpassword);
   function connecttodb($servername,$dbname,$dbuser,$dbpassword)
   {
      global $link;
      $link=mysql_connect ("$servername","$dbuser","$dbpassword");
      if(!$link){die("Could not connect to MySQL");}
      mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error());
   }
   $Studentname = mysql_query("SELECT * FROM student WHERE idstud='idstud'")
   or die(mysql_error());

   while($name = mysql_fetch_array( $Studentname ))
   {
   echo "
Thank You "; echo $name['studname']." for Your Co-operation.
";
   }
?>

<?php         
$query = ("select studname from student where idstud='$idstud'");
$result = mysql_query($query);

   while($row = mysql_fetch_array($result, MYSQL_ASSOC))
   {
   $studname= $row['studname'];

echo "<font face='Verdana' color ='blue' size='2' >{$row['studname']}
";
}
      ?> 

 

This way if your script calls idstud, it is a variable and if it was not assigned anything it is left as just ""

Link to comment
Share on other sites

this is from the php.ini file about notice errors:

 

; E_NOTICE          - run-time notices (these are warnings which often result
;                     from a bug in your code, but it's possible that it was
;                     intentional (e.g., using an uninitialized variable and
;                     relying on the fact it's automatically initialized to an
;                     empty string)

 

so if you wish you can turn notices off, but its up to you. because usually they are intentional things.

Link to comment
Share on other sites

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.