PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Thu Apr 08, 2004 2:58 pm
The session licenseprice is always returned blank when echod
Code: Select all
<?php
//getting the database information
while ( $row = mysql_fetch_array($result)) {
$lifetime = $row[0];
$oneyear = $row[1];
$AB100 = $row[2];
$AB150 = $row[3];
$copywright = $row[4];
}
//debugging
echo $lifetime."<br>";
echo $oneyear."<br>";
echo $AB100."<br>";
echo $AB150."<br>";
echo $copywright."<br>";
echo $_SESSION['timelicense'];
//if no optional copywright is false
if (empty($optional)){ $copywright="0"; }
if ($_SESSION['timelicense'] == 'Life Time License')
{
$_SESSION['licenseprice'] = $lifetime;
}
elseif ($_SESSION['timelicense'] == 'One Year License')
{
$_SESSION['licenseprice'] = $oneyear;
}
?>
This is what I get from the debugging
50
20
20
40
25
Life Time Licence
This is so weird... or am I just being stupid?
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Thu Apr 08, 2004 3:08 pm
And you have session_start() in there ok?
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Thu Apr 08, 2004 3:09 pm
Yep thats just a part of my code..
line1: <? session_start(); ?>
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Thu Apr 08, 2004 3:11 pm
Hmm..maybe some more debugging..
if ($_SESSION['timelicense'] == 'Life Time License')
{
echo 'SETTING SESSION TO '.$lifetime.'<br />';
$_SESSION['licenseprice'] = $lifetime;
}
See if you see that echo ok, and where are you checking the session var? Maybe do a var_dump($_SESSION); to see what's in there?
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Thu Apr 08, 2004 3:15 pm
The echo does not show up.. I already tried that..
this is the result of the var dump.. which shows timelicense to be Life Time License I believe..
array(5) { ["status"]=> &int(0) ["timelicense"]=> &string(17) "Life Time Licence" ["hosting"]=> &string(4) "None" ["optional"]=> &NULL ["total"]=> &int(0) } Life Time Licence
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Thu Apr 08, 2004 3:17 pm
Hmm..might be a possible newline in there. Is timelicense coming from a file by any chance?
Might want to try
if (trim($_SESSION['timelicense']) == 'Life Time License')
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Thu Apr 08, 2004 3:19 pm
No the session is created in the same file, after a form is submitted.
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Thu Apr 08, 2004 3:25 pm
["timelicense"]=> &string(17) in your var_dump looks weird, the & shouldn't be there.
Must be related to register_globals and/or session_register, so are globals On or Off and do you use session_register() anywhere?
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Thu Apr 08, 2004 3:34 pm
globals are on.. and session_register is not used anywhere
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Thu Apr 08, 2004 3:45 pm
Ah, that's where the & comes from then. Still not sure why it's not working though, have you tried with register_globals Off, just to see if that's the problem or not?
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Thu Apr 08, 2004 3:46 pm
I don't have access to the php.ini file :S
I don't know I'm really boggled.
I would appreciate greatly if you could come up with something
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Thu Apr 08, 2004 3:49 pm
1 more thing I just realized..
I know have a seperate file that is included in later in the script..
I have this line
if ($_SESSION['timelicense']=="Life Time Licence"){
and it runs the code fine........
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Thu Apr 08, 2004 3:54 pm
Well the only difference between if ($_SESSION['timelicense']=="Life Time Licence") and the 'problem' line is the use of double vs single quotes, but that can't be the problem.
Might have to post the exact (full) code, maybe there's something that you didn't paste above that's causing it *shrug*
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Thu Apr 08, 2004 3:56 pm
Code: Select all
<?php
<? session_start(); ?>
<link href="inc/css.css" rel="stylesheet" type="text/css">
<?
include("inc/connect.php");
include("inc/paypal.php");
//assigning empty variables
$missing = array();
$error=0;
//setting variables for which page should be loaded
if (isset($personal)){
$_SESSION['status']=2;
}else{
$_SESSION['status']=1;
}
//error checking
if ($_SESSION['status']==1 || $_SESSION['status']==2){ #1
$missing = array();
if ($submit == 'Continue'){ #2
if(!empty($_POST)) { #3
if ($status==1){ #4
$required = array('hosting','timelicense'); } ##1
elseif ($status==2){ #5
$required = array('firstname','lastname','password','email','contact'); } ##2
foreach($required as $req){ #6
if(empty($_POST[$req])){ #7
$missing[] = $req;
$error += 1;
}else{ #8 ##3
$_SESSION['status']=0;
} } } } } ##4 ##5 ##6 ##7 ##8
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)) {
$lifetime = $row[0];
$oneyear = $row[1];
$AB100 = $row[2];
$AB150 = $row[3];
$copywright = $row[4];
}
echo $lifetime."<br>";
echo $oneyear."<br>";
echo $AB100."<br>";
echo $AB150."<br>";
echo $copywright."<br>";
echo $timelicense;
var_dump($_SESSION);
echo $_SESSION['timelicense'];
if ($_SESSION['timelicense'] == 'Life Time License')
{
$_SESSION['licenseprice'] = $lifetime;
}
elseif ($_SESSION['timelicense'] == 'One Year License')
{
$_SESSION['licenseprice'] = $oneyear;
}
//if ($timelicense=="Life Time License"){ $licenseprice=$lifetimeL; }else{ $licenseprice=$oneyearL; }
//if ($hosting=="Forum hosting package AB100"){ $hostingprice=$AB100; }elseif ($hosting=="Forum hosting package AB150"){ $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"> - <? echo $_SESSION['timelicense']; echo " $".$_SESSION['licenseprice']; ?> </td> </tr>
<tr> <td bordercolor="#EEEEEE" bgcolor="#EEEEEE"> </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"> - <? echo $_SESSION['hosting']; echo " $".$hostingprice; ?> </td> </tr>
<? } if (!empty($optional)){ ?>
<tr> <td bordercolor="#EEEEEE" bgcolor="#EEEEEE"> - <? 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> </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.<br>';
$errormsg=1;
}
if ($password != $password2){
$errormessage .= 'Your passwords do not match, please go back and enter identical passwords.<br>';
$errormsg=1;
}
if (strlen($password) < 6 && (isset($password))){
$errormessage .='Your password is too short, please enter a password of 6 or more characters.<br>';
$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> </td>
<td> </td>
<td> </td>
</tr>
<tr bordercolor="EEEEEE">
<td> </td>
<td class="subtitle2">LICENSE</td>
<td> </td>
</tr>
<tr bordercolor="EEEEEE">
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr bordercolor="EEEEEE">
<td> </td>
<td>Type:</td>
<td><? echo $_SESSION['timelicense']; ?></td>
</tr>
<tr bordercolor="EEEEEE">
<td> </td>
<td>Hosting:</td>
<td><? echo $_SESSION['hosting']; ?></td>
</tr>
<tr bordercolor="EEEEEE">
<td> </td>
<td>Optional:</td>
<td><? echo $_SESSION['optional']; ?></td>
</tr>
<tr bordercolor="EEEEEE">
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr bordercolor="EEEEEE">
<td> </td>
<td>Total:</td>
<td>$<? echo $_SESSION['total']; ?> (USD)</td>
</tr>
<tr bordercolor="EEEEEE">
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr bordercolor="EEEEEE">
<td> </td>
<td colspan="2" class="subtitle2">PERSONAL</td>
</tr>
<tr bordercolor="EEEEEE">
<td width="3%"> </td>
<td width="14%"> </td>
<td width="83%"> </td>
</tr>
<tr bordercolor="EEEEEE">
<td> </td>
<td>Firstname: </td>
<td><? echo $_SESSION['firstname']; ?></td>
</tr>
<tr bordercolor="EEEEEE">
<td> </td>
<td>Lastname:</td>
<td><? echo $_SESSION['lastname']; ?></td>
</tr>
<tr bordercolor="EEEEEE">
<td> </td>
<td>Contact #:</td>
<td><? echo $_SESSION['contact']; ?></td>
</tr>
<tr bordercolor="EEEEEE">
<td> </td>
<td>Email:</td>
<td><? echo $_SESSION['email']; ?></td>
</tr>
<tr bordercolor="EEEEEE">
<td height="20"> </td>
<td> </td>
<td> </td>
</tr>
</table>
<div align="center"><br>
<? if (!isset($sent)){
echo "<a href="?confirmed=1&personal=2&error=0&sent=1">click here to confirm this information</a><br>\n";
}
?>
<br>
<?
if ($confirmed==1){
$sql = "INSERT INTO user SET license='$license', hosting='$hosting', optional='optional', firstname='$firstname',lastname='$lastname',password='$password',email='$email',contact='$contact',comments='$comments'";
if (isset($sent)){
echo "<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but01.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
<input type="hidden" name="encrypted" value="$paypal">
</form>";
}
if (@mysql_query($sql)) {
echo("<table width="50%" border="1" align="center" class="text" cellpadding="0" cellspacing="0" bordercolor="#000000" bgcolor="#EEEEEE">
<tr>
<td bordercolor="#EEEEEE">Thanks for your order , a sales assistant will process
the application . Please click the '<b>BUY NOW</b>' button to make your payment. If you
choose not to pay now you have 48 hours to process the
the payment before your order becomes void. An email will be sent shortly
providing you a link to the payment section if you choose not to pay at
this moment. <br><br>Thank you.</td>
</tr>
</table>");
} else {
echo ("Error adding your request, please try again later. " . mysql_error());
} }
}
}
}
?>
</div>
?>
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Thu Apr 08, 2004 4:09 pm
Hmm..it's defineltely down to register_globals being On, as with them on $_SESSION['timelicense'] creates a var called $timelicense in the global scope, ie $timelicense IS $_SESSION['timelicense'], so you change one and the 'other' changes automatically, this doesn't happen with globals Off.
How this is affecting you code exactly i'm not sure of, it's on the tip of my tongue but my brain has gone all spongey at the moment, i'll keep looking though if no one else spots it