fmwebschool.com
Top Experts [learn more]Top 4-10
webko

9743 K
bandmandq

2458 K
Genx

1525 K
4. tcmeyers
5. kbata
6. Martie
7. Hammerton
8. rrenfrow
9. bneeman
10. plegler
Welcome, Guest. Please login or register.
June 18, 2013, 05:40:08 PM

Login with username, password and session length
Search:     Advanced search
Welcome to the FileMaker Web Masters Exchange.  If you have any questions about how to use this forum, please watch the getting started movie at:
http://www.fmwebschool.com/movies/forum1/forum1.html
27507 Posts in 6073 Topics by 1524 Members
Latest Member: fmwebster
* Home Help Search Calendar Login Register
+  fmwebschool.com
|-+  PHP Web Publishing Technologies
| |-+  FileMaker PHP, FX.php custom web publishing
| | |-+  Checking form value entry is not greater than quantity in database
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] Print
Author Topic: Checking form value entry is not greater than quantity in database  (Read 586 times)
alan betts
FMTouch Enterprise
Newbie
*
Offline Offline

Posts: 4


« on: August 09, 2012, 05:54:16 AM »

I have what seems like a simple problem - but am not finding it easy to solve.

I have a stock list of consumable items that can be either, transferred, sold, stolen or any number of other scenarios.

I have a form that the quantity that has been sold, stolen etc which the users enters into. I also have a quantity of stock stored in the database.

Is there a simple piece of code that can check one value against another on the response page and then redirect back to the form page and [IMPORTANT] arrive at the correct record.
I can get the response page to check and die with a message - this works fine. What I can't seem to do is return the Record ID back to the form page with a variable attached using die, as it doesn't execute any code - and as soon as I put in a variable to be passed back to the page the response page freezes. (White screen)

My latest piece of code is thus:
<?php
if( $_REQUEST['Quantity_Entered'] > $_REQUEST['Database_Quantity']
   ){
$message = 'The amount Sold exceeds the amount in stock';
fmsredirect ('form.php'.'?Record_ID='.$_REQUEST['Record_ID']);
 }
?>

This code has had various permutations, using location and die and is inserted at the first line of the response page - all the requests are passed as fields from the form.php.

Seems simple to do, anyone out there had a similar problem?

Thanks for any help
Logged
webko
Global Moderator
Hero Member
*****
Offline Offline

Posts: 2060
Kudos: 9743



WWW
Applications:
« Reply #1 on: August 09, 2012, 04:04:41 PM »

Two approaches - personally, I'd make it so they *can't* enter anything more than what's in stock, probably using a drop down field for the Quantity. So, on load the form checks how many there are in stock etc, then you could use something like:

Code:
<?php
//Pseudo code, this probably won't work as is
$quantity $find_set('Quantity');
$dropdown "";
for (
$i 1$i <= $quantity$i++) {
      
$dropdown .= "<option value=\"".$i."\">".$i."</option>";
}
?>

<select name="quantity">
   <?php echo $dropdown?>
</select>

If this isn';t really applicable, then you can check on submission - the way you outline should work, except you can't just transfer variables between pages. And if the $REQUEST['Database_Quantity'] isn't set from the form in the first place, then it won't work either. And I wouldn't use the FMS redirect, just a normal location header

Code:
<?php
session_start
//Required to have a session variable that can transfer between pages
if( $_REQUEST['Quantity_Entered'] > $_REQUEST['Database_Quantity']
   ){
$_SESSION['message'] = 'The amount Sold exceeds the amount in stock';
header("Location: form.php'.'?Record_ID='.$_REQUEST['Record_ID']"); 
//This assumes that the form page uses a Record_ID for a search on load, *and* that the form has passed that value to the handling page
 
}
Logged

tim.webko_at_gmail.com
alan betts
FMTouch Enterprise
Newbie
*
Offline Offline

Posts: 4


« Reply #2 on: August 14, 2012, 10:23:03 AM »

Hi Webko

Thanks for reply, used your second way ie the response page method and it seems to work fine - apart from the fact that I can't seem to show the message in the original form page.

my message code on the form page is

if(isset($message)){
        echo $message;
     }
... written as such because I wasn't originally using a session variable to pass the message. So I need to know how to show the message in the original form when sent back to it as a session variable.

Thanks for your assistance - this is really helpful with a number of other similar issues.

...and as a PS - would this technique work to show errors where you want to take the user back to their original page with a message rather than using the generic "error.php" response.
Logged
webko
Global Moderator
Hero Member
*****
Offline Offline

Posts: 2060
Kudos: 9743



WWW
Applications:
« Reply #3 on: August 14, 2012, 04:02:46 PM »

If you want to use session variables, every page must start like:

Code:
<?php
session_start
;
...
?>


then you can call any set variable like:
[code]
<?php
echo $_SESSION['message'];

Of course, the first time that page is loaded, that variable will not exist (it will only exist after the handler page has been used), so you should wrap that into a check to see if it's there:
Code:
if (isset($_SESSION['message'])) { echo $_SESSION['message']; }

And of course this will work for any similar situation - I use this sort of thing *a lot* although I also use Spry to do JavaScript validation on the fly, and AJAX to check database values on the fly for validation...[/code]
Logged

tim.webko_at_gmail.com
alan betts
FMTouch Enterprise
Newbie
*
Offline Offline

Posts: 4


« Reply #4 on: August 15, 2012, 01:45:54 AM »

Thanks so much for your reply

In one fell swoop you have explained something I was having problems understanding. ie Session variables.

If I am right in my understanding - once you have set a session variable in any page you can call that variable by simply opening a session on any other page.

I was led to understand that session variables are a bit $$variables in Filemaker - which stay set until the user logs out or Quits the application. So once a session variable is set then it "hangs around" in the background until it is called for by any page that uses start session.

One last clarification - cos this is so useful - can I set a session variable (eg Contact_ID) on one page, go to another page and set another session variable (eg Form_ID) then on the third or fourth or even the nth page, then call both those variables set on the first two pages simply by opening a session on the relevant page.

... and to get rid of the session variables? should I do a destroy session on the users log in page or a menu page so the process starts all over agin

Thanks again for your help Webko - if I can get my head around sessions properly then it will open up so many possibilities that I have been struggling with.
Logged
Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!