Fallback-Message if select fails

QuestionsFallback-Message if select fails
Mario asked 8 years ago

If a select, fails for instance if something is missing, I get message like

———————
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 'LIMIT 1 OFFSET 0' at line 1 – Select * from table where coupon =
———————

Is it possible to adapt the erormessage or at least load the site and echo the message on the site? Is there a szenario for this? In this case I would like to write for instance: "Please add the Parameter coupon in your url like "?coupon=123". Wha is the best szenario to have a fallback message for failing selects?

1 Answers
Abu Ghufran answered 8 years ago

Hi,

You can put this condition on page using php code:

$msg = '';
if (empty($_GET["coupon"]))
{
$msg = "Please add the Parameter coupon in your url like ?coupon=123";
$coupon = "1234567";
}
else
$coupon =intval( $_GET["coupon"]);

and in query:

->select_command = Select * from table where coupon = $coupon;

and on page, where you want to display message:

<?php
if (!empty($msg)) echo $msg;

Your Answer

3 + 5 =

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?