Page 1 of 1

Few problems with my script

Posted: Tue Apr 06, 2004 2:29 pm
by John Cartwright
I have this register script for a forum license ( not quite done and optimized yet ) but this is the prototype. Throughout the script they fill out several forms, 1 at a time depending on errors etc etc.. as you can see in the script. If they choose back it is simply a javascript with history.back but when thye click back it brings them to a page cannot be found... this only recently started happening, out of nowhere, it used to work fine :S.
Thats not really php but heres my actual php problem:

*edit* WHen the page is first loaded, everything is blank except for my debugging variables.. which at load only one of them is shown..

which is $_SESSION['status']==1 ... that determines what part of the script is being loaded, to the most part. Once I reload then the script is run properly, anyone see the problem?

CODE:

Code: Select all

<? session_start(); ?>

<link href="inc/css.css" rel="stylesheet" type="text/css">

<?
include("inc/connect.php");

//assigning empty variables
$missing = array();

//setting variables for which page should be loaded
if (isset($personal)){
	$_SESSION['status']=2;
}else{
	$_SESSION['status']=1;
}
$error=0;

//error checking
if ($_SESSION['status']==1 || $_SESSION['status']==2){
$missing = array(); 
if ($submit == 'Continue'){ 
  	if(!empty($_POST)) { 
    	if ($status==1){
			$required = array('hosting','timelicense');  }
		elseif ($status==2){
			$required = array('firstname','lastname','password','email','contact');  }	
    	foreach($required as $req){ 
      		if(empty($_POST[$req])){ 
        		$missing[] = $req; 
        		$error += 1; 
      		}else{ 
        		$_SESSION['status']=0;
				
     } } } } }

if (($_SESSION['status']==1 || $error==1 || $error==2) && (!$personal)){ 

//setting variables for filled in fields

if(!empty($_POST['submit'])){ 
	if ($timelicense=="Life Time Licence"){           $timelicense1 = "checked"; }
	elseif ($timelicense=="One Year License")   {     $timelicense2 = "checked"; }
	if ($hosting=="Forum hosting package AB100"){     $hosting1 = "checked"; }
	elseif ($hosting=="Forum hosting package AB150"){ $hosting2 = "checked"; }
	if ($optional=="Copywright Removal"){             $optional1 = "checked"; }
	} 

include("form.php");

//when form is submitted and no errors

}elseif ($_SESSION['status']==0 && (!$personal)){

//assigning the sessions to variables
if (!isset($_SESSION['timelicense'])){ $_SESSION['timelicense'] = $timelicense; }
if (!isset($_SESSION['hosting'])){$_SESSION['hosting'] = $hosting; }
if (!isset($_SESSION['optional'])){$_SESSION['optional'] = $optional; }

//setting the query
   $result = @mysql_query("SELECT * FROM prices"); 
   if (!$result) { 
   echo("<p>Error performing query: ". mysql_error()); 
   exit(); 
   } 
 
//getting the database information
    while ( $row = mysql_fetch_array($result)) { 
	$lifetimeL  = $row[0]; 
	$oneyearL   = $row[1]; 
	$AB100      = $row[2]; 
	$AB150      = $row[3]; 
	$copywright = $row[4];
	}

//if no optional copywright is false
if (empty($optional)){ $copywright="0"; }

if ($timelicense=="Life Time License"){ $licenseprice=$lifetimeL; }else{ $licenseprice=$oneyearL; }
if ($hosting=="Forum hosting package AB100"){ $hostingprice=$AB100; }else{ $hostingprice=$AB150; } ## GOTTO FIX THE PRICING

?>
<div align="center" class="text">Thank you for showing an interest in AG.</div>
<br>
<? //confirming the users order ?>
<table width="50%" border="0" align="center" cellpadding="0" cellspacing="0" class="error">
  <tr> 
    <td class="steps">Step 2/3 - Confirming your License</td>
  </tr>
</table>
<table class="text" align="center" width="50%" border="1" cellpadding="0" cellspacing="0" bordercolor="#000000">
    <tr> <td bordercolor="#EEEEEE" bgcolor="#EEEEEE">Your chosen Purchase Items: </td> </tr>
    <tr> <td bordercolor="#EEEEEE" bgcolor="#EEEEEE">&nbsp; - <? echo $_SESSION['timelicense']; echo " $".$licenseprice; ?> </td> </tr>
    <tr> <td bordercolor="#EEEEEE" bgcolor="#EEEEEE">&nbsp;</td> </tr>
    <? if ($_SESSION['hosting'] != "None" || (isset($_SESSION['optional']))) { ?>
	<tr> <td bordercolor="#EEEEEE" bgcolor="#EEEEEE">Your Purchase Optional Items:</td> </tr>
	<? } if ($_SESSION['hosting'] != "None"){ ?>
    <tr> <td bordercolor="#EEEEEE" bgcolor="#EEEEEE">&nbsp; - <? echo $_SESSION['hosting']; echo " $".$hostingprice; ?> </td> </tr>
    <? } if (!empty($optional)){ ?>
	<tr> <td bordercolor="#EEEEEE" bgcolor="#EEEEEE">&nbsp; - <? echo $_SESSION['optional']; echo " $".$copywright; ?> </td> </tr> 
	<? } ?>
    <tr> <td bordercolor="#EEEEEE" bgcolor="#EEEEEE">
	<div align="right">Total: <? $total=$licenseprice+$hostingprice+$copywright; echo "$".$total; ?></div>
	</td> </tr>
    </table>
    
	<? $_SESSION['total'] = $total; ?>
	
	<br>

    <div align="center">
    
  <table width="50%" border="0" cellpadding="0" cellspacing="0">
    <tr bgcolor="#EEEEEE"> 
      <td width="50%" height="26"><input name="button" type="button" onClick="history.back()" value="Back"></td>
      <form name="register" method="post" action="register.php">
        <td>&nbsp;</td>
        <td width="50%"> <div align="right"> <input name="submit" type="submit" id="submit" value="Continue"></div></td>
        <input type="hidden" name="personal" value="2"/>
      </form>
    </tr>
  </table>
    </div>
<?

}elseif ($personal){

if (($personal == 2 && $error != 0) || $error==0){
	if ($error != 0){
		
			if ($email != $email2){
				$errormessage='Your emails do not match, please go back and enter identical emails. Make sure your emails are correct as they are required for futur uses.';
				$errormsg=1;
			}elseif ($password != $password2){
				$errormessage='Your passwords do not match, please go back and enter identical passwords.';
				$errormsg=1;
			}elseif (strlen($password) < 6 && (isset($password))){
				$errormessage='Your password is too short, please enter a password of 6 or more characters.';
				$errormsg=1;
			}

include("form.php");
}elseif ($error=="0"){ 

$_SESSION['firstname'] = $firstname;
$_SESSION['lastname']  = $lastname;
$_SESSION['contact']  = $contact;
$_SESSION['email']  = $email;
$_SESSION['password']  = $password;
$_SESSION['contact']  = $contact;
$_SESSION['comments']  = $comments;

?>



<table width="50%" border="0" align="center" cellpadding="0" cellspacing="0" class="steps">
  <tr>
    <td>Purchase Summary</td>
  </tr>
</table>
<table width="50%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#000000" bgcolor="#EEEEEE" class="text">
  <tr bordercolor="EEEEEE"> 
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr bordercolor="EEEEEE"> 
    <td>&nbsp;</td>
    <td class="subtitle2">LICENSE</td>
    <td>&nbsp;</td>
  </tr>
  <tr bordercolor="EEEEEE"> 
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr bordercolor="EEEEEE"> 
    <td>&nbsp;</td>
    <td>Type:</td>
    <td><? echo $_SESSION['timelicense']; ?></td>
  </tr>
  <tr bordercolor="EEEEEE"> 
    <td>&nbsp;</td>
    <td>Hosting:</td>
    <td><? echo $_SESSION['hosting']; ?></td>
  </tr>
  <tr bordercolor="EEEEEE"> 
    <td>&nbsp;</td>
    <td>Optional:</td>
    <td><? echo $_SESSION['optional']; ?></td>
  </tr>
  <tr bordercolor="EEEEEE"> 
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr bordercolor="EEEEEE"> 
    <td>&nbsp;</td>
    <td>Total:</td>
    <td>$<? echo $_SESSION['total']; ?> (USD)</td>
  </tr>
  <tr bordercolor="EEEEEE"> 
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr bordercolor="EEEEEE"> 
    <td>&nbsp;</td>
    <td colspan="2" class="subtitle2">PERSONAL</td>
  </tr>
  <tr bordercolor="EEEEEE"> 
    <td width="3%">&nbsp;</td>
    <td width="14%">&nbsp;</td>
    <td width="83%">&nbsp;</td>
  </tr>
  <tr bordercolor="EEEEEE"> 
    <td>&nbsp;</td>
    <td>Firstname: </td>
    <td><? echo $_SESSION['firstname']; ?></td>
  </tr>
  <tr bordercolor="EEEEEE"> 
    <td>&nbsp;</td>
    <td>Lastname:</td>
    <td><? echo $_SESSION['lastname']; ?></td>
  </tr>
  <tr bordercolor="EEEEEE"> 
    <td>&nbsp;</td>
    <td>Contact #:</td>
    <td><? echo $_SESSION['contact']; ?></td>
  </tr>
  <tr bordercolor="EEEEEE"> 
    <td>&nbsp;</td>
    <td>Email:</td>
    <td><? echo $_SESSION['email']; ?></td>
  </tr>
  <tr bordercolor="EEEEEE"> 
    <td height="20">&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>



<?
	if ($confirmed==1)
		$sql = "INSERT INTO users SET firstname='$firstname',lastname='$lastname',password='$password',email='$email',contact='$contact',comments='$comments'"; 
   
  		if (@mysql_query($sql)) { 
    		echo("Your request for a license has be submitted to our database. Check your email to confirm your information and you will be contacted withen 48 business hours."); 
  		} else { 
    	echo ("Error adding your request, please try again later. " . mysql_error()); 
  		} 
	}
}
}
echo $_SESSION['status'];
if (!$_SESSION['status']){ echo "die"; }
	

?>

Posted: Tue Apr 06, 2004 8:07 pm
by John Cartwright
up

Posted: Wed Apr 07, 2004 9:00 pm
by John Cartwright
up.. . could someoone help me? Just a refresh.. anyone know why when it is first loaded the page is blank?

Posted: Wed Apr 07, 2004 9:28 pm
by feyd
by chance, have you checked your error logs on your server?

okay.. I spotted two things that are probably wrong.
1.you are missing a starting { here:

Code: Select all

if ($confirmed==1)
2. I don't know if you intended it, but it looks like you will only display exactly 1 (the last) query result:

Code: Select all

while ( $row = mysql_fetch_array($result)) { 
   $lifetimeL  = $row[0]; 
   $oneyearL   = $row[1]; 
   $AB100      = $row[2]; 
   $AB150      = $row[3]; 
   $copywright = $row[4]; 
   }

Posted: Wed Apr 07, 2004 9:32 pm
by John Cartwright
Yea sorry when I posted the code I had that problem.. I noticed it too and fixed it a bit ago,

and yes that table only has 1 entry :P and is updated, no rows are added

Posted: Wed Apr 07, 2004 9:35 pm
by feyd
your session_start() might likely be failing if you have any text displaying before this file displayed.. that includes any whitespace too.

Posted: Wed Apr 07, 2004 9:47 pm
by John Cartwright
But look at my session_start isnt it fine how I did it?
The sessions are working tho.. :S

*edit* on the code I posted ther eis a what space but its just how it came out on the forums.. session_start is on line 1 in my script