Page 1 of 1
Ridiculous, easy problem.
Posted: Wed Jul 07, 2010 9:43 am
by Steji
I'm having a nightmare with this. It's a simple form using the POST method but the script on the other side is not picking any of the variables up that have been sent. Can anyone tell me why?
This is the header.php file containing the form, which is included by the index.php.
Code: Select all
<form action="password.php" method="post" name="loginform" id="loginform" onSubmit="return valid(this);">
<table width="155" border="0" cellspacing="0" cellpadding="0" class="login">
<tr>
<td colspan="2">
<input name="email" type="text" id="email"/>
</td>
</tr>
<tr>
<td height="20" colspan="2">
<input name="pass" type="password" />
</td>
<td><input type="submit" name="loginbutton" id="loginbutton" value="Login" /></td>
</tr>
<tr>
<?php
if($_SESSION['cid']=="" and !isset($_SESSION['login']))
{?>
<!--<td width="66" align="left"><a href="javascript:submitForm();"><img src="images/login-button.gif" alt="Login" width="60" height="22" /></a></td>-->
<td width="89" align="right"><img src="images/register.gif" alt="Register" width="83" height="22" /></td>
<?php
} else
{ ?>
<td width="66" align="left"><a href="myaccount.php"><img src="images/myaccount.gif" alt="My account" width="60" height="22" /></a></td>
<td width="89" align="right"><img src="images/logout.gif" alt="Logout" width="83" height="22" /></td>
<?php
} ?>
<td><input type="hidden" name="redirect" value="<?=$_GET["goto"];?>" /></td>
</tr>
</table>
</form>
And here is the script it is being sent to, password.php.
Code: Select all
include("connection.inc.php");
$emailnew=$_POST['email'];
if(isset($_POST['loginbutton'])) {
echo "submit works";
}
else {
echo "login is not working";
}
echo $_POST['email'];
Re: Ridiculous, easy problem.
Posted: Wed Jul 07, 2010 9:56 am
by Jade
Have you tried doing print_r($_POST); in the password.php page?
Re: Ridiculous, easy problem.
Posted: Wed Jul 07, 2010 10:00 am
by Steji
Jade wrote:Have you tried doing print_r($_POST); in the password.php page?
That returns Array ( )
??
Re: Ridiculous, easy problem.
Posted: Wed Jul 07, 2010 10:03 am
by AbraCadaver
Could be some problem in the javascript function valid(). Try removing the onSubmit="return valid(this);" to isolate.
Re: Ridiculous, easy problem.
Posted: Wed Jul 07, 2010 10:08 am
by Steji
AbraCadaver wrote:Could be some problem in the javascript function valid(). Try removing the onSubmit="return valid(this);" to isolate.
Good thinking, but its still the same.
Array ( ) login is not working
Warning: Cannot modify header information - headers already sent by (output started at D:\inetpub\vhosts\northerngraphic.co.uk\httpdocs\password.php:4) in D:\inetpub\vhosts\northerngraphic.co.uk\httpdocs\password.php on line 124
Re: Ridiculous, easy problem.
Posted: Wed Jul 07, 2010 10:13 am
by AbraCadaver
Steji wrote:AbraCadaver wrote:Could be some problem in the javascript function valid(). Try removing the onSubmit="return valid(this);" to isolate.
Good thinking, but its still the same.
Array ( ) login is not working
Warning: Cannot modify header information - headers already sent by (output started at D:\inetpub\vhosts\northerngraphic.co.uk\httpdocs\password.php:4) in D:\inetpub\vhosts\northerngraphic.co.uk\httpdocs\password.php on line 124
We'd need to see all of the password.php code to tell.
Re: Ridiculous, easy problem.
Posted: Wed Jul 07, 2010 10:18 am
by Steji
AbraCadaver wrote:Steji wrote:AbraCadaver wrote:Could be some problem in the javascript function valid(). Try removing the onSubmit="return valid(this);" to isolate.
Good thinking, but its still the same.
Array ( ) login is not working
Warning: Cannot modify header information - headers already sent by (output started at D:\inetpub\vhosts\northerngraphic.co.uk\httpdocs\password.php:4) in D:\inetpub\vhosts\northerngraphic.co.uk\httpdocs\password.php on line 124
We'd need to see all of the password.php code to tell.
Without trying to echo the variables it just sends me back to the index with err=1 in the url.
Code: Select all
<?
include("connection.inc.php");
$emailnew=$_POST['email'];
print_r($_POST);
if(isset($_POST['loginbutton'])) {
echo "submit works";
}
else {
echo "login is not working";
}
echo $_POST['email'];
$regemail = stripslashes($_GET['regemail']);
$regpass = stripslashes($_GET['regpass']);
$page = "";
if (isset($_POST['goto'])) {
$page = base64_decode($_POST['goto']);
} else if (isset($_GET['goto'])) {
$page = base64_decode($_GET['goto']);
}
if($_POST['email']=="")
{
if($_POST['email2']!="")
{
$emailnew = $_POST['email2'];
}
}
$pass=$_POST['pass'];
if($_POST['pass']=="")
{
if($_POST['pass2']!="")
{
$pass = $_POST['pass2'];
}
}
$remember = $_POST['rememberme'];
if($regemail !="")
{
$emailnew = $regemail;
}
if($regpass !="")
{
$pass = $regpass;
}
$query="select * from registration where email='$emailnew' and pass_word='$pass'";
$result=mysql_query($query);
$total = mysql_num_rows($result);
if($total>0)
{
echo "here";
$row=mysql_fetch_array($result);
if($row['customer_status']=='0')
{
/*if($_REQUEST["productid"]!="")
{
$_SESSION['login'] = true;
$_SESSION['emailaddress'] = $row["email"];
$_SESSION['cid'] = $row["id"];
if ($remember == "checked") { //Remember user
setcookie(ini_get("session.name"),session_id(),time()+(84600*30*12));
}
header("location: item-details.php?prid=".$_REQUEST["productid"]);
exit;
}*/
$_SESSION['login'] = true;
$_SESSION['emailaddress'] = $row["email"];
$_SESSION['cid'] = $row["id"];
if ($remember == "checked") { //Remember user
//setcookie(ini_get("session.name"),session_id(),time()+(84600*30*12));
$cookie_time = (3600 * 24 * 30); // 30 days
$cookie_name = 'siteAuth';
$password_hash = md5($pass); // will result in a 32 characters hash
setcookie ($cookie_name, 'usr='.$emailnew.'&hash='.$password_hash, time() + $cookie_time);
}
if($_POST['redirect']!="")
{
header("location:".base64_decode($_POST['redirect']));
exit;
}
elseif($page!="")
{
header("Location:$page");
exit;
}
elseif($regemail!="")
{
header("Location: register-success.php?message=1");
exit;
}
else
{
header("Location: myaccount.php");
exit;
}
}
else
{
if($_REQUEST["page"]!="")
{
header("Location: login.php?err=3");
exit;
}
else
{
header("Location: index.php?err=4");
exit;
}
}
}
else
{
if($_REQUEST["page"]!="")
{
header("Location: login.php?err=2");
}
else
{
header("Location: index.php?err=1");
}
}
?>
Re: Ridiculous, easy problem.
Posted: Wed Jul 07, 2010 10:31 am
by pickle
Steji wrote:Jade wrote:Have you tried doing print_r($_POST); in the password.php page?
That returns Array ( )
??
That means none of the form variables are being sent. $_POST is always present, and will always be an array. Only if a form is submitted will $_POST be populated.
Is the form being submitted at all? What happens if you try to reload the page after you submit the form? Does it ask you to resubmit form data or does it happily reload? If it doesn't ask you to resubmit, then your form isn't being submitted in the first place.
Re: Ridiculous, easy problem.
Posted: Wed Jul 07, 2010 10:39 am
by Steji
pickle wrote:Steji wrote:Jade wrote:Have you tried doing print_r($_POST); in the password.php page?
That returns Array ( )
??
That means none of the form variables are being sent. $_POST is always present, and will always be an array. Only if a form is submitted will $_POST be populated.
Is the form being submitted at all? What happens if you try to reload the page after you submit the form? Does it ask you to resubmit form data or does it happily reload? If it doesn't ask you to resubmit, then your form isn't being submitted in the first place.
It mustn't be being submitted because it isn't asking me to resend the data. Why would my submit button not be submitting the data?
Re: Ridiculous, easy problem.
Posted: Wed Jul 07, 2010 10:48 am
by Jade
Are you using nested <form> tags anywhere? for instance:
Code: Select all
<form action=post>
... form stuff here
<form action=post>
..more form stuff here
</form>
</form>
Re: Ridiculous, easy problem.
Posted: Wed Jul 07, 2010 11:12 am
by pickle
You're using <a> elements to trigger form submission, not <input> elements. When the link is clicked, it is followed - regardless of what Javascript you have running. If you want to have the form submitted when you click the link, have your submitForm() function return boolean false.
Re: Ridiculous, easy problem.
Posted: Wed Jul 07, 2010 12:30 pm
by Jonah Bron
Steji wrote:Without trying to echo the variables it just sends me back to the index with err=1 in the url.
Code: Select all
<?
include("connection.inc.php");
$emailnew=$_POST['email'];
print_r($_POST);
if(isset($_POST['loginbutton'])) {
echo "submit works";
}
else {
echo "login is not working";
}
echo $_POST['email'];
$regemail = stripslashes($_GET['regemail']);
$regpass = stripslashes($_GET['regpass']);
$page = "";
if (isset($_POST['goto'])) {
$page = base64_decode($_POST['goto']);
} else if (isset($_GET['goto'])) {
$page = base64_decode($_GET['goto']);
}
if($_POST['email']=="")
{
if($_POST['email2']!="")
{
$emailnew = $_POST['email2'];
}
}
$pass=$_POST['pass'];
if($_POST['pass']=="")
{
if($_POST['pass2']!="")
{
$pass = $_POST['pass2'];
}
}
$remember = $_POST['rememberme'];
if($regemail !="")
{
$emailnew = $regemail;
}
if($regpass !="")
{
$pass = $regpass;
}
$query="select * from registration where email='$emailnew' and pass_word='$pass'";
$result=mysql_query($query);
$total = mysql_num_rows($result);
if($total>0)
{
echo "here";
$row=mysql_fetch_array($result);
if($row['customer_status']=='0')
{
/*if($_REQUEST["productid"]!="")
{
$_SESSION['login'] = true;
$_SESSION['emailaddress'] = $row["email"];
$_SESSION['cid'] = $row["id"];
if ($remember == "checked") { //Remember user
setcookie(ini_get("session.name"),session_id(),time()+(84600*30*12));
}
header("location: item-details.php?prid=".$_REQUEST["productid"]);
exit;
}*/
$_SESSION['login'] = true;
$_SESSION['emailaddress'] = $row["email"];
$_SESSION['cid'] = $row["id"];
if ($remember == "checked") { //Remember user
//setcookie(ini_get("session.name"),session_id(),time()+(84600*30*12));
$cookie_time = (3600 * 24 * 30); // 30 days
$cookie_name = 'siteAuth';
$password_hash = md5($pass); // will result in a 32 characters hash
setcookie ($cookie_name, 'usr='.$emailnew.'&hash='.$password_hash, time() + $cookie_time);
}
if($_POST['redirect']!="")
{
header("location:".base64_decode($_POST['redirect']));
exit;
}
elseif($page!="")
{
header("Location:$page");
exit;
}
elseif($regemail!="")
{
header("Location: register-success.php?message=1");
exit;
}
else
{
header("Location: myaccount.php");
exit;
}
}
else
{
if($_REQUEST["page"]!="")
{
header("Location: login.php?err=3");
exit;
}
else
{
header("Location: index.php?err=4");
exit;
}
}
}
else
{
if($_REQUEST["page"]!="")
{
header("Location: login.php?err=2");
}
else
{
header("Location: index.php?err=1");
}
}
?>
That "headers already sent" error is being given because you have to set cookies and stuff before any output at all.
Re: Ridiculous, easy problem.
Posted: Thu Jul 08, 2010 3:18 am
by Steji
Jade wrote:Are you using nested <form> tags anywhere? for instance:
Code: Select all
<form action=post>
... form stuff here
<form action=post>
..more form stuff here
</form>
</form>
I'm not unfortunately.
pickle wrote:You're using <a> elements to trigger form submission, not <input> elements. When the link is clicked, it is followed - regardless of what Javascript you have running. If you want to have the form submitted when you click the link, have your submitForm() function return boolean false.
I'm not sure what you mean? I have:
Code: Select all
<form action="password.php" method="post" name="loginform" id="loginform" onSubmit="return valid(this);">
<input name="email" type="text" id="email"/>
<input name="pass" type="password" />
<input type="submit" name="loginbutton" id="loginbutton" value="Login" />
The javascript one has been commented out for now until I can get the basic form working.
Jonah Bron wrote:Steji wrote:Without trying to echo the variables it just sends me back to the index with err=1 in the url.
Code: Select all
<?
include("connection.inc.php");
$emailnew=$_POST['email'];
print_r($_POST);
if(isset($_POST['loginbutton'])) {
echo "submit works";
}
else {
echo "login is not working";
}
echo $_POST['email'];
$regemail = stripslashes($_GET['regemail']);
$regpass = stripslashes($_GET['regpass']);
$page = "";
if (isset($_POST['goto'])) {
$page = base64_decode($_POST['goto']);
} else if (isset($_GET['goto'])) {
$page = base64_decode($_GET['goto']);
}
if($_POST['email']=="")
{
if($_POST['email2']!="")
{
$emailnew = $_POST['email2'];
}
}
$pass=$_POST['pass'];
if($_POST['pass']=="")
{
if($_POST['pass2']!="")
{
$pass = $_POST['pass2'];
}
}
$remember = $_POST['rememberme'];
if($regemail !="")
{
$emailnew = $regemail;
}
if($regpass !="")
{
$pass = $regpass;
}
$query="select * from registration where email='$emailnew' and pass_word='$pass'";
$result=mysql_query($query);
$total = mysql_num_rows($result);
if($total>0)
{
echo "here";
$row=mysql_fetch_array($result);
if($row['customer_status']=='0')
{
/*if($_REQUEST["productid"]!="")
{
$_SESSION['login'] = true;
$_SESSION['emailaddress'] = $row["email"];
$_SESSION['cid'] = $row["id"];
if ($remember == "checked") { //Remember user
setcookie(ini_get("session.name"),session_id(),time()+(84600*30*12));
}
header("location: item-details.php?prid=".$_REQUEST["productid"]);
exit;
}*/
$_SESSION['login'] = true;
$_SESSION['emailaddress'] = $row["email"];
$_SESSION['cid'] = $row["id"];
if ($remember == "checked") { //Remember user
//setcookie(ini_get("session.name"),session_id(),time()+(84600*30*12));
$cookie_time = (3600 * 24 * 30); // 30 days
$cookie_name = 'siteAuth';
$password_hash = md5($pass); // will result in a 32 characters hash
setcookie ($cookie_name, 'usr='.$emailnew.'&hash='.$password_hash, time() + $cookie_time);
}
if($_POST['redirect']!="")
{
header("location:".base64_decode($_POST['redirect']));
exit;
}
elseif($page!="")
{
header("Location:$page");
exit;
}
elseif($regemail!="")
{
header("Location: register-success.php?message=1");
exit;
}
else
{
header("Location: myaccount.php");
exit;
}
}
else
{
if($_REQUEST["page"]!="")
{
header("Location: login.php?err=3");
exit;
}
else
{
header("Location: index.php?err=4");
exit;
}
}
}
else
{
if($_REQUEST["page"]!="")
{
header("Location: login.php?err=2");
}
else
{
header("Location: index.php?err=1");
}
}
?>
That "headers already sent" error is being given because you have to set cookies and stuff before any output at all.
I think that will be solved when I get it working because it won't have any output, it's just for testing purposes?
This has got me completely baffled....
Re: Ridiculous, easy problem.
Posted: Thu Jul 08, 2010 3:29 am
by Steji
Ok, so I know there is nothing wrong with the form because if I change form action to testscript.php which contains the first few lines of password.php
Code: Select all
<?php
include("connection.inc.php");
$emailnew=$_POST['email'];
print_r($_POST);
if(isset($_POST['loginbutton'])) {
echo "submit works";
}
else {
echo "login is not working";
}
echo $_POST['email'];
?>
Then everything is fine and I get this output:
Code: Select all
Array ( [email] => test.test@test.com [pass] => password[loginbutton] => Login [redirect] => ) submit works test.test@test.com
So it has to be something to do with password.php
Re: Ridiculous, easy problem.
Posted: Thu Jul 08, 2010 3:36 am
by Steji
It works now. All I had to do is change the name from password.php to something else? Why could that be?