/    Sign up×
Community /Pin to ProfileBookmark

Session/Echo Question

We are using SESSION to pass a value to another php page, which is working great. My question is how to echo a form page depending on the value we collected from the first php page.

In the second php page:

[code=php]
<?php
session_start();
?>
[/code]

in html:

[code=php]
<?php
if($_SESSION[‘item’] = “Orange”
echo $_SESSION[‘item’];
echo “<form name=”PrePage” method = “post” action = “https://websitepayment.aspx”> <input type = “hidden” name = “LinkId” value =”xxxxxxxxx1″ /> <input type = “image” src =”//content.thewebsite/images/buynow.gif” /></form>”;
elseifif($_SESSION[‘item’] = “Grapes”
echo $_SESSION[‘item’];
echo “<form name=”PrePage” method = “post” action = “https://websitepayment.aspx”> <input type = “hidden” name = “LinkId” value =”xxxxxxxxx2″ /> <input type = “image” src =”//content.thewebsite/images/buynow.gif” /></form>”;
endif;
?>
[/code]

I can’t get the form to show up :p I have no idea what I am doing! I need the ITEM bolded and the FORM to show below the ITEM. Help!!!

I was going to make separate pages for each items, this will save me a lot of time if I can only get it to work.

TY
Lis

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@JunkMaleMar 24.2009 — elseifif

don't you mean

elseif

?


Also enclose in braces to ensure that the interpreter can deal with the if clause correctly incase if terminates at the EOL marker.

See how that goes.
Copy linkTweet thisAlerts:
@xoxLISAxoxauthorMar 24.2009 — Yes, elseif, lol


Also enclose in braces to ensure that the interpreter can deal with the if clause correctly incase if terminates at the EOL marker.

See how that goes.[/QUOTE]


I'm lost ?
Copy linkTweet thisAlerts:
@Phill_PaffordMar 24.2009 — I see a lot wrong with your code, I have made some changes below.

[code=php]
<?php
if(strtolower($_SESSION['item']) == "orange") {
echo $_SESSION['item'];
echo "<form name='PrePage' method='post' action='https://websitepayment.aspx'>
<input type='hidden' name='LinkId' value='xxxxxxxxx1' />
<input type='image' src='//content.thewebsite/images/buynow.gif' />
</form>";
} elseif (strtolower($_SESSION['item']) == "grapes") {
echo $_SESSION['item'];
echo "<form name='PrePage' method = 'post' action = 'https://websitepayment.aspx'>
<input type = 'hidden' name = 'LinkId' value ='xxxxxxxxx2' />
<input type = 'image' src ='//content.thewebsite/images/buynow.gif' />
</form>";
}
?>
[/code]


My next question to you is, "What is this value to be?" xxxxxxxxx2 or xxxxxxxxx1 who do you make this?

instead of hard coding the condition I would suggest a function to do this action. Might be easier to add new items this way.

Example:
[code=php]
function getLinkInfo($value) {

$html =<<<HTML
<form name="PrePage" method="post" action="https://websitepayment.aspx">
<input type="hidden" name="LinkId" value="$value" />
<input type="image" src="//content.thewebsite/images/buynow.gif" />
</form>
HTML;

return $html;
}

function getValueForItem($item) {
$sql = "SELECT value FROM itemValue WHERE item = " . $item . " ";

// Do MySQL query to get the results
$result = mysql_query($sql);

// Return results (Should only be one)
return $result;
}

$value = getValueForItem($_SESSION['item']);
$html = getLinkInfo($value);
echo $html;
[/code]


must create a table with the item/value info in MySQL and a connection class for MySQL, but this is just the basic example
Copy linkTweet thisAlerts:
@JunkMaleMar 24.2009 — Braces... or as some people call them curly brackets { } these define the parts of a condition set.
Copy linkTweet thisAlerts:
@xoxLISAxoxauthorApr 14.2009 — One quick question though. In our old setup, the first page collects all the data and send us the email. With these changes, it is the 3rd page that sends the email. With these changes, I am not receiving the email at all.

first page php:
[code=php]
<?php
session_start();
$emailadr = '';
$cost = '';
$_SESSION['cost'] = $cost;
$_SESSION['emailadr'] = $emailadr;
[/code]


3rd page php:
[code=php]
<?php
session_start();
$thankyou = 'thankyou.html';
$mailcopy = '[email protected]';
$mailsubj = 'Your Order';
$fullname = '';
$cr = "r"; // carriage-return character
$lf = "n"; // line-feed character
$lterm = $cr.$lf; // headers and body line terminator for email
$messages = ''; // form fields error messages

if ($_SERVER['REQUEST_METHOD'] == 'POST'):
$fullname = $_POST['fullname'];
$mailsubj .= $fullname;

if(strlen($messages)==0):
$mailheaders = 'Content-Type: text/plain;'.$lterm;
$mailheaders .= 'X-Mailer: PHP;'.$lterm;
$mailheaders .= 'X-MSMail-Priority: High;'.$lterm;
$mailheaders .= 'X-Priority: 1;'.$lterm;
$mailheaders .= 'Return-path: '.$emailadr.$lterm;
$mailheaders .= 'Sender: '.$emailadr.$lterm;
$mailheaders .= 'From: '.$emailadr.$lterm;
if (isset($mailcc)
&& !empty($mailcc)):
$mailheaders .= 'Cc: '.$mailcc.$lterm;
endif;
$mailbody = "
$_SESSION['cost']
Name: {$fullname}
Email: $_SESSION['emailadr']
".$lterm;

ini_set(sendmail_from, $mailcopy);
if (mail($mailcopy, $mailsubj, $mailbody, $mailheaders)):
ini_restore(sendmail_from);
header('Location: '.$thankyou);
exit;
endif;
ini_restore(sendmail_from);
$messages = 'Failed to send email!';
endif;
endif;

[/code]
Copy linkTweet thisAlerts:
@xoxLISAxoxauthorApr 14.2009 — Please disregard this post as I made another making it simpler. I don't know how to delete that's why.

I apologize if I did this wrong.

Thanks

Lis
×

Success!

Help @xoxLISAxox spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...