Current location: Hot Scripts Forums » Programming Languages » PHP » Create Multiple Varibles Based On Database


Create Multiple Varibles Based On Database

Reply
  #1 (permalink)  
Old 11-20-04, 12:14 PM
cebuy cebuy is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Create Multiple Varibles Based On Database

I am trying to set up an order page for website. I just want one page that the quantity and options are entered and then a resulting page is echoed that the customer can then print and mail in the order. My question is this. I have a database and in my code, I really do not want to hard code all the variables into the code. I want them generated based on the results from a column in the mysql database. My table for example:

id|product|description|price|o1|o1a|o2|o2a (o1 stands for option 1)
jug|asian jug|great widget!|2.50|color|red,blue,green|size|large,mediu m,small
jar|fruit jar|grest christmas gift!|100.00|size|large,small|||
saltshaker|mrs. saltshaker|great christmas gift!|10.00|size|large,small|||

I took some code from a tutorial and trying to adapt it to my needs, but I am seeing very fast that I am having to hard code variables in and if the database changes, I will have to recode everytime. I need some advice on how to do this. I think it has something to do with variable variables, but I am new to coding. Any help would be appreciated. I have a form and the form processing code below that I have done so far.

PHP Code:

 <h2>Order Form</h2>


<
form action="processingorder.php" method="post" target="frame2">
<
table border=0 width="347">
<
tr bgcolor=#cccccc>
  
<td width=150>Item</td>
  <
td width=40>Quantity</td>
  <
td width=143>Color</td>
</
tr>
<
tr>
  <
td width="150">Jug</td>
  <
td align=center width="40"><input type="text" name="jugqty" size=3 maxlength=3>&nbsp; </td>
  
  <
td align=center width="143"><select size="1" name="jugcolor">
   <
option value="">color</option>
   <
option>red</option>
  <
option>blue</option>
  <
option>green</option>
  </
select></td>
  
</
tr>
<
tr>
  <
td width="150">Jar</td>
  <
td align=center width="40"><input type="text" name="jarqty" size=3 maxlength=3></td>
  <
td align=center width="143">&nbsp;</td>
</
tr>
<
tr>
  <
td width="150">Salt shaker</td>
  <
td align=center width="40"><input type="text" name="saltshakerqty" size=3 maxlength=3></td>
  <
td align=center width="143">&nbsp;</td>
</
tr>
<
tr>
  <
td colspan=3 align=center width="341"><input type=submit value="Submit Order"></td>
</
tr>
</
table>
</
form

and here is the form processing code I have done so far at processingorder.php....

PHP Code:

<?

echo "<P>Order Processed.";
echo 
date("H:i, jS F");
echo 
"<br>";
if (!
$jugqty==""){echo $jugqty.' jugs'
                  if (!
$jugcolor==""){echo '--- Color '.$jugcolor.'<BR>';} else {echo '<br>';}
} else {echo 
'';}

if (!
$jarqty==""){echo $jugqty.' jars'
       if (!
$jarcolor==""){echo '--- Color '.$jarcolor.'<BR>';} else {echo '<br>';}
} else {echo 
'';}

if (!
$saltshakerqty=="")
{echo 
$saltshakerqty.' jugs'
            if (!
$saltshakercolor==""){echo '--- Color '.$saltshakercolor.'<BR>';}  else {echo '<br>';}
} else {echo 
'';}


$totalqty 0;
$totalamount 0.00;

define("jugprice"100);
define("jarprice"10);
define("saltshakerprice"4);


$totalqty $jugqty $jarqty $saltshakerqty;
$totalamount $jugqty jugprice 
                        
$jarqty jarprice
                        
$saltshakerqty saltshakerprice;
$totalamount number_format($totalamount2);
echo 
"<BR>\n";
echo 
"Items ordered:                 ".$totalqty."<br>\n";
echo 
"Subtotal:                         ".$totalamount."<BR>\n";
$taxrate=0.10;    // local sales tax is 10% here
$tax $taxrate;

$totalamount2 $totalamount $tax;
$taxsub $totalamount $taxrate;
$taxsub number_format($taxsub2);
echo 
'Taxes: $'.$taxsub.'<br>';
$totalamount2 number_format($totalamount22);
echo 
"total Including Tax: $".$totalamount2."<BR>\n";
?>
See? Instead of hard coding $jugprice for jug or $jarprice, I want these variables generated on the fly from the database. Any ideas? example is here http://www.somethingsouthernpottery.com/orderform.html of what I am building.

PS: I do know that I do not have any sql statements yet linking to my database. I just wanted some advice first.

Last edited by cebuy; 11-20-04 at 12:27 PM.
Reply With Quote
  #2 (permalink)  
Old 11-23-04, 04:20 AM
James Talbot James Talbot is offline
Newbie Coder
 
Join Date: Jul 2004
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Im not sure if i understand what you mean but what i got from it is that you dont want to insert any values into the database until the end? So the user see's the completed form before all values are inserted into the database? In that case on the page after processingorder.php you just need to echo out the form variables.

PHP Code:



$_POST
['formvariable']; 
Then get them to verfiry the information and then use mail(); or do whatever you want to do with the form variables. No need for a database if you dont need to store anything.

I hope thats what you were asking. Just say if you need any more help.
Reply With Quote
  #3 (permalink)  
Old 11-25-04, 11:15 PM
cebuy cebuy is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
ok thanks.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Create Database : Not working Romeo PHP 4 10-27-04 08:07 PM
Uploading multiple images and save to database peterpeter ASP 0 09-07-04 01:00 AM
Declared Functions skipper23 PHP 4 12-17-03 10:06 AM
index page not showing up skipper23 PHP 3 12-15-03 01:10 PM


All times are GMT -5. The time now is 05:15 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.