Hi Everyone,

I was hoping to get a little help structuring a script that I'm trying to devise. Probably easy as cake for you guys -

I'd like an if statement that basically says: If there is no ZipCode in the current record in the database, then go to the ZipCode entry page, otherwise keep loading the current document.

Any help or ideas would be greatly appreciated.

Thanks,
Chris

    Can we see you existing code for loading the current page? Much easier if we know how your going about things.

      i got 2 for you...they are simple and stupid...need some cleaning up but here

      <?php
      
      if( $zipcode = NULL )
      {
          header( "form.php");
      }
      else
      {
          header( "complete.php");
      }
      
      ?>
      
      <?php
      
      if( $zipcode = NULL )
      {
          echo "*missing required input<br>
          <form>
          Name: <input type=\"input\" name=\"name\" value=\"$name\"><br>
          *Zipcode: <input type=\"input\" name=\"$zipcode\"><br>
          <input type=\"submit\" value=\"Submit\">";
      }
      
      ?>

      the first one is pretty dumb...but the 2nd is a bit better. If you have a bunch of inputs for a form the best thing to do would probalby make a class that would evaulate the inputs if they are either full or empty. If any "required" field is empty...then don't process it...So for the 2nd example...it would be if ( $name != NULL && $zipcode != NULL )
      then process...
      otherwise
      reload form with note on what still needs to be input (which is what i wrote out)

        Hey Guys, sorry for the vague info earlier, I was in too much of a rush to post. I haven't begun to make the if statement yet, but I was going to put another php section for it right before the html begins.

        I didn't create any of this code, it came with the package we bought. Here's the entire page, view_cart.php:

        <?  
        session_start(); include_once('FX/server_data.php'); include_once('FX/FX.php'); include_once('FX/FMErrors.php'); if(empty($_SESSION['ordno'])){ include_once('index.php'); }else{ $style=new FX($serverIP,$webCompanionPort); $style->SetDBData('FXCart.fp7','Web_Setup'); $style->SetDBPassword('blah','blah'); $styleResult=$style->FMFindAll(); foreach($styleResult['data']as $key=>$styleData); $cats=new FX($serverIP,$webCompanionPort); $cats->SetDBData('FXCart.fp7','Categories'); $cats->SetDBPassword('blah','blah'); $catsResult=$cats->FMFindAll(); $order=new FX($serverIP,$webCompanionPort); $order->SetDBData('FXCart.fp7','Orders_Temp'); $order->SetDBPassword('blah','blah'); $order->AddDBParam('Order_No',$_SESSION['ordno']); $orderResult=$order->FMFind(); foreach($orderResult['data']as $key=>$orderData); //update shopping cart begin if(isset($_POST['type'])){ if($_POST['type']=='updatecart'){ $reccom=$_POST['reccom']; for($i=0; $i<count($reccom); $i++){ $qty[$i]=$_POST['qty'.$i]; $remove[$i]=$_POST['remove'.$i]; $update=new FX($serverIP,$webCompanionPort); $update->SetDBData('FXCart.fp7','LineItems'); $update->SetDBPassword('blah','blah'); $update->AddDBParam('-recid',$reccom[$i]); $update->AddDBParam('qty',$qty[$i]); if($remove[$i]=='Yes'){ $updateResult=$update->FMDelete(); }else{ $updateResult=$update->FMEdit(); } } } } //update shopping cart end $items=new FX($serverIP,$webCompanionPort); $items->SetDBData('FXCart.fp7','LineItems'); $items->SetDBPassword('blah','blah'); $items->AddDBParam('Order_No',$_SESSION['ordno']); $itemsResult=$items->FMFind(); if(isset($_SESSION['ordno'])){ $totals=new FX($serverIP,$webCompanionPort); $totals->SetDBData('FXCart.fp7','Orders_Temp'); $totals->SetDBPassword('blah','blah'); $totals->AddDBParam('Order_No',$_SESSION['ordno']); $totalsResult=$totals->FMFind(); foreach($totalsResult['data']as $key=>$totalsData); $items=$totalsData['Items'][0]; $subtotal=$totalsData['Order_Subtotal'][0]; $tax=$totalsData['Tax'][0]; $total=$totalsData['Order_Total'][0]; $shipping=$totalsData['Shipping'][0]; }else{ $items='0'; $total='0.00'; } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>FXCart FMWebschool.com</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link href="webstyle.css" rel="stylesheet" type="text/css"> </head> <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> <? include_once('includes/header.php'); ?> <p>&nbsp;</p> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="200" valign="top"><? include_once('includes/left.php'); ?></td> <td align="center" valign="top" class="arial10B"><p>&nbsp;</p> <form method="post" action="view_cart.php"> <input type="hidden" name="type" value="updatecart"> <table width="96%" border="1" cellpadding="1" cellspacing="0" bordercolor="<? echo $styleData['cart_border'][0]; ?>"> <? $int=0;$ant=0; foreach($itemsResult['data']as $key=>$itemsData){ $int++; ?> <input type="hidden" name="reccom[]" value="<? echo $itemsData['Line_ID'][0]; ?>"> <tr class="arial10"> <td align="center"><input name="qty<? echo $ant; ?>" type="text" value="<? echo $itemsData['Qty'][0]; ?>" size="4"> </td> <td><? echo $itemsData['Products::Item_Name'][0]; ?></td> <td><? echo $itemsData['Products::Item_Description'][0]; ?></td> <td align="right">$<? echo $itemsData['Item_Total'][0]; ?></td> <td valign="middle"><input type="checkbox" name="remove<? echo $ant; ?>" value="Yes"> Remove</td> </tr> <? $ant++; } ?> <tr class="arial10"> <td colspan="3" align="right"><span class="arial10B">Subtotal</span> &nbsp;</td> <td align="right">$<? echo $subtotal; ?>&nbsp;</td> <td valign="middle">&nbsp;</td> </tr> <tr class="arial10"> <td colspan="3" align="right"><span class="arial10B">Tax</span> &nbsp;</td> <td align="right">$<? echo $tax; ?>&nbsp;</td> <td valign="middle">&nbsp;</td> </tr> <tr class="arial10"> <td colspan="3" align="right"><span class="arial10B">Shipping</span> &nbsp;</td> <td align="right">$<? echo $shipping; ?>&nbsp;</td> <td valign="middle">&nbsp;</td> </tr> <tr class="arial10"> <td colspan="3" align="right"><span class="arial10B">Total</span> &nbsp;</td> <td align="right">$<? echo $total; ?>&nbsp;</td> <td valign="middle"><input type="image" name="submit" src="images/update.jpg" width="82" height="17"></td> </tr> </table> <br>&nbsp; </form> <form method="post" action="http://data.honoluluacademy.org/php_paypal/process.php"> <input type="hidden" name="invoice" value="<? echo $_SESSION['ordno']; ?>"> <input type="hidden" name="item_name" value="Order# <? echo $_SESSION['ordno']; ?>"> <input type="hidden" name="amount" value="<? echo $orderData['Order_Total'][0]; ?>"> <table width="400" border="0" cellspacing="0" cellpadding="1"> <tr> <td align="right"><a href="index.php"><img src="images/continue_shopping.jpg" width="118" height="17" border="0"></a></td> <td><input type="image" name="submit" src="images/complete.jpg"></td> </tr> </table> </form></td> </tr> </table> </p> </body> </html> <? } ?>

        I also haven't declared my variable for zip code yet, but I'm guessing I'll have to put a line like this underneath the shipping declaration in order to get my if statement to work correctly:

        $zip=$totalsData['ZipCode'][0];

        Just for some background info... I'm a complete php newbie, but I'm fairly good with FileMaker Pro. I've gone through some basic php training files, but nothing advanced yet. My higher-ups have been hounding me about getting this thing on the road so I'm feeling the pressure. If you want to check out the live site it is at http://data.honoluluacademy.org

        The site is basically a purchased, pre-made FileMaker Pro 7 database that included php files. The database, however, had nothing included to calculate shipping costs. I made some scripts within the database to calculate the costs, but in order for them to work, a zip code must be entered. I'm trying to find the best way to get a user to insert the zip code, so I figured the best time is when they want to view their cart (view_cart.php).

        I'd like to make it so that if there is no zip code, it redirects to a zip_code.php page. Once the zip code is submitted, it takes you back to view_cart.php

          I'm guessing this bit is where you want to add the test

          if(isset($_SESSION['ordno'])){
          $totals=new FX($serverIP,$webCompanionPort);
          $totals->SetDBData('FXCart.fp7','Orders_Temp');
          $totals->SetDBPassword('blah','blah');
          $totals->AddDBParam('Order_No',$_SESSION['ordno']);
          $totalsResult=$totals->FMFind();
          foreach($totalsResult['data']as $key=>$totalsData);
          $items=$totalsData['Items'][0];
          $subtotal=$totalsData['Order_Subtotal'][0];
          $tax=$totalsData['Tax'][0];
          $total=$totalsData['Order_Total'][0];
          $shipping=$totalsData['Shipping'][0];
          }else{
          $items='0';
          $total='0.00';
          }
          
          ?>

          Just one question first: how many of these $totalsData results will there be? It looks like there's just one, in which case the loop is unnecessary (no point preparing to do something multiple times if you're only ever going to do it once). If there can be more than one, then what if some of them has ZIP codes and some don't. Anyway....

          $zip=$totalsData['ZipCode'][0];

          That can go with the similar lines. One thing that has to be considered is if the ordno session variable is not set - in that case the zip code is still going to be empty, so presumably you'd want to go to the zip code page in that case.

          So after the final } in the above-quoted code, and before the ?> that drops you back into HTML (no point sending any of that if you're just going to another page anyway...) add the test:

          if(empty($zip))
          {
              header("Location: url://for.zip.code.entry.page");
              exit;
          }

          You don't mention what $totalsData['ZipCode'][0] would contain if it doesn't contain a zip code, but empty() will work if it's something like 0 or null or an empty string. If not, then it's a matter of $zip==whatever an empty zip code looks like. Either way, if $zip doesn't have a zip code, the client will be told to go to the zip code page, and this script will then stop. If it does have a zip code, then the test fails, the script skips those two statements and goes on to display the rest of the page.

            Looks freakin' awesome weedpack, I'm gonna try this first thing when I go back to work in the morning. (Hawaii Time, so I believe I'm way behind y'all). Where is Mayfair by the way?

            I'll need to check how filemaker stores the empties, but I think your code will work.

            You're right about where I wanted to add the test, but I don't completely understand the question after that. I didn't build the original page, plus I'm a real noob, so I can't see where in the code you are referring to a loop. And I don't know how many results there will be, that whole section of code doesn't make much sense to me at all. I've been managing to get by knowing the bare minimum so far.

            If I manage to get this working tomorrow, I'm probably gonna have to worry about error checking and correction on the zip code entry page huh? Gotta prevent people from putting in bogus zips... I might have to use some variation of the filemaker script I created.

              Alright! That code you provided worked perfectly to check the zip and redirect the page. The 'empty' worked fine with filemaker pro.

              So now here comes the next step - making the zipcode.php page. Should I include all of the first php script from the view_cart page (minus the if statement, of course)?

              Assuming I keep all of that stuff, all I will need is an input box and a submit button in the body of the html (I'll worry about error checking after). Could I get some help with making the input box and submit button?

              Thanks!
              Chris

                A simple text input and a submit button like

                Enter Something<input type='text' name='forminput' /><br /.
                <input type='submit' name='submit' value='Continue'>

                I mean it seems that you asked about coding a couple of simple HTML elements.

                  Hey Houdini,

                  I tried what you said, and here's what my code looks like:

                  Please Enter Your Zip Code:<input type='text' name='zip'/></br>
                            <input type="image" name="submit" src="images/update.jpg" >

                  Looks simple enough, but I've got a few questions... The part where you say name='forminput', what am I supposed to put in here - the actual ZipCode field name from my database, or the name of my $zip variable?

                  Also, the script isn't actually redirecting to the zipcode.php page... I'm guessing this is because of the "header" command in my if statement. Is there any way to totally redirect to a page instead of using this header method? I get the following errors when using the header method:

                  Notice: Undefined index: qty0 in c:\inetpub\wwwroot\view_cart.php on line 34

                  Notice: Undefined index: remove0 in c:\inetpub\wwwroot\view_cart.php on line 35

                  Notice: Undefined index: qty1 in c:\inetpub\wwwroot\view_cart.php on line 34

                  Notice: Undefined index: remove1 in c:\inetpub\wwwroot\view_cart.php on line 35

                  Notice: Undefined index: qty2 in c:\inetpub\wwwroot\view_cart.php on line 34

                  Notice: Undefined index: remove2 in c:\inetpub\wwwroot\view_cart.php on line 35

                  Warning: Cannot modify header information - headers already sent by (output started at c:\inetpub\wwwroot\view_cart.php:34) in c:\inetpub\wwwroot\view_cart.php on line 79

                    Write a Reply...