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
https://forums.phpfreaks.com/topic/224080-php-include-help/
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
https://forums.phpfreaks.com/topic/224080-php-include-help/#findComment-1157876
Share on other sites

Archived

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

×
×
  • 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.