pontiac007 Posted March 18, 2007 Share Posted March 18, 2007 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. Quote Link to comment Share on other sites More sharing options...
chawezul Posted March 18, 2007 Share Posted March 18, 2007 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 Quote Link to comment Share on other sites More sharing options...
pontiac007 Posted March 18, 2007 Author Share Posted March 18, 2007 it doesn't work. is there any other way to defined the variables? in PHP? Quote Link to comment Share on other sites More sharing options...
per1os Posted March 18, 2007 Share Posted March 18, 2007 <?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 "" Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted March 18, 2007 Share Posted March 18, 2007 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. Quote Link to comment Share on other sites More sharing options...
shaunrigby Posted March 18, 2007 Share Posted March 18, 2007 What is the purpose of this line?? @$_SESSION['idstud']=$_SESSION['idstud']; Quote Link to comment Share on other sites More sharing options...
trq Posted March 18, 2007 Share Posted March 18, 2007 Dont use the error supressor (@). What exactly is the point of this line? $_SESSION['idstud']=$_SESSION['idstud']; It doesn't do anything. Quote Link to comment Share on other sites More sharing options...
pontiac007 Posted March 20, 2007 Author Share Posted March 20, 2007 Dont use the error supressor (@). What exactly is the point of this line? $_SESSION['idstud']=$_SESSION['idstud']; It doesn't do anything. Ahh... i suppose to dio it this way... code: $_SESSION['idstud']=$_POST['idstud']; Thanx guys.. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.