Jump to content

PHP Include help


Emaj

Recommended Posts

I am fairly new to PHP. I tried searching for answers on Google and in this forum, but I found no solutions.

 

Problem

I used PHP include as a way of navigating through my website. I did this so if I changed the design of the website, I don't have to edit each page. The function is similar to iframes.

Yesterday I developed a tip calculator (calculates how much tip you need to give to the waiter or waitress based on your bill). However I've noticed after I press "submit", it sends the visitor to a page that shows only the results. I want to show the results within my website design.

 

Screen shots:

Help1.gif

I input the data. Notice the gray background and the navigation bar.

help2.gif

After I press "Submit Order", it shows the results but the results aren't within my website's design. (Notice the white background).

 

Question:

How can I incorporate the results from the tip calculator in my design after pressing the "Submit Order" button?

 

Here is the code on the main page of my website (HTML/CSS with PHP)

P.S For links in the navigation section, I used : ?id=name

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>MV Book</title>
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
</head>

<body>


<div id="wrapper">
<div id="wrapper2">
<div id="header"></div> <!-- End of Header -->

<div id="navi">
<ul>
<li><a href="/">Home</a></li>
<li><a href="?id=tip">Tip calculator</a></li>
<li><a href="?id=orderform">Tip calculator</a></li>

</ul>
</div> 
<!-- End of Navi -->
<div id="content">



<?php
$id = $_GET['id'] ;
switch($id) { default: include('cutenews/show_news.php');
break; case "orderform": include('orderform.html');
break; case "tip": include('tip.php');
} ?> 


</div> <!-- End of Content -->
</div> <!-- End of Wrapper 2 -->
</div> <!-- End of Wrapper -->

</body>
</html>

 

And this is the code that is on the page where I input the code:

 

<form action="processtip.php" method="POST">

<table border="0">
  <tr>
  <td>Bill Amount</td>
  <td align="center"><input type="text" name="billamount" size="10"
     maxlength="10" id="billamount"></td>
     </tr>
     
  <td>Tip Percent (%)</td>
  <td align="center"><input type="text" name="tippercent" size="10"
     maxlength="10" id="tippercent"></td>
</tr>
<tr>
  <td>Number Of People (Split)</td>
  <td align="center"><input type="text" name="people" size="10"
     maxlength="10" id="people" /></td>
</tr>

<tr>
  <td colspan="2" align="center"><input type="submit" value="Submit Order"></td>
</tr>
</table>
</form>

 

 

This is the PHP Code that process the input data and displays the results (processtip.php) :

 

<?PHP
  $billamount = $_POST['billamount'];
  $tipnumber = $_POST['tipnumber'];
  $people = $_POST['people'];
?>
<html>
<head>
  <title>Emaj's Tip Calculator</title>
</head>
<body>
<h1>Emaj's Tip Calculator</h1>
<h2>Thanks for using my Online Tip Calculator</h2>

<?php

if ($billamount < 0) {
  echo "<p> You can't have a negative number. Does the restuarant owe you money?";
  exit;


} else {

  if ($billamount == 0) {
	echo "What's the point of using a tip calculator if you didn't order anything?<br />";
	exit;

  }

  if ($billamount > 0) {
	echo "<p> Your bill is $".$billamount;

  }
}


$tippercent = 0;
$tippercent = $tipnumber/100;

$tipamount = 0;
$tipamount = $billamount * $tippercent;
echo "<p> Total tip is $".$tipamount;


$totalamount = 0;
$totalamount = $billamount + $tipamount;
echo "<p>Total bill (Tip included) is $".$totalamount;

echo "<p>You are splitting the Total Bill with ".$people." people.";

$indperson = 0;
$indperson = $totalamount/$people;
echo "<p>Each individual person pays $".$indperson;

?>


 

If there is a thread that has a similar problem with a solution, can you please post a link to it? Thank you and I apologize in advance if there's a duplicate thread.

 

-Emaj

 

Link to comment
Share on other sites

Just add your processing page to the switch statement:

$id = $_GET['id'] ;
switch($id) { default: include('cutenews/show_news.php');
break; case "orderform": include('orderform.html');
break; case "tip": include('tip.php');
break; case "processtip": include('processtip.php');
}

 

And then make the form submit to ?id=processtip instead of processtip.php.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.