PDA

View Full Version : Undefined Variable in code problem



Rockonmetal
04-02-2008, 02:31 AM
A little background information:
this is the fourth part of a comment form on my site... This is the part where the comment gets validated and that the user gets the option of edditing it or posting it. I am having slight problems though... I get:

Notice: Undefined variable: _SESSION in C:\netserver\www\Pureadd\pictures\comment\1c.php on line 8

Notice: Undefined variable: _SESSION in C:\netserver\www\Pureadd\pictures\comment\1c.php on line 9

Notice: Undefined variable: _SESSION in C:\netserver\www\Pureadd\pictures\comment\1c.php on line 10

Notice: Undefined variable: _SESSION in C:\netserver\www\Pureadd\pictures\comment\1c.php on line 11
Here is the code for that page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript" type="text/javascript" src="niceforms.js"></script>
<style type="text/css" media="screen">@import url(niceforms-default.css);</style>
<?php
$username = $_SESSION['Username']; // Line 8
$password = $_SESSION['Password']; // Line 9
$email = $_SESSION['Email']; // Line 10
$ID = $_SESSION['ID']; // Line 11
$rating = $_POST['rating'];
$comment = strip_tags($_POST['Comment']);
$lcomment = strlen($comment);
if($lcomment<=400 && $lcomment>=3){
$correct = 0;
$correct++;
}else{
$correct = $correct*0;
}
if($rating<=5 && $rating>=0){
$correct++;
}else{
$correct = $correct*0;
}
$time = date('h:i:s A');
$date = date('m/d/Y');
?>
</head>
<body>
<div id="container">
<form action="1d.php" method="post" class="niceform">
<br />Hey <?php echo $username;?>! Check your comment to make sure its what you want to say!

<label for="Comment">Your Comment</label>
<br /><?php $comment; ?>
<br />
<label for="rating">Rating:</label>
You are rating the DVD Rewinder at <?php echo $rating; ?> stars.
<br />
<?php
if($correct==2){
echo '<br /><a href="1b.php">Edit your comment and or rating!</a>';
echo '<br /><input type="submit" value="Post Comment" />';
}else{
echo '<br /><a href="1b.php">You need to edit your comment</a>';
}
?>


</form>
</div>
</body>
</html>
Either I don't think I set the Session variables correctly because i just do this to set the Session variables:

$_SESSION['Username'] = $_POST['username'];
It was working before I re-did the code to fix the ad link problem... *Not evident on this page...*

Master_script_maker
04-02-2008, 02:35 AM
Your can set them like that. Only problem is you forgot the most important rule when using sessions, the first line of php should have:
session_start();

Rockonmetal
04-02-2008, 03:05 AM
Thats already there on 1.php *the first of six pages linked in this session...* and when I do put that on any other pages... the browser's php interpretor flips out and can't handle it and throws this on the page:

Could it be that the selected lines of code Line 8-11 need to be in the body? I tried it and it doesn't work... I'll get that error line in a minute...

Rockonmetal
04-02-2008, 06:44 PM
Ok... i have the code for the series of pages here:
1.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript" type="text/javascript" src="niceforms.js"></script>
<style type="text/css" media="screen">@import url(niceforms-default.css);</style>
<title>Pureadd</title>
</head>
<body>
<div id="container">
<form action="1a.php" class="niceform" method="post">
<label for="Username">Username:</label>
<br />
<input type="text" id="textinput" name="Username" size="12"/>
<br />
<br />
<label for="Password">Password:</label>
<br />
<input type="Password" id="passwordinput" name="Password" size="12"/>
<br />
<input type="submit" value="Login"/>
</form>
</div>
</body>
</html>
1a.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<?php
$_SESSION['Username'] = $_POST['Username'];
$username = $_POST['Username'];
$_SESSION['Password'] = $_POST['Password'];
$password = $_POST['Password'];
$con = mysql_connect("localhost","admin","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("markmon_pureadd_userbase", $con);

$result = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password' ");

while($row = mysql_fetch_array($result))
{
$combination = "" . $username . "" . $password . "";
$mysqlcombination = "" . $row['username'] . "" . $row['password'] . "";
if($combination=$mysqlcombination){
if($row['rights']=="Suspended"){
$ID= $row['ID'];
echo "Sorry your account has been suspended see your account's suspension report here:";
echo '<a href="http://www.pureadd.com/report.php?p=' . $ID . '">Click to read</a>';
}elseif($row['rights']=="Full"){
$_SESSION['ID'] = $row['ID'];
$_SESSION['Email'] = $row['email'];
include("login_log.php");
include("1b.php");
}
}elseif($combination!=$mysqlcombination || $row['rights']!="Full"){
include("redirect.php");
}
}

?>
</body>
1b.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript" type="text/javascript" src="niceforms.js"></script>
<style type="text/css" media="screen">@import url(niceforms-default.css);</style>
</head>
<body>
<?php
$username = $_SESSION['Username'];
$password = $_SESSION['Password'];
$email = $_SESSION['Email'];
$ID = $_SESSION['ID'];
?>
<div id="container">
<form action="1c.php" method="post" class="niceform">
<br />Hey <?php echo $username; ?>! Your gonna make a comment for the DVD Rewinder! Remember to keep your comment's content PG-13. Vulgar messages containing content past the PG-13 mark are deteled and also result in suspension of your account for one to three weeks depending on the vulgarity of the comment! Thanks! Here some helpful tips when leaving comments:
<ol>
<li>Try to tell what made you laugh</li>
<li>Why you think this deserves your rating</li>
<li>Express what you think but don't say you know something behind the scenes!</li>
<li>ABSOLUTELY NO SIGNITURES! (They're really annoying and waste space)</li>
</ol>
<br />

<label for="Comment">Your Comment</label>
<br /><textarea id="textareainput" name="Comment" cols="50" rows="6"></textarea>
<br />Only text please... All scripts will be removed... Any comments containing links will be deleted even if they link to another image on Pureadd. If you want to compare its ok to!
<label for="rating">Rating:</label>
<br /><input type="radio" id="option1" value="0" name="rating" />
<label for="option1">0 Stars (Not even funny)</label>
<br /><input type="radio" id="option2" value="1" name="rating" />
<label for="option2">1 Star (Chuckled)</label>
<br /><input type="radio" id="option3" value="2" name="rating" />
<label for="option3">2 Stars (Laughed)</label>
<br /><input type="radio" id="option4" value="3" name="rating" />
<label for="option4">3 Stars (Laughed for half a minute)</label>
<br /><input type="radio" id="option5" value="4" name="rating" />
<label for="option5">4 Stars (Laughed for a minute)</label>
<br /><input type="radio" id="option6" value="5" name="rating" />
<label for="option5">5 Stars (Laughed or still laughing hysterically) </label>
<br />
<br /><input type="submit" value="Preview Comment" />
</form>
</div>
</body>
</html>
1c.php: (where problem is occuring)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript" type="text/javascript" src="niceforms.js"></script>
<style type="text/css" media="screen">@import url(niceforms-default.css);</style>
</head>
<body>
<?php
$username = $_SESSION['Username'];
$password = $_SESSION['Password'];
$email = $_SESSION['Email'];
$ID = $_SESSION['ID'];
$rating = $_POST['rating'];
$comment1 = $_POST['Comment'];
$comment = strip_tags($comment1);
$lcomment = strlen($comment);
if($lcomment<=400 && $lcomment>=3){
$correct = 0;
$correct++;
}else{
$correct = $correct*0;
}
if($rating<=5 && $rating>=0){
$correct++;
}else{
$correct = $correct*0;
}
$time = date('h:i:s A');
$date = date('m/d/Y');
?>
<div id="container">
<form action="1d.php" method="post" class="niceform">
<br />Hey <?php echo $username;?>! Check your comment to make sure its what you want to say!

<label for="Comment">Your Comment</label>
<br /><?php $comment; ?>
<br />
<label for="rating">Rating:</label>
You are rating the DVD Rewinder at <?php echo $rating; ?> stars.
<br />
<?php
if($correct==2){
echo '<br /><a href="1b.php">Edit your comment and or rating!</a>';
echo '<br /><input type="submit" value="Post Comment" />';
}else{
echo '<br /><a href="1b.php">You need to edit your comment</a>';
}
?>


</form>
</div>
</body>
</html>
Either the computer hates me or I haven't registered the Session variables correctly...
Thanks

thetestingsite
04-02-2008, 07:53 PM
I see nothing in any of the pages you pointed to above that has the code to begin the session:



<?php
session_start();
?>


should be placed at the very beginning of the php pages.

Hope this helps.

Rockonmetal
04-02-2008, 08:07 PM
K thanks...