Page 1 of 1

collecting data from html template for php script

Posted: Tue Dec 01, 2015 6:42 pm
by sladepowers
hello, my name is slade. i'm working with a shopping cart template that allows for the option to choose the product, choose the quantity, choose the earpiece. there are only three items that we offer so it seems like a pretty straight forward script. i was hoping to avoid sessions and use a php to convert the values of the options to variables then insert them into the mysql db. here is the back of the html code:

Code: Select all

		   <form id="shoppingCart" method="POST" class="form-inline" name="basket_form" action="">
   				<div class="content">
                       <div class="navbar">
                           <div class="navbar-inner">
                               <ul class="nav custom_nav">
                                   <li class="pull-left">
                                       <div>
                                           <a href="javascript: void(0);" class="btn btn-info">
                                               <i class="icon-hand-left icon-white"></i>
                                              Continue Shopping
                                          </a>
                                      </div>
                                  </li>
                                  <li class="pull-right">
                                      <a href="checkout.html">
                                      <button class="btn btn-success continue_to_checkout" type="submit" value="Checkout" name="cont_to_checkout1">
                                          Continue To Checkout
                                      </button>   
                              </a></li>
                                  <li class="pull-right">&nbsp;&nbsp;</li>
                                  <li class="pull-right">
                                      <div>
                                          <button class="btn btn-danger remove_all" type="submit" name="remove_all1" value="remove_all" rel="tooltip" data-placement="bottom" data-original-title="Be careful! All products will be entirely removed from the basket!">
                                              <i class="icon-remove icon-white"></i>
                                              Remove All
                                          </button>
                                      </div>
                                  </li>
                              </ul>
                          </div>
                      </div>
  					<div class="basket_list clearfix">
  						<div class="tables">
  						  <table class="table table_header">
  								<thead>
  									<tr>
  										<th colspan="2" class="description">
  											Item Description
  										</th>
  										<th class="size">
  											TEMPLE
  										</th>
  										
  								  <th class="quantity">
  											Quantity
  									  </th>
  										<th class="price">
  											Price
  										</th>
  										<th class="subtotal">
  											Subtotal
                    </th>
  										<th>&nbsp;
  											
  										</th>
  									</tr>
  								</thead>
  							</table>
  							<table class="table">
  								<tbody>
  									<tr class="warning">
  										<td class="thumb" rowspan="2">
  											<a href="javascript: void(0);" title="Link to product page">
  												<img src="img/331.jpg" width="123" height="91" title="Product Image">
  											</a>
  </td>
  										<td class="description" rowspan="2">
  											<a class="item-name" href="javascript: void(0);" title="Link to product page">The Carat</a>
  											<div>
  												<div class="item-availability"><em>These Diamond Shape Spectacles Accentuate Anyone's Style and Grace</em>.</div>
  												<div class="item-sku">MDL331</div>
  											</div>
  										</td>
  										<td class="size">
                                              <select class="span2" id="prod2_size1" name="prod2_size1">
  												<option value="0">Size</option>
  												<option value="Buffalo Horn" selected>Buffalo Horn</option>
  												<option value="Gold">Gold</option>
  												<option value="Rose Gold">Rose Gold</option>
  												<option value="White Gold">White Gold</option>
  												<option value="Titanium">Titanium</option>
  												<option value="Platinum">Platinum</option>
  												<option value="Whale Bone">Whale Bone</option>
                                              </select>
  								    </td>
  										<td class="color">
  
  
  											<input type="hidden" id="prod2_color1" name="prod2_color1" value="no">
  										</td>
  								  <td class="quantity">
  											<label class="inline">Qty:</label>
                                              <input id="prod2_qty1" name="prod2_qty1" type="text" class="number" value="1" class="inline input-mini">
  									  </td>
  										<td class="price">
  											<span class="currency">$</span><span class="amount">3000.00</span>
  										</td>
  										<td class="subtotal">
  											<span class="currency">$</span><span class="amount">3000.00</span>
 										</td>
 										<td class="remove">
                                             <button class="btn btn-danger btn-mini" type="submit" name="prod2_remove1" value="remove_item" rel="tooltip" data-placement="left" data-original-title="Be careful! This item will be entirely removed from the basket!">
                                                 <i class="icon-remove icon-white"></i>
                                             </button>
 										</td>
 									</tr>
 									<tr class="warning additional_empty">
 										<td class="empty_td" colspan="8">
 											
 										</td>
 									</tr>
 							  </tbody>
 					    </table>
                        
                        
                         <table class="table">
 							  <tbody>
 									<tr class="warning">
 										<td class="thumb" rowspan="2">
 											<a href="javascript: void(0);" title="Link to product page">
 												<img src="img/332.jpg" width="123" height="91" title="Product Image">
 											</a>
 </td>
 										<td class="description" rowspan="2">
 											<a class="item-name" href="javascript: void(0);" title="Link to product page">The Minimum</a>
 											<div>
 												<div class="item-availability">
 												  <p><em>Timeless Design, </em><em>A true work of art</em>, <em>High Quality Lenses, </em><em>A Comfortable Fit</em></p>
 </div>
 												<div class="item-sku">MDL332</div>
 											</div>
 										</td>
 										<td class="size">
                                             <select class="span2" id="prod2_size1" name="prod2_size1">
 												<option value="0">Size</option>
 												<option value="Buffalo Horn" selected>Buffalo Horn</option>
 												<option value="Gold">Gold</option>
 												<option value="Rose Gold">Rose Gold</option>
 												<option value="White Gold">White Gold</option>
 												<option value="Titanium">Titanium</option>
 												<option value="Platinum">Platinum</option>
 												<option value="Whale Bone">Whale Bone</option>
                                             </select>
 										</td>
 										<td class="color"><input type="hidden" id="prod2_color1" name="prod2_color1" value="no">
 									  </td>
 								  <td class="quantity">
 											<label class="inline">Qty:</label>
                                             <input id="prod2_qty1" name="prod2_qty1" type="text" class="number" value="1" class="inline input-mini">
 									  </td>
 										<td class="price">
 											<span class="currency">$</span><span class="amount">4000.00</span>
 										</td>
 										<td class="subtotal">
 											<span class="currency">$</span><span class="amount">4000.00</span>
 										</td>
 										<td class="remove">
                                             <button class="btn btn-danger btn-mini" type="submit" name="prod2_remove1" value="remove_item" rel="tooltip" data-placement="left" data-original-title="Be careful! This item will be entirely removed from the basket!">
                                                 <i class="icon-remove icon-white"></i>
                                             </button>
 										</td>
 									</tr>
 									<tr class="warning additional_empty">
 										<td class="empty_td" colspan="8">
 											
 									  </td>
 									</tr>
 							  </tbody>
 					    </table>
                        
                        
                         <table class="table">
 								<tbody>
 									<tr class="warning">
 										<td class="thumb" rowspan="2">
 											<a href="javascript: void(0);" title="Link to product page">
 												<img src="img/333.jpg" width="123" height="91" title="Product Image">
 											</a>
     </td>
 										<td class="description" rowspan="2">
 											<a class="item-name" href="javascript: void(0);" title="Link to product page">The Maximum</a>
 											<div>
 												<div class="item-availability"><em>Rimless frames</em>, <em> Sophistication &  Elegance</em> by Design</div>
 												<div class="item-sku">MDL333</div>
 											</div>
 										</td>
 										<td class="size">
                                             <select class="span2" id="prod2_size1" name="prod2_size1">
 												<option value="0">Size</option>
 												<option value="Buffalo Horn" selected>Buffalo Horn</option>
 												<option value="Gold">Gold</option>
 												<option value="Rose Gold">Rose Gold</option>
 												<option value="White Gold">White Gold</option>
 												<option value="Titanium">Titanium</option>
 												<option value="Platinum">Platinum</option>
 												<option value="Whale Bone">Whale Bone</option>
                                             </select>
 										</td>
 										<td class="color"><input type="hidden" id="prod2_color1" name="prod2_color1" value="no">
 									  </td>
 										<td class="quantity">
 											<label class="inline">Qty:</label>
                                             <input id="prod2_qty1" name="prod2_qty1" type="text" class="number" value="1" class="inline input-mini">
 										</td>
 										<td class="price">
 											<span class="currency">$</span><span class="amount">5000.00</span>
 										</td>
 										<td class="subtotal">
 											<span class="currency">$</span><span class="amount">5000.00</span>
 										</td>
 										<td class="remove">
                                             <button class="btn btn-danger btn-mini" type="submit" name="prod2_remove1" value="remove_item" rel="tooltip" data-placement="left" data-original-title="Be careful! This item will be entirely removed from the basket!">
                                                 <i class="icon-remove icon-white"></i>
                                             </button>
 										</td>
 									</tr>
 									<tr class="warning additional_empty">
 										<td class="empty_td" colspan="8">
 											
 									  </td>
 									</tr>
 							  </tbody>
 					    </table>
                        
                                              
 
                        
                        
                         <table class="table">
 						  <tbody>
 							    <tr class="warning">
 							      <td class="thumb" rowspan="2"><a href="javascript: void(0);" title="Link to product page"> <img src="img/334.jpg" alt="" width="123" height="91" title="Product Image"> </a></td>
 							      <td class="description" rowspan="2"><a class="item-name" href="javascript: void(0);" title="Link to product page">The Drop</a>
 							        <div>
 							          <div class="item-availability"><em>These Teardrop Cut Lenses with Lightweight Rimless frames are a work of art</em></div>
 							          <div class="item-sku">MDL334</div>
 						            </div></td>
 							      <td class="size"><select class="span2" id="prod2_size3" name="prod2_size3">
 							        <option value="0">Size</option>
 							        <option value="Buffalo Horn" selected>Buffalo Horn</option>
 							        <option value="Gold">Gold</option>
 							        <option value="Rose Gold">Rose Gold</option>
 							        <option value="White Gold">White Gold</option>
 							        <option value="Titanium">Titanium</option>
 							        <option value="Platinum">Platinum</option>
 							        <option value="Whale Bone">Whale Bone</option>
 							        </select></td>
 							      <td class="color"><input type="hidden" id="prod2_color3" name="prod2_color3" value="no"></td>
 							      <td class="quantity"><label class="inline">Qty:</label>
 							        <input id="prod2_qty1" name="prod2_qty1" type="text" class="number" value="1" class="inline input-mini"></td>
 							      <td class="price"><span class="currency">$</span><span class="amount">6000.00</span></td>
 							      <td class="subtotal"><span class="currency">$</span><span class="amount">6000.00</span></td>
 							      <td class="remove"><button class="btn btn-danger btn-mini" type="submit" name="prod2_remove1" value="remove_item" rel="tooltip" data-placement="left" data-original-title="Be careful! This item will be entirely removed from the basket!"> <i class="icon-remove icon-white"></i> </button></td>
 						        </tr>
 							    <tr class="warning additional_empty">
 							      <td class="empty_td" colspan="8"></td>
 						        </tr>
 					      </tbody>
 						  </table>
 						</div>
 						<div class="empty_basket">
 							Your Shopping Cart is empty!
 						</div>
 						<div class="order_blocks clearfix">
 							<div class="row">
 								<div class="span6 shipping_block clearfix">
 									<div class="delivery_block pull-left">
 										<h4>Delivery Method</h4>
 										<label class="radio">
 											<input type="radio" name="deliveryOption" id="deliveryOption1" value="0" checked>
 											STANDARD - 4-5 working days: <span class="currency">$</span>0.00
 										</label>
 										<label class="radio">
 											<input type="radio" name="deliveryOption" id="deliveryOption2" value="9.95">
 											EXPRESS DELIVERY - 48h: <span class="currency">$</span>9.95
 										</label>
 									</div>
 									<div class="promotional_block pull-right">
 										<h4>Promotional Code</h4>
 										<div class="input-append">
 											<input class="span2" id="appendedInputButton" name="promotional" value="" size="16" type="text" >
 											<button class="btn" type="submit" formaction="demo_admin.html" id="promotionAdd" rel="tooltip" data-placement="bottom" data-original-title="If you have a promotional code - you could add it here.">Add</button>
 										</div>
 										<h6>(Use any text here and you'll receive 10% of discount!)</h6>
 									</div>
 								</div>
 								<div class="span6 total_block">
 									<h4>Summary Block</h4>
 									<table id="basketTotalsList">
 										<tbody>
 											<tr>
 												<td class="total_position">Goods Subtotal</td>
 												<td class="basket_subtotal">
 													<span class="currency">$</span><span class="amount">325.67</span>
 												</td>
 											</tr>
 											<tr>
 												<td class="total_position">Taxes (<span class="taxes_percent">0</span>%)</td>
 												<td class="basket_taxes">
 													<span class="currency">$</span><span class="amount">325.67</span>
 												</td>
 											</tr>
 											<tr>
 												<td class="total_position">Delivery cost</td>
 												<td class="basket_delivery">
 													<span class="currency">$</span><span class="amount">325.67</span>
 												</td>
 											</tr>
 											<tr>
 												<td class="total_position">Discount (<span class="discount_percent">0</span>%)</td>
 												<td class="basket_discount">
 													-<span class="currency">$</span><span class="amount">325.67</span>
 												</td>
 											</tr>
 											<tr class="total">
 												<td class="total_position">
 													<h3>Order Total</h3>
 												</td>
 												<td class="basket_total">
 													<h3>
 														<span class="currency">$</span><span class="amount">325.67</span>
 													</h3>
 												</td>
 											</tr>
 										</tbody>
 									</table>
 								</div>
 							</div>
 						</div>
 					</div>
 					<div class="navbar">
 						<div class="navbar-inner">
 							<ul class="nav custom_nav">
 								<li class="pull-left">
 									<div>
 										<a href="javascript: void(0);" class="btn btn-info">
 											<i class="icon-hand-left icon-white"></i>
 											Continue Shopping
 										</a>
 									</div>
 								</li>
 							
 	<li class="pull-right">
 									<a href="ajax_fakes/checkout.html">
 									<button class="btn btn-success continue_to_checkout" type="submit" value="Checkout" name="cont_to_checkout2">
 										Continue To Checkout
 									</button>
 			                </a></li>
 								<li class="pull-right">&nbsp;&nbsp;</li>
 								<li class="pull-right">
 									<div>
 										<button class="btn btn-danger remove_all" type="submit" name="remove_all2" value="remove_all" rel="tooltip" data-placement="top" data-original-title="Be careful! All products will be entirely removed from the basket!">
 											<i class="icon-remove icon-white"></i>
 											Remove All
 										</button>
 									</div>
 								</li>
 							</ul>
 						</div>
 					</div>
 				</div>
 			</form>
 
here is my php:

Code: Select all

		  /*** mysql hostname ***/
  $hostname = 'localhost';
  
  /*** mysql username ***/
  $username = 'username';
  
  /*** mysql password ***/
  $password = 'password';
  
 try {
     $dbh = new PDO("mysql:host=$hostname;dbname=mysql", $username, $password);
     /*** echo a message saying we have connected ***/
     echo 'Connected to database';
 
 
 
 /*** close the db connection. always do this ***/
     }
$dbh = null;
{
 
     }
 catch(PDOException $e)
     {
     echo $e->getMessage();
     }
 
 
 echo('Thank you for choosing our services. Your order is being processed.')
 
this is how i would like the data to be displayed in the db:

Code: Select all

	  
  $array = array();
  $array['options4521'][] = array('A','C','D');
  $array['options4521'][] = array('B','B','A');
  
  echo print_r($array);
  
  And the output is:
  
 [options4521] => Array
     (
         [0] => Array
             (
                 [0] => A
                 [1] => C
                 [2] => D
             )
 
         [1] => Array
             (
                 [0] => B
                 [1] => B
                 [2] => A
             )
 
     )
thank you all. glad you all around.

Re: collecting data from html template for php script

Posted: Tue Dec 01, 2015 8:55 pm
by requinix
I assume you're having some kind of problem with it?

Re: collecting data from html template for php script

Posted: Tue Dec 01, 2015 10:40 pm
by Christopher
You can get the values from your form in PHP from the $_POST superglobal variable. See http://us3.php.net/manual/en/language.v ... ternal.php