Jump to content

Archived

This topic is now archived and is closed to further replies.

cscrofani

How to Enter Data Into Database from Webpage?

Recommended Posts

Hi Everyone,

I bought a 'turnkey' shopping cart solution from FMWebschool.com, and they left me high and dry to calculate shipping costs on my own. I was able to create a great calculation which my back end database takes care of just fine, but in order for the calculation to work, the user needs to submit their zip code through the web page first.

I'd like it to work like this: Someone clicks on the 'View Cart' button > The view_cart.php page checks to see if a ZipCode is entered in the database; if not, it will redirect you to zipcode.php > Once a ZipCode is entered, you are returned to the view_cart.php page, and all shipping costs have been calculated correctly. You can see the live site here: [a href=\"http://data.honoluluacademy.org\" target=\"_blank\"]http://data.honoluluacademy.org[/a]

I know almost nothing about php, so I'm not sure how to let the user get their zip code info into my database. Basically what I have is a view_cart.php page, with a script that I created and inserted towards the top of the page:
[code]//Inserted Script by Chris
if (empty($ZipCode))
{
    header ("Location: http://data.honoluluacademy.org/zipcode.php");
    exit;
}
//End of Chris Script[/code]

I don't think the script is ACTUALLY checking the ZipCode field in my database though. ZipCode is a field that I added to the database after I purchased the system, so I'll probably need to add a reference to it somewhere else in the php code that was provided to me.

[b]So, I've got two questions:[/b]
[i]1) How can I get this script to actually look inside the ZipCode field to check if there is one entered? What kind of references must I add to the existing code?
2) Once the script is actually working, what code must I include in my zipcode.php page to allow entry into this field? How can I get the page to redirect back to view_cart.php once the data is submitted?[/i]

I am including the ENTIRE code from both pages below, just in case you need to see it to get a better idea of what I'm talking about. I really hope you guys can give me some advice on this. Much thanks in advance!

Chris















view_cart.php:
[code]<?  
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('omit','omit');
$styleResult=$style->FMFindAll();
foreach($styleResult['data']as $key=>$styleData);

$cats=new FX($serverIP,$webCompanionPort);
$cats->SetDBData('FXCart.fp7','Categories');
$cats->SetDBPassword('omit','omit');
$catsResult=$cats->FMFindAll();

$order=new FX($serverIP,$webCompanionPort);
$order->SetDBData('FXCart.fp7','Orders_Temp');
$order->SetDBPassword('','omit');
$order->AddDBParam('Order_No',$_SESSION['ordno']);
$orderResult=$order->FMFind();
foreach($orderResult['data']as $key=>$orderData);


//Inserted Script by Chris
if (empty($ZipCode))
{
    header ("Location: http://data.honoluluacademy.org/zipcode.php");
    exit;
}
//End of Chris Script

//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('','omit');
$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('','omit');
$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('omit','omit');
$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>The Academy Shop at the Honolulu Academy of Arts</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> </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>Your Order Number is <? echo $_SESSION['ordno']; ?> </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"><? printf('$%.2f', $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>  </td>
          <td align="right"><? printf('$%.2f',$subtotal); ?> </td>
          <td valign="middle"> </td>
        </tr>
        <tr class="arial10">
          <td colspan="3" align="right"><span class="arial10B">Tax</span>  </td>
          <td align="right"><? printf('$%.2f',$tax); ?> </td>
          <td valign="middle"> </td>
        </tr>
<tr class="arial10">
          <td colspan="3" align="right"><span class="arial10B">Shipping</span>  </td>
          <td align="right"><? printf('$%.2f',$shipping); ?> </td>
          <td valign="middle"> </td>
        </tr>
        <tr class="arial10">
          <td colspan="3" align="right"><span class="arial10B">Total</span>  </td>
          <td align="right"><? printf('$%.2f',$total); ?> </td>
          <td valign="middle"><input type="image" name="submit" src="images/update.jpg" width="82" height="17"></td>

        </tr>
      </table>      <br> 
      </form>

      <form method="post" action="http://data.honoluluacademy.org/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>
<? } ?>[/code]

And zipcode.php (What I've got so far... I'm not sure if any of the top php code is necessary, I just copied most of it from the view_cart.php page):
[code]<?  
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('omit','omit');
$styleResult=$style->FMFindAll();
foreach($styleResult['data']as $key=>$styleData);

$cats=new FX($serverIP,$webCompanionPort);
$cats->SetDBData('FXCart.fp7','Categories');
$cats->SetDBPassword('omit','omit');
$catsResult=$cats->FMFindAll();

$order=new FX($serverIP,$webCompanionPort);
$order->SetDBData('FXCart.fp7','Orders_Temp');
$order->SetDBPassword('','omit');
$order->AddDBParam('Order_No',$_SESSION['ordno']);
$orderResult=$order->FMFind();
foreach($orderResult['data']as $key=>$orderData);

$items=new FX($serverIP,$webCompanionPort);
$items->SetDBData('FXCart.fp7','LineItems');
$items->SetDBPassword('','omit');
$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('omit','omit');
$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>The Academy Shop at the Honolulu Academy of Arts</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> </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>Your Order Number is <? echo $_SESSION['ordno']; ?> </p>
<form method="post" action="zipcode.php">
<input type="hidden" name="type" value="updatecart">

      <table width="96%" border="1" cellpadding="1" cellspacing="0" bordercolor="<? echo $styleData['cart_border'][0]; ?>">
  
        <tr class="arial10">
          <td width="50%" align="right"><p>Please Enter Your Zip Code to <br>
            Calculate Shipping Charges:<br>
                <input type='text' name='ZipCode'/>
            </p>
            </td>
          <td width="50%" valign="middle"><input type="image" name="submit" src="images/update.jpg" width="82" height="17"></td>
        </tr>
      </table>      
      <br> 
<table width="400" border="0" cellspacing="0" cellpadding="1">
  
  <tr>
    <td align="right"><div align="center"></div></td>
    </tr>
</table>
</form></td>
  </tr>
</table>
</p>
</body>
</html>
<? } ?>[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.