url parameter in sql-select

Questionsurl parameter in sql-select
Mario asked 9 years ago

Hello,

how may I integrate an url-parameter for instance "123" into the select

From this code:
$g->select_command = "SELECT * FROM `t` where id = 123; ";

to a code like this:
echo
' "$g->select_command = "SELECT * from t where id =". $_GET["ref_id"]. ";"';

Or is this not not possible having a flexible id in the select command?

best regards,
Mario

3 Answers
Abu Ghufran answered 9 years ago

Ideally $_GET should work as it is. But you can try the following:

e.g.

if (!empty($_GET["ref_id"]))
{
$_SESSION["ref_id"] = $_GET["ref_id"];
}
$ref_id= $_SESSION["ref_id"];

and use `$ref_id` in your SQL.

Mario answered 9 years ago

Thank you. The standard case works.

But the referrer-id is only kept with the first click. As soon as the second click is there the message appears:

Couldn't execute query. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '…WHERE ref_id = '

This means at the second click the ref_id is empty. Is there a possibility to keep the id over the whole session, or is there a possibility to errorhandle an error like "Couldn't execute query." to a redirect?

thanx and best regards,
Mario

Abu Ghufran answered 9 years ago

Session persist till you close the browser OR you close the session via code.
If the variable is in session for first time, it should be there till session ends.

Please share your code for review.
You can Email or Use pastebin.com

Your Answer

16 + 19 =

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?