Jump to content

Why am I being returned to index.php?


tommybfisher

Recommended Posts

Hi,

I have a dynamic php page - index.php. In one section (called nav.php) is the user login input boxes (username and password). If the user navigates to the registration section, nav.php remains (including the login form) and the registration form is displayed in the main area.

I currently do not have the registration form linked with the MySql database yet as I am just testing. However, when the submit button is pressed on the registration form, it always returns the user to index.php. I have tried different settings in the form action page, even setting it to a new page entirely (I simply want it to send the form back to the same page).

Does anyone know why it is always sending me back to index.php? Is it because when the registration form is viewed by the user, there are two forms on display (login in the nav.php section and registration in regform.php)?

Any advice would be appreciated.

Thanks,

Tommy

 

My code is below.

The first snippet is the code for index.php:

<?php

// login check

include 'inc/functions.php';
//include 'inc/resources/init.php';

if (loggedin())
{
	header ("Location: loggedin.php");
	exit();
}

if(isset($_POST['login']) && !empty($_POST['login']))
{
	if ($_POST['login'])
	{
		// get data
		$email = $_POST['email'];
		$password = $_POST['password'];
		if(isset($_POST['rememberme']) && !empty($_POST['rememberme']))
			$rememberme = $_POST['rememberme'];

		if ($email && $password)
		{
			$login = mysql_query("SELECT * FROM users WHERE email='$email'");
			while ($row = mysql_fetch_assoc($login))
			{
				$db_password = $row['password'];
				if (md5($password)==$db_password)
					$loginok=TRUE;
				else
					$loginok=FALSE;

				if ($loginok == TRUE)
				{

					if (isset($rememberme) && $rememberme == "on")
						setcookie("login",$email, time()+7200);
					else if (!isset($rememberme))
						$_SESSION['login']=$email;

					header ("Location: loggedin.php");
					exit();
				}
				else
					die("incorrect username/password");
			}
		}
	}
}
?>
<?php

// check for lang and set cookie

$exp = time() + 86400;

if(isset($_GET['lang']) && !empty($_GET['lang']))
	$lang = $_GET['lang'];

if(isset($_GET['newlang']) && !empty($_GET['newlang']))
	$newlang = $_GET['newlang'];

if (isset($newlang))
{
	if ($lang == "english")
	{
		setcookie ("lang","english", $exp);
		include "lang/english.php";
	}
	else
	{
		setcookie ("lang","suomi", $exp);
		include "lang/suomi.php";
	}
}
else
{	
	if (isset($_COOKIE["lang"]))
	{
		if ($_COOKIE["lang"] == 'english')
			{
			include "lang/english.php";
			}
		else	
			{
			include "lang/suomi.php";
			}
	}
	else
	{
		include "lang/suomi.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" xml:lang="en" lang="en">

<head>

<meta http-equiv="content-type" content="text/html; charset=utf-8" />

<meta name="description" content="" />

<meta name="keywords" content="" />

<meta name="author" content="" />

<link rel="stylesheet" type="text/css" href="/makuboxicom/style.css" media="screen" />

<title></title>

</head>

<body>
    
	<div id="wrapper">        	
        
        	<?php include('inc/primary/header.php'); ?>
            
		<?php 
			if(isset($loginok) && !empty($loginok))
			{
				if ($loginok == TRUE)
					{
						include ('inc/login/lgnav.php');
					}
				else
					{
						include('inc/nav.php'); 
					}
			}
			else
				include('inc/nav.php'); 
		?>
            
            <?php
				if(isset($_GET['page']) && !empty($_GET['page']))
				{
					$page=$_GET['page'];
					if ($page)
					{
						if (
						!strpos($page,".")
						)
						{

						$path = "inc/".$page.".php";
							if (file_exists($path))
							{
								include ($path);	
							}
							else
							{
								echo "Page does not exist";
							}
						}
						else
							{
							echo "Not allowed";
							}
					}
					else
					{
						include ('inc/primary/mainbody.php');
					}
				}
				else
					include ('inc/primary/mainbody.php');
          		?>
            
            <?php include('inc/primary/footer.php'); ?>
            
	</div> 

</body>

</html>

 

Here is the code for nav.php:

<div id="nav">
  
    <div id="navbuttons">
        <a href='index.php?page=primary/mainbody'><?php echo $home ?></a> •
        <a href='index.php?page=primary/mainbodyinfo'><?php echo $info ?></a> •
        <a href='index.php?page=primary/mainbodyproducts'><?php echo $products ?></a> •
        <a href="index.php?page=primary/registration"><?php echo $register ?></a>
    </div> <!-- end #navbuttons -->
    
    <div id="inputlogin">
    	<form name="login" action="index.php" method="POST">
         email 
      
        		<input name="email" type="text" placeholder='email'/>
  
         <?php echo $passwordlbl ?> 

            	<input name="password" type="password" placeholder=<?php echo $passwordlbl ?>>

    </div> <!-- end #inputlogin-->
    
    <div id="tableremember">    
        <table>
            <tr>
                <td>
                	<?php echo $rememberme ?> <input name="rememberme" type="checkbox"/>   
                </td>
                <td>
               		<input name="login" type="submit" value="<?php echo $loginbtn ?>"/>
               	</td>
            </tr>
            <tr>
            	<td>
                	<a href="">forgotten password</a>
                </td>
            </tr>
        </table>
        
       
    </div> <!-- end #tableremember -->
    
    <div id="langselect">
    	<a href="index.php?newlang=y&lang=suomi">Suomi</a><br />
        <a href="index.php?newlang=y&lang=english">English</a>
    </div> <!-- end #langselect -->
    
</div> <!-- end #nav -->

 

And this is the code for the registration form:

<?php

// form data

if(isset($_POST['submit']) && !empty($_POST['submit'])) 
	$rgsubmit = $_POST['submit'];
if(isset($_POST['firstname']) && !empty($_POST['firstname']))
	$rgfirstname = $_POST['firstname'];
if(isset($_POST['secondname']) && !empty($_POST['secondname']))
	$rgsecondname = $_POST['secondname'];
if(isset($_POST['address']) && !empty($_POST['address']))
	$rgaddress = $_POST['address'];
if(isset($_POST['postcode']) && !empty($_POST['postcode']))
	$rgpostcode = $_POST['postcode'];
if(isset($_POST['postarea']) && !empty($_POST['postarea']))
	$rgpostarea = $_POST['postarea'];
if(isset($_POST['phone']) && !empty($_POST['phone']))
	$rgphone = $_POST['phone'];
if(isset($_POST['email']) && !empty($_POST['email']))
	$rgemail = $_POST['email'];
if(isset($_POST['password']) && !empty($_POST['password']))
	$rgpassword = $_POST['password'];
if(isset($_POST['passwordrepeat']) && !empty($_POST['passwordrepeat']))
	$rgpasswordrepeat = $_POST['passwordrepeat'];


?>

<table width="620px" cellpadding="0" cellsoacing="0">
<tr>
    	<td width="100px">
        
        	<h1>
			<?php echo $register; ?>
            </h1>

	</td>
</tr>
    
    <form name="register" action="index.php?page=primary/registration" method="POST">

    <tr>
    	<td>
        	<?php echo $firstnamelbl; ?>
        </td>
        
        <td>
        	<input type='text' name='firstname'>
        </td>
    </tr>
    
   	<tr>
    	<td>
        	<?php echo $secondnamelbl; ?>
        </td>
        
    <td>
        	<input type='text' name='secondname'>
        </td>
    </tr>
    
    <tr>
    	<td>
        	<?php echo $addresslbl; ?>
        </td>
        
        <td>
        	<input type='text' name='address'>
        </td>
    </tr>
    
  	<tr>
    	<td>
        	<?php echo $postcodelbl; ?>
        </td>
        
        <td>
        	<input type='text' name='postcode'>
        </td>
    </tr>
    
  	<tr>
    	<td>
        	<?php echo $postarealbl; ?>
        </td>
        
        <td>
        	<input type='text' name='postarea'>
        </td>
    </tr>
    
   	<tr>
    	<td>
        	<?php echo $phonelbl; ?>
        </td>
        
        <td>
        	<input type='text' name='phone'>
        </td>
    </tr>
    
   	<tr>
    	<td>
        	Email
        </td>
        
        <td>
        	<input type='text' name='email'>
        </td>
    </tr>
    
   	<tr>
    	<td>
        	<?php echo $passwordlbl2; ?>
        </td>
        
        <td>
        	<input type='password' name='password'>
        </td>
    </tr>
    
  	<tr>
    	<td>
        	<?php echo $passwordrepeatlbl; ?>
        </td>
        
        <td>
        	<input type='password' name='passwordrepeat'>
        </td>
    </tr>
    
      	<tr>
    	<td>
        	
        </td>
        
        <td>
        	<input type='submit' name='submit' value="<?php echo $register; ?>">
        </td>
    </tr>
    
    </form>
</table>

Link to comment
Share on other sites

Yes it is the last section that is taking me back to index.php. I have tried putting the name of the form into the form action, I've also tried putting in the same page's file name, I've tried $_SERVER['PHP_SELF'], and I've also tried an external website address, all of which takes me back to index.php. This all makes me sure that the problem is not in the form action itself, but somewhere before...

Could it have something to do with the two forms being on the same page? They both have separate names though, so I don't see why it should.

 

(By the way, from the code of the first form (login) I uploaded, I found that I forgot the </form> tag. I put this in hoping that this was the problem, but I still had the same problem.)

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.