Hey everyone,

I recently make a simple test site on my local server to login as an admin and redirect to an admin based page as well as to log in as a user for the regular user page..When I made the test site..it seems to work fine but when I put it on the site that actually needs to go on the web..it doesn't work..it says that I have multiple undefined errors..and I'm not sure why because when I echo out what I sent from the form..the data shows, including whether or not the submit button has been submitted..I'm at a loss..

Here are the errors

"Notice: Undefined index: username in C:\Program Files (x86)\EasyPHP-5.3.8.1\www\Test\index.php on line 3

Notice: Undefined index: password in C:\Program Files (x86)\EasyPHP-5.3.8.1\www\Test\index.php on line 4

Notice: Undefined index: Submit in C:\Program Files (x86)\EasyPHP-5.3.8.1\www\Test\index.php on line 9"

here is the index.php(which includes a login section starting at line 109)

<?php

$user = $_POST['username'];
$pass = $_POST['password'];

mysql_connect("*********","*****","********");
mysql_select_db("********");

if($_POST['Submit']){
$select = "SELECT * FROM USERS where username='".$_SESSION['$user']."' && password='".$_SESSION['$pass']."'";
$msq = mysql_query($select);
 if(mysql_num_rows($msq)>0)
    {
    while($row = mysql_fetch_array($msq))
          {
            $username = $row['username'];
			session_start();
            $_SESSION['username'] = $username;
            echo $_SESSION['username'];
            
            }
            header("location: checkuser.php");
   }}


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>
</title>
<link rel="stylesheet" type="text/css" href="CSS/style.css" />
<meta name="description" content="This book will give women, men, and teenagers a different perspective on pregnancy and your life immediately following having kids. This story describes my overall experience being pregnant. This book will prepare all women to make sure that they are ready to get pregnant! I hope you enjoy!!!" />
<meta name="keywords" content="***********,teen,teen mother,TEEN MOTHER,struggle,life,Baby,babysitting,childbirth,pregnancy,giving birth,hospital,health,mom,being a mom,parent,being a parent,Ready or Not,books,story,blog,blogs,email,family," />
<script type="text/javascript">
function preload(arrayOfImages) {
    $(arrayOfImages).each(function(){
        $('<Images/>')[0].src = this;
        // Alternatively you could use:
        // (new Images()).src = this;
    });
}

// Usage:

preload([
    'Images/butterfly-background.jpg',
    'Images/book cover2 another version1.jpg',
    'Images/facebook-logo-pink.png'
	'Images/Email-icon.jpg'
	'Images/header-background.jpg'
	'menu-background.jpg'
]);
</script> 
</head>
<body>
<div class="container">
<div id="main-pic">
<a href="AboutMe.html"><div id="main-pic-background"><img src="Images/********.jpeg" width="240px" height="327px" /></div><!-- end of #main-pic-background --></a>
</div><!-- end of #main-pic -->
<div id="side-pic1"><a href="#"><table style="margin-left: 4px; margin-top: 4px;" border="0" width="204px" height="54" cellpadding="0" cellspacing="0">
       <tr>
	<td style="border-top: 1px solid purple; border-left: 1px solid purple; border-bottom: 1px solid purple; padding-left: 5px; padding-right: 15px;"><img src="Images/facebook-logo-pink.png" width="38px" height="38px" /></td>
	<td style="border-top: 1px solid purple; border-right: 1px solid purple; border-bottom: 1px solid purple; color: #000;">Become A Fan of ******** on Facebook</td>
       </tr>
</table></a>
</div><!-- end of #sid-pic1 -->
<div id="side-pic2"><a href="EmailForm.php" target="_blank"><div class="inner-side-pic2"><img src="Images/Email-icon.jpg" width="50px" height="40px" /><div class="inner-side-pic2-text">Shoot ******* an Email!!<!-- end of .inner-side-pic-text --></div></div><!-- end of .inner-side-pic2 --></a></div><!-- end of #side-pic2 -->
<div id="side-pic3">
<a href="Buy.php"><img src="Images/book cover2 another version1.jpg" width="210px" height="300px" /></a></div><!-- end of #side-pic3 -->
<div id="side-pic4"><div class="inner-side-pic4"><h3 style="font-size: 20px; font-weight: bold; margin-left: 10px;"><u>On Sale Nov. 2nd, 2011</u></h3><p class="pic-4-description">Order "Ready Or Not" at these online retalers:</p>
<ul>
	<li><a href="#">amazon.com</a></li>
	<li><a href="#">ebay.com</a></li>
</ul>
</div><!-- end of .inner-side-pic4 -->
</div><!-- end of #side-pic4 -->
<div id="side-pic5">
<div class="inner-side-pic5">
<div class="inner-side-pic5-text">
<h3 style="font-size: 20px; font-weight: bold; margin-left: 10px;"><u>Recent Blog Posts</u></h3>
<ul>
	<li><span class="headline"><b>No blogs Have been posted at this time.<b></span></li><br />
	<li><span class="headline">Please check back later for more updates!</b></span></li>
</ul>
</div><!-- end of inner-side-pic4-text -->
</div><!-- end of .inner-side-pic5 -->
</div><!-- end of #side-pic5 -->
<div id="header">
<div id="nav-header">
<a href="index.php"><h1><i>************</i></h1><h2><i><u>Ready or Not!!</u></i></h2></a>
</div><!-- end of nav-header -->
</div><!-- end of #header -->
<div id="menu">
<ul>
<li><a href="index.php">Home</a></li>
<li><a href="Register1.php">Register</a></li>
<li><a href="AboutMe.html">About Me</a></li>
<li><a href="Blog.php">Blog</a></li>
<li><a href="Buy.php">Buy Now</a></li>
<li><a href="ContactMe.html">Contact Me</a></li>
<li><a href="logout.php">Sign Out</a></li>
</ul>
</div><!-- end of #menu -->
<div id="content">
<div id="login-content">
<u>Log In</u>
<form action="checkuser.php" method="post" name="" id="">
Username:<br />
<input size="10" type="text" name="username" id="username" /><br />
Password:<br />
<input size="10" type="password" name="password" id="password" /><br />
<input type="Submit" name="Submit" value="Submit">
</form>

</div><!--end of #login-content-->
<div id="inner-content">
<div class="subnav">
<p>Latest News...</p>
<div id="main-content">
<h2><i>Ready Or Not, my 1st story, on sale now!</i><br /></h2><br />
<hr size="1px" color="#cccccc" />
<br />
<h2><a href="Buy.php">Ready or Not!!</a></h2>
<h3>Ready or Not, came out Nov. 2nd, 2011. <a href="Buy.php">Order</a> your copy today!!
<br /><br />
<br />
<hr size="1px" color="#cccccc" />
<br />
<h2><a href="Blog.php">Blog</a></h2>
<h3>Here, I will post various topics pretaining to my experiences and would very much appreciate feedback commentary if desired.</h3><br />
<hr size="1px" color="#cccccc" />
<br />
<h2><a href="#">Reach Me!!</a></h2>
<h3>I have an active <a href="#">Facebook</a> page dedicated to my book, where I interact with my readers as well as on here. You can also get information from my <a href="Blog.php">blog</a>. Lets get the conversation started!!</h3>
<br />
<hr size="1px" color="#cccccc" />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<div style="clear: both;"></div>
</div><!-- end of #main-content -->
</div><!-- end of #inner-content -->
</div><!-- end of #content -->
<div id="footer">
<div class="left">
&copy; 2011 *********, All Rights Reserved
</div><!-- end of .left -->
<div class="right">
Web Design by <a href="http://www.facebook.com/pages/Gene-Howell/166880296733102?sk=info" target="_blank">Gene Howell</a>. Hosting by <a href="http://www.godaddy.com/default.aspx" target="_blank">Godaddy.com</a>
</div><!-- end of .right -->
</div><!-- end of #footer -->
</div><!-- end of .container -->
</body>
</html>

Recommended Answers

All 9 Replies

does it only give you that error after you submitt the form or before

try changing the top to this let me know how it goes
also if this is a login script i would say to validate the data
also session start should be on top no spaces

<?PHP
session_start();

if($_POST['Submit']){
$user = $_POST['username'];
$pass = $_POST['password'];
// validate the data
$user = stripslashes($user);
$pass = stripslashes($pass);
$user = mysql_real_escape_string($user);
$pass = mysql_real_escape_string($pass);
 
mysql_connect("*********","*****","********");
mysql_select_db("********");
$select = "SELECT * FROM USERS where username='".$_SESSION['$user']."' && password='".$_SESSION['$pass']."'";
$msq = mysql_query($select);
if(mysql_num_rows($msq)>0)
{
while($row = mysql_fetch_array($msq))
{
$username = $row['username'];

$_SESSION['username'] = $username;
echo $_SESSION['username'];
 
}
header("location: checkuser.php");
}}

well that took away the first set..now the only thing that's left is the submit button..

when I do an if/else statement and echo out if the button has been submitted or not and then get the message "your submit button has been pressed"..shouldn't that mean that it is working? if so then why do I get that error?

'Notice: Undefined index: Submit in C:\Program Files (x86)\EasyPHP-5.3.8.1\www\Test\index.php on line 4'

can you post ur form its hard to follow your code

<form action="checkuser.php" method="post" name="" id="">
Username:<br />
<input size="10" type="text" name="username" id="username" /><br />
Password:<br />
<input size="10" type="password" name="password" id="password" /><br />
<input type="Submit" name="Submit" value="Submit">
</form>

so I fixed the submit issue..I needed to add "isset" to the post variable..but now when it submits..the checkuser.php shows up with a black page..and it doesn't redirect to the designated page depending on whether its an admin or a regular user..

checkuser.php

<?php
error_reporting (E_ALL ^ E_NOTICE);
?>
<?php
session_start();

//connect to db
$connect = mysql_connect("*********","*****","*******");
mysql_select_db("******");



$get = mysql_query("SELECT * FROM users WHERE username ='".$_SESSION['username']."'") or die(mysql_error());
while($row = mysql_fetch_array($get)) 
{
   $admin = $row['user_level'];
         if ($admin == 0)
         {
            header("Location: index.php");
         }
        elseif ($admin == 1) 
        {
           header("Location: Blog-admin-area.php");
        }
      else
      {
         echo "this is an invalid status";
         }
}
?>

why does this work with my test site and not this one?

probley diffrent versions of php and diffrent servers like lamp or wamp
also your $get variable

$select = "SELECT * FROM USERS where username='".$_SESSION['$user']."' && password='".$_SESSION['$pass']."'";

// i think before we were valiadating $user and $pass



$select = "SELECT * FROM USERS where username='".$user."' && password='".$pass."'";

or there is no user because we never set the session

Should I replace my $select query with the second one you have without the session in front of the user and password for the index page?

and I'm using Easy PHP for my local server..EasyPHP-version 5.3.8.1

well I guess this thread has been solved since the undefined errors are gone. I'll post another thread over this blank page that seems to show. Thanks!

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.