Fallback for Url-Variable for select-statement

QuestionsFallback for Url-Variable for select-statement
Mario asked 8 years ago

I use in the $g->select_command = a variable like
——-
$g->select_command = "select * from table where coupon = $coupon"
——–

This works fine, if I use the urlvariable
But sometimes the urlvariable could be lost, or the user forgets it.

I defined the url-variable "coupon" as

————-
$coupon = $_GET["coupon"];
if (!isset($coupon)) $coupon = '1234567';
————-

and in links as:

————-
<a href="<?php echo 'samplelink.php?coupon='.$_GET["coupon"].'&language=de'.'&e='.$_GET["e"].''.'&plz='.$_GET["plz"].''; ?>">my link</a>

How may I integrate the "if not set"-clause into this Link, as a fallback, if the variable should be not set? Using a session is not really an option, I like to solve it with the if statemement directly in the Link,.

Thank you for help
Mario

3 Answers
Abu Ghufran answered 8 years ago

Perhaps i dont understand it completely. But you need to replace the $_GET["coupon"] with the $coupon variable.

$coupon = $_GET["coupon"];
if (!isset($coupon)) $coupon = '1234567';

<a href="<?php echo 'samplelink.php?coupon='.$coupon.'&language=de'.'&e='.$_GET["e"].''.'&plz='.$_GET["plz"].''; ?>">my link</a>

Mario answered 8 years ago

right. The replacement of the $coupon variable works aleady, but only if an URL-Parameter site.com?coupon=12334567 is set. But if site.com hat no parameter in the URL the error occours. This is why I like to have a fallback, if someone uses no Parameter in the URL. So the standardcoupon may be fill the variable and the select-command would even work if no parameter is set.

Abu Ghufran answered 8 years ago

I guess it should work.
code should be like:

if (!isset( $_GET["coupon"]))
$coupon = '1234567';
else
$coupon = $_GET["coupon"];

Your Answer

16 + 8 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?