Welcome Guest ( Log In | Register)



3 Pages V   1 2 3 >  
Reply to this topicStart new topic
> Submit Restrictions, Is there anyway to bypass this on my localhost?
darran
post Sep 17 2006, 02:35 AM
Post #1


Privileged Member
*********

Group: Members
Posts: 661
Joined: 31-August 06
From: Singapore
Member No.: 29,189



This can be considered my first php page after a long while, I did a little basic php years ago and I have totally forgotten most of it. But I have come up with a page; a simple calculator if you will with the essential add, subtract, multiply and divide functions. When I load the page on my localhost, I get this error

IPB Image

However when I upload it to trap17, there is no problem, please take a look

http://darran.trap17.com/php/Calculator/calculator.php

I know this does not matter but I want to find out where I went wrong on my first php page.

The code listing for my calculator.php are as follows

CODE
<!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=iso-8859-1" />
<title>Calculator</title>

<style type="text/css">
<!--
.style1 {font-family: Georgia, "Times New Roman", Times, serif}
.style3 {font-family: Georgia, "Times New Roman", Times, serif; font-size: 36px; }
body,td,th {
    font-family: Georgia, Times New Roman, Times, serif;
}
-->
</style>
</head>

<body>
    
<form id="frmCalculator" name="Calculator" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  <br />
  <br />
  <br />
  <br />
  <br />
  <br />
  <br />
  <br />
  <table width="200" border="1" align="center" cellpadding="50" cellspacing="0" bordercolor="#000000">
    <tr>
      <td><table width="562" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td><div align="center"><span class="style3">Simple Calculator</span> </div></td>
        </tr>
      </table>
        <br />
        <table width="546" border="0" align="center" cellpadding="5" cellspacing="0" bordercolor="#000000">
        <tr>
          <td width="101"><span class="style1">1st Number </span></td>
          <td width="151"><span class="style1">
            <label>
            <input name="txt1stNumber" type="text" id="txt1stNumber" />
            </label>
          </span></td>
          <td width="110"><span class="style1">2nd Number </span></td>
          <td width="144"><span class="style1"></span>
              <input name="txt2ndNumber" type="text" id="txt2ndNumber" /></td>
        </tr>
        <tr>
          <td colspan="4"><label></label>
              <span class="style1">
                <label></label>
              <label></label>
              <label></label>
              </span>
              <label></label>
              <div align="center">
                <label> <span class="style1">
                <input type="radio" name="rad1" value="Add" />
                  Add</span></label>
                <span class="style1">
                <input type="radio" name="rad1" value="Subtract" />
                <label>Subtract</label>
                <label>
                <input type="radio" name="rad1" value="Multiply" />
                  Multiply</label>
                <label>
                <input type="radio" name="rad1" value="Divide" />
                  Divide</label>
            </span></div></td>
        </tr>
        <tr>
          <td colspan="4"><div align="center">
              <input name="btnSubmit" type="submit" class="style1" value="Submit"/>
              <input name="btnReset" type="reset" class="style1" id="btnReset" value="Reset"/>
          </div></td>
        </tr>
        <tr>
          <td colspan="4"><strong>Result:</strong>   <?php
                $rad1 = $_POST['rad1'];
                  $_1stNumber =  $_POST['txt1stNumber'];
                $_2ndNumber = $_POST['txt2ndNumber'];
                $result = "";

                if ($rad1 != null){
                      switch($rad1){
                        case "Add": $result = $_1stNumber + $_2ndNumber;
                        break;
                        case "Subtract": $result = $_1stNumber - $_2ndNumber;
                        break;
                        case "Multiply": $result = $_1stNumber * $_2ndNumber;
                        break;
                        case "Divide": $result = $_1stNumber / $_2ndNumber;
                        break;
                    }        
                    echo("<font color=#FF0000>$result</font>");
                }
    ?></td>
        </tr>
      </table></td>
    </tr>
  </table>
</form>
<p>&nbsp;</p>
</body>
</html>


I would appreciate it if anyone of you can guide me in this?
Go to the top of the page
 
+Quote Post
Albus Dumbledore
post Sep 17 2006, 02:51 AM
Post #2


Hidden Secrets can't be told threw just words. One must feel what the other feels to truely understand...
**************

Group: Members
Posts: 1,522
Joined: 8-January 06
From: Sacramento California
Member No.: 16,756



PHP does not work when opened in a browser.

for instance, when i try to look at my webpages in a browser when not uploaded to a website it will not show the PHP Includes that i have in my webpage. i dont know why, but it just wont show PHP functions like that
Go to the top of the page
 
+Quote Post
darran
post Sep 17 2006, 02:57 AM
Post #3


Privileged Member
*********

Group: Members
Posts: 661
Joined: 31-August 06
From: Singapore
Member No.: 29,189



I believe php works when opened in a browser, I mean I uploaded the php page into my trap17 host and it works fine. However when I do it on a localhost, I have errors coming. I think when you upload it, for security reason, Firefox or IE will simply format it. Anyway do you know what is wrong with my page? They both have the same code except 1 is previewed using my localhost and the other, on the trap17 host
Go to the top of the page
 
+Quote Post
Albus Dumbledore
post Sep 17 2006, 02:58 AM
Post #4


Hidden Secrets can't be told threw just words. One must feel what the other feels to truely understand...
**************

Group: Members
Posts: 1,522
Joined: 8-January 06
From: Sacramento California
Member No.: 16,756



what do you mean by your localhost?
Go to the top of the page
 
+Quote Post
tdktank59
post Sep 17 2006, 03:02 AM
Post #5


Super Member
*********

Group: Members
Posts: 398
Joined: 21-June 05
From: Callifornia
Member No.: 8,519



he means hes got apache and php instaled on his local computer or a local server at his place for testing...

or something along those lines i belive...

if not theres the problem lol

This post has been edited by tdktank59: Sep 17 2006, 03:03 AM
Go to the top of the page
 
+Quote Post
darran
post Sep 17 2006, 03:13 AM
Post #6


Privileged Member
*********

Group: Members
Posts: 661
Joined: 31-August 06
From: Singapore
Member No.: 29,189



tdktank59 says it. I have got apache and php installed in my system and the problem should not be anything pertaining to these services not installed in my system.
Go to the top of the page
 
+Quote Post
jlhaslip
post Sep 17 2006, 07:47 AM
Post #7


A computer once beat me at chess, but it was no match for me at kick boxing.
Group Icon

Group: [MODERATOR]
Posts: 4,081
Joined: 24-July 05
From: Linix, DOS and Windows…the good, the bad and the ugly
Member No.: 9,787
Spam Patrol



Typically, I would've handled this differntly than you have done. Check the following code which includes an input form for calculating the value of a purchase. Notice the difference in the logical structure?
The first thing this form does is check for a previously 'submitted' value and then handle the form or else present the form and include the 'hidden' field which is what is used in the first logic block above it.

CODE

<!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" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>Widget Cost Calculator</title>
</head>
<body>
<?php
// Check if the form has been submitted.
if (isset($_POST['submitted'])) {

// Cast all the variables to a specific type.
$quantity = (int) $_POST['quantity'];
$price = (float) $_POST['price'];
$tax = (float) $_POST['tax'];

// All variables should be positive!
if ( ($quantity > 0) && ($price > 0) && ($tax > 0)) {

// Calculate the total.
$total = ($quantity * $price) * (($tax/100) + 1);

// Print the result.
echo '<p>The total cost of purchasing ' . $quantity . ' widget(s) at $' . number_format ($price, 2) . ' each is $' . number_format ($total, 2) . '.</p>';

} else { // Invalid submitted values.
echo '<p><font color="red">Please enter a valid quantity, price, and tax rate.</font></p>';
}

} // End of main isset() IF.

// Leave the PHP section and create the HTML form.
?>
<h2>Widget Cost Calculator</h2>
<form action="calculator.php" method="post">
<p>Quantity: <input type="text" name="quantity" size="5" maxlength="10" value="<?php if (isset($quantity)) echo $quantity; ?>" /></p>
<p>Price: <input type="text" name="price" size="5" maxlength="10" value="<?php if (isset($price)) echo $price; ?>" /></p>
<p>Tax (%): <input type="text" name="tax" size="5" maxlength="10" value="<?php if (isset($tax)) echo $tax; ?>" /> (optional)</p>
<p><input type="submit" name="submit" value="Calculate!" /></p>
<input type="hidden" name="submitted" value="TRUE" />
</form>
</body>
</html>

There is always 'another way to do things, so check this page to see if you can recognize the difference in structure.
As to what is wrong with your form? I don't know. I had a terribly diffifult time when I read it. Tables and div's all mashed in together? No hidden field to see if the form had been submitted? Multiple uses of the same 'name'. The best thing I can do about your problem is to show you a sample of code which I would've used and perhaps you can learn from it and find the error. Besides, it is late at night and I need some sleep. Might have another look in the morning.

What version of php are you running on the XAMMP set-up? Might be a version problem. And the reset button doesn't clear a calculated value when I tried to use the page you posted.

Good effort for the first page, at least you got a result. Besides, the messages are 'Notices', not errors. Keep learning.
Go to the top of the page
 
+Quote Post
darran