Page 1 of 1

New-ish to PHP

Posted: Mon Apr 25, 2011 6:29 pm
by xCiter
I've tried searching the internet for my answer, but it all just seem's to confusing.

Basically, i have a page called "services.php" when someone hits "Buy" (with a quantity entered) i want the button (that links to that service)
to goto a confirmation page which will display info from the previous page such as..

The service name
The price
etc

Re: New-ish to PHP

Posted: Mon Apr 25, 2011 7:38 pm
by fugix
you will need to make a form around your inputs that has the action of the page that you want to go to

Code: Select all

<form action='confirmation_page.php' method='post'>
you can then store the user information that you want to store inside of a database..then echo those values on your confirmation page

Re: New-ish to PHP

Posted: Tue Apr 26, 2011 1:09 am
by social_experiment
On the confirmation page your information will be available in the $_POST array. Depending on your html form, fields can be accessed in the following way

Code: Select all

<?php echo $_POST['yourFieldName'];  ?>

Re: New-ish to PHP

Posted: Tue Apr 26, 2011 6:36 am
by xCiter
Hi, it works, thanks for the help.

However, i still have problems with displaying the result of which service purchase they selected.

In services.php i have:

Code: Select all

$serviceArray = array('Computer Tuneup', 'Hardware Repair', 'Software Install', 'Network Setup or Repair');
and in confirm.php i have:

Code: Select all

<?php echo $_POST['serviceArray[$i]'];?>
Not sure if this is correct way to do it.

Also, i have quantity boxes for the user to select how many computers they want to purchase the service for.

I was wondering how i get the confirm page to calculate the cost depending on the price of the service times the quantity they entered. The prices of the service are stored in an array as well.

Re: New-ish to PHP

Posted: Tue Apr 26, 2011 6:51 am
by superdezign
I'm not exactly sure what you are trying to do since you are only giving us one line of code at a time, but try removing the single quotes in the confirm.php line that you gave. Also, a general tip for debugging: Echo everything that you are unsure of.

Re: New-ish to PHP

Posted: Tue Apr 26, 2011 7:00 am
by social_experiment
To access any specific element inside the $serviceArray array, you would use $serviceArray[X], where X is the key of the element you want to access. I agree with superdezign, give more information about the problem.

Re: New-ish to PHP

Posted: Tue Apr 26, 2011 7:06 am
by xCiter
Here is my Confirm.php page, full code.

Code: Select all

<?php

// Build months array
$months = array('', 'January', 'Feburary', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<meta name="description" content="Your description goes here" />
	<meta name="keywords" content="your,keywords,goes,here" />
	<meta name="author" content="Your Name" />
	<link rel="stylesheet" type="text/css" href="andreas09.css" title="andreas09" media="screen,projection" />
	<title>TecheChat : Services</title>
</head>

<body>
<div id="container">
	<div id="sitename">
	  <h1>TecheChat</h1>
		<h2> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Computer Services</h2>
  </div>
	<div id="mainmenu">
		<ul>
			<li><a class="current" href="index.html">Home</a></li>
			<li><a href="green.html">Services</a></li>
			<li><a href="orange.html">Purchase</a></li>
			<li><a href="purple.html">Live Stream</a></li>
			<li><a href="red.html">Forum</a></li>
			<li><a href="black.html">Contact</a></li>
		</ul>
	</div>
 
	<div id="wrap">
		<div id="leftside">
			<h1>Included layouts</h1>
			<p><span class="hide"> | </span>
			<a class="nav" href="2col.html">2 columns</a><span class="hide"> | </span>
			<a class="nav" href="#">Samplebutton</a><span class="hide"> | </span>
			<a class="nav sub" href="#">Sub-page 1</a><span class="hide"> | </span>
			<a class="nav sub" href="#">Sub-page 2</a><span class="hide"> | </span>
			<a class="nav sub" href="#">Sub-page 3</a></p>
		</div>

		<div id="rightside">
			<h1>Search</h1>
			<p class="searchform">
			<input type="text" alt="Search" class="searchbox" />
			<input type="submit" value="Go!" class="searchbutton" />
			</p>
	
			<h1>Latest news</h1>
			<p><strong>July 07, 2008:</strong><br />
It's been a while. But better late than never: New version, updated with refreshed sample content and simplified code. This is andreas09 v2.2!</p>

			<h1>Links:</h1>
			<ul class="linklist">
				<li><a href="http://andreasviklund.com/templates/commercial/">Premium templates</a></li>
				<li><a href="http://andreasviklund.com/templates/">Free templates</a></li>
				<li><a href="http://purevolume.com/andreasviklund">Andreas' music</a></li>
				<li><a href="http://andreasviklund.com/support/">Support my work</a></li>
			</ul>
		</div>

		<div id="content">
		  <h1>Contact Details</h1>
		  <p class="intro">Please review your purchase and enter your contact details and what day/time you would like one of our team members to visit you. </p>
		  <form id="form1" method="post" action="confirm.php">
		    <table width="532" border="0" align="center">
		      <tr>
		        <td width="246"><div align="right"><strong>You have purchased the service: </strong></div></td>
		        <td width="276"><?php echo $_POST['serviceArray[$i]'];?></td>
	          </tr>
		      <tr>
		        <td><div align="right"><strong>Quantity:</strong></div></td>
		        <td>w</td>
	          </tr>
		      <tr>
		        <td><div align="right"><strong>Overall Cost: </strong></div></td>
		        <td>&nbsp;</td>
	          </tr>
		      <tr>
		        <td>&nbsp;</td>
		        <td>&nbsp;</td>
	          </tr>
		      <tr>
		        <td><div align="right"><strong>First Name:</strong></div></td>
		        <td><label for="name"></label>
	            <input type="text" name="name" id="name" /></td>
	          </tr>
		      <tr>
		        <td><div align="right"><strong>Last Name:</strong></div></td>
		        <td><label for="lname"></label>
	            <input type="text" name="lname" id="lname" /></td>
	          </tr>
		      <tr>
		        <td><div align="right"><strong>Contact Number:</strong></div></td>
		        <td><label for="contact_num"></label>
	            <input type="text" name="contact_num" id="contact_num" /></td>
	          </tr>
		      <tr>
		        <td><div align="right"><strong>Address:</strong></div></td>
		        <td><label for="address"></label>
	            <input type="text" name="address" id="address" /></td>
	          </tr>
		      <tr>
		        <td><div align="right"><strong>City:</strong></div></td>
		        <td><label for="city"></label>
	            <input type="text" name="city" id="city" /></td>
	          </tr>
		      <tr>
		        <td><div align="right"></div></td>
		        <td>&nbsp;</td>
	          </tr>
		      <tr>
		        <td><div align="right"><strong>Time you wish us to arrive: </strong></div></td>
		        <td>&nbsp;</td>
	          </tr>
		      <tr>
		        <td><div align="right"></div></td>
		        <td>&nbsp;</td>
	          </tr>
		      <tr>
		        <td><div align="right"><strong>Date you wish us to arrive: </strong></div></td>
		        <td>&nbsp;lol</td>
	          </tr>
		      <tr>
		        <td>&nbsp;</td>
		        <td>&nbsp;</td>
	          </tr>
		      <tr>
		        <td>&nbsp;</td>
		        <td><input type="submit" name="confirm_details" id="confirm_details" value="Confirm Details" />
	            <input type="reset" name="reset_form" id="reset_form" value="Reset Details" /></td>
	          </tr>
	        </table>
		    <br />
		    <p>Please read the terms & conditions about our purchasing and returns policy if you require any more information before buying.<br />
		    </p>
		    <p>Once form is submitted, you will be taken to PayPal to confirm your purchase. We only accept PayPal Payments at this time. </p>
          </form>
		  </p>
	      <p class="intro">&nbsp;</p>
	  </div>
	<div class="clearingdiv">&nbsp;</div>
	</div>
</div>

<div id="footer">
	<p>&copy; 2011 TecheChat | Template design by <a href="http://andreasviklund.com/">Andreas Viklund</a></p>
</div>

</body>
</html>
and this is Services.php

Code: Select all

<?php
//Define Service Names
$serviceArray = array('Computer Tuneup', 'Hardware Repair', 'Software Install', 'Network Setup or Repair');

//Define Service Prices (All are in order)
$servicePriceArray = array('10', '25', '15', '30');


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<meta name="description" content="Your description goes here" />
	<meta name="keywords" content="your,keywords,goes,here" />
	<meta name="author" content="Your Name" />
	<link rel="stylesheet" type="text/css" href="andreas09.css" title="andreas09" media="screen,projection" />
	<title>TecheChat : Services</title>
</head>

<body>
<div id="container">
	<div id="sitename">
	  <h1>TecheChat</h1>
		<h2> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Computer Services</h2>
  </div>
	<div id="mainmenu">
		<ul>
			<li><a class="current" href="index.html">Home</a></li>
			<li><a href="green.html">Services</a></li>
			<li><a href="orange.html">Purchase</a></li>
			<li><a href="purple.html">Live Stream</a></li>
			<li><a href="red.html">Forum</a></li>
			<li><a href="black.html">Contact</a></li>
		</ul>
	</div>
 
	<div id="wrap">
		<div id="leftside">
			<h1>Included layouts</h1>
			<p><span class="hide"> | </span>
			<a class="nav" href="2col.html">2 columns</a><span class="hide"> | </span>
			<a class="nav" href="#">Samplebutton</a><span class="hide"> | </span>
			<a class="nav sub" href="#">Sub-page 1</a><span class="hide"> | </span>
			<a class="nav sub" href="#">Sub-page 2</a><span class="hide"> | </span>
			<a class="nav sub" href="#">Sub-page 3</a></p>
		</div>

		<div id="rightside">
			<h1>Search</h1>
			<p class="searchform">
			<input type="text" alt="Search" class="searchbox" />
			<input type="submit" value="Go!" class="searchbutton" />
			</p>
	
			<h1>Latest news</h1>
			<p><strong>July 07, 2008:</strong><br />
It's been a while. But better late than never: New version, updated with refreshed sample content and simplified code. This is andreas09 v2.2!</p>

			<h1>Links:</h1>
			<ul class="linklist">
				<li><a href="http://andreasviklund.com/templates/commercial/">Premium templates</a></li>
				<li><a href="http://andreasviklund.com/templates/">Free templates</a></li>
				<li><a href="http://purevolume.com/andreasviklund">Andreas' music</a></li>
				<li><a href="http://andreasviklund.com/support/">Support my work</a></li>
			</ul>
		</div>

		<div id="content">
		  <h1>Services</h1>
		  <p class="intro">We here at TecheChat, it's all about offering quality service to our customers at affordable prices. All of us know, Technology breaks, things can happen and why should you pay so much for mistakes made by the computer itself and why should you pay so much for someone's criminal activity in infecting your PC with malicious software? </p>
		  <p class="intro">Well, at TecheChat, we have reviewed our service prices. We have come up with, what we think, to be very fair in the repair of your PC. Some servies you can purchase for multiple computers, if it is just one PC, leave the "Quantity" as 1</p>
		  <form id="form1" method="post" action="confirm.php">
		    <table width="677" border="1" align="center">
		      <tr>
		        <td width="162" align="center"><strong>Service </strong></td>
		        <td width="376" align="center"><strong>Description</strong></td>
		        <td width="117" align="center"><strong>Price</strong></td>
	          </tr>
		      <tr>
		        <td align="center" valign="top"><b><?php echo "$serviceArray[0]";?></b></td>
		        <td valign="top"><p>This service, we will perform the following actions on your PC: </p>
		          <p>- Disk Defragmentation</p>
		          <p>- Disk Cleanup</p>
		          <p>- Virus scan and removal</p>
	            <p>- Registry Cleanup</p>
	            <p>Extra Info:</p>
	            <p>While servicing your PC, if we detect any other problems, we will give you a "Critical Rating" we will inform you of any other potential probelms that we find with your PC. Depending on the problem and how serious it is, we may charge an extra £5 if the problem is a serious risk. If you do not wish us to fix it, we will respect your decision and leave it be. </p>
	            <p>&nbsp;</p>
	            <p>&nbsp;</p></td>
		        <td valign="top"><p align="center"><strong>£<?php echo "$servicePriceArray[0]";?></strong></p>
	            <p align="center">
	              <label for="tune_up_quan">Purchase:</label>
	              <input name="tune_up_quan" type="text" class="quantity" id="tune_up_quan" value="1" size="4" maxlength="2" />
	              <br />
	              <input type="submit" name="buy_tune_up" id="buy_tune_up" value="Buy Service" onclick="confirm_purchase.php" />
</p>
	            <p align="center"><br />
                </p></td>
	          </tr>
		      <tr>
		        <td align="center" valign="top"><b><?php echo "$serviceArray[1]";?></b></td>
		        <td valign="top">In this service, TecheChat will implement your new hardware, install any drivers that are required, all for £25</td>
		        <td align="center" valign="top"><p><strong>£<?php echo "$servicePriceArray[1]";?></strong></p>
	            <p>
	              <label for="hardware_repair_buy">Purchase:</label>
	              <input name="hardware_repair_buy" type="text" class="quantity" id="hardware_repair_buy" value="1" size="4" maxlength="2" />
	              <br />
	              <input type="submit" name="buy_hardware_repair" id="buy_hardware_repair" value="Buy Service" />
                </p></td>
	          </tr>
		      <tr>
		        <td align="center" valign="top"><b><?php echo "$serviceArray[2]";?></b></td>
		        <td valign="top">Having problems installing software? TecheChat will solve all of those problems for you. </td>
		        <td align="center" valign="top"><p><strong>£<?php echo "$servicePriceArray[2]";?></strong></p>
	            <p>
	              <label for="software_install_buy">Purchase:</label>
	              <input name="software_install_buy" type="text" class="quantity" id="software_install_buy" value="1" size="4" maxlength="2" />
	              <br />
	              <input type="submit" name="buy_software_install" id="buy_software_install" value="Buy Service" />
                </p></td>
	          </tr>
		      <tr>
		        <td align="center" valign="top"><b><?php echo "$serviceArray[3]";?></b></td>
		        <td valign="top">Network setup and repair. This service, we will come and setup your home or other network to share data between PC's or too simply connect to the internet.</td>
		        <td align="center" valign="top"><p><strong>£<?php echo "$servicePriceArray[3]";?></strong></p>
	            <p>
                  <label for="network_setup_r_b">Purchase:</label>
                  <strong>
	              <input name="network_setup_r_b" type="text" class="quantity" id="network_setup_r_b" value="1" size="4" maxlength="2" />
                </strong><br />
                <input type="submit" name="buy_network_sr" id="buy_network_sr" value="Buy Service" />
	            </p></td>
	          </tr>
	        </table>
	      </form>
		  <p class="intro">&nbsp;</p>
	  </div>
	<div class="clearingdiv">&nbsp;</div>
	</div>
</div>

<div id="footer">
	<p>&copy; 2011 TecheChat | Template design by <a href="http://andreasviklund.com/">Andreas Viklund</a></p>
</div>

</body>
</html>
I just want it so they click on a service, it gets the name of that service, the total cost depending on how much qauntity is entered, and the quantity they entered to be display on the confirm page. Sort of like a receipt to look over what they have purchased just to see if they've made any mistakes.