FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » display two values on page
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
display two values on page [message #181130] Thu, 18 April 2013 09:44 Go to next message
newbie php is currently offline  newbie php
Messages: 3
Registered: April 2013
Karma: 0
Junior Member
Hi all,
I'm an absolute newbie to PHP, but I need to send two values to a php-page and multiplay to calculate costs for an order.
Simplified, i have a form that sends number and price to calculate.php.
code:
<form name="form" method="post" action="calculate.php">
<table border="0" cellspacing="5" cellpadding="10">
<tr>
<td>tickets</td>
<td><select name="number">
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
<option value=4>4</option>
<option value=5>5</option>
<option value=6>6</option>
<option value=7>7</option>
<option value=8>8</option>
<option value=9>9</option>
<option value=10>10</option>
</select></td>
</tr>

<tr>
<td>&nbsp;</td>
<td><input type="submit" name="button" id="button" value="calculate"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table><input name="price" type="hidden" value=6>
</form>

So the form sends the chosen number and the hidden value of 6 to calculate.php

Calculate php maltiplies both values. In code:

<html>
<head>Cost calculated</head>
<body>

<?php
$p=$_POST[price];
$n=$_POST[number];
$kosten = $p * $n;

echo $a "<br>"
echo $p "<br>"
echo $kosten "<br>"

?>

</body>
</html>

However, this results in a server-error.

Please, anybody, where do I go wrong?

Sybolt
Re: display two values on page [message #181131 is a reply to message #181130] Thu, 18 April 2013 10:01 Go to previous messageGo to next message
Tim Streater is currently offline  Tim Streater
Messages: 328
Registered: September 2010
Karma: 0
Senior Member
In article <e154c2d7-ccdf-4058-81d5-cbfbfec20264(at)googlegroups(dot)com>,
newbie php <s(dot)hoitinga(at)gmail(dot)com> wrote:

> <html>
> <head>Cost calculated</head>
> <body>

1) You probably mean:
<head>
<title >Cost calculated</title>
</head>

> <?php
> $p=$_POST[price];
> $n=$_POST[number];

2) For forward compatibility, better put:
$p=$_POST['price'];
$n=$_POST['number'];

> $kosten = $p * $n;
>
> echo $a "<br>"
> echo $p "<br>"

3) You really *must* put:
echo $a . "<br>"
echo $p . "<br>"

--
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted" -- Bill of Rights 1689
Re: display two values on page [message #181132 is a reply to message #181130] Thu, 18 April 2013 10:12 Go to previous messageGo to next message
Paul Herber is currently offline  Paul Herber
Messages: 26
Registered: February 2011
Karma: 0
Junior Member
On Thu, 18 Apr 2013 02:44:23 -0700 (PDT), newbie php <s(dot)hoitinga(at)gmail(dot)com> wrote:



> echo $a "<br>"
> echo $p "<br>"
> echo $kosten "<br>"

You need a ';' at the end of each of these lines for a start:

echo $a "<br>";
echo $p "<br>";
echo $kosten "<br>";
Re: display two values on page [message #181133 is a reply to message #181131] Thu, 18 April 2013 10:14 Go to previous messageGo to next message
Christoph Becker is currently offline  Christoph Becker
Messages: 91
Registered: June 2012
Karma: 0
Member
Tim Streater wrote:
> 3) You really *must* put:
> echo $a . "<br>"
> echo $p . "<br>"

Don't forget the terminating semicolon:

echo $a . "<br>";

--
Christoph M. Becker
Re: display two values on page [message #181134 is a reply to message #181130] Thu, 18 April 2013 10:18 Go to previous messageGo to next message
Christoph Becker is currently offline  Christoph Becker
Messages: 91
Registered: June 2012
Karma: 0
Member
newbie php wrote:
> However, this results in a server-error.

You'll want to activate error_reporting[1] and have a look at the error
logs. On a development system you may want to activate display_errors.

[1] <http://php.net/manual/en/function.error-reporting.php>

--
Christoph M. Becker
Re: display two values on page [message #181135 is a reply to message #181130] Thu, 18 April 2013 10:22 Go to previous messageGo to next message
newbie php is currently offline  newbie php
Messages: 3
Registered: April 2013
Karma: 0
Junior Member
Great!

Thanks guys.
Re: display two values on page [message #181136 is a reply to message #181133] Thu, 18 April 2013 12:05 Go to previous messageGo to next message
Tim Streater is currently offline  Tim Streater
Messages: 328
Registered: September 2010
Karma: 0
Senior Member
In article <kkoh1h$v37$1(at)speranza(dot)aioe(dot)org>,
Christoph Becker <cmbecker69(at)gmx(dot)de> wrote:

> Tim Streater wrote:
>> 3) You really *must* put:
>> echo $a . "<br>"
>> echo $p . "<br>"
>
> Don't forget the terminating semicolon:
>
> echo $a . "<br>";

Ha yes, you're quite right. My excuse: I was chasing a problem with
SQLite at the time.

--
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted" -- Bill of Rights 1689
Re: display two values on page [message #181137 is a reply to message #181130] Thu, 18 April 2013 13:08 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
In addition to what the others have said:

On 4/18/2013 5:44 AM, newbie php wrote:
<snip>

$p=isset($_POST['price']) ? $_POST['price'] : 0;
$n=isset($_POST['number']) ? $_POST['number'] : 0;


The reason being - your page may be called from pages other than the
form (i.e., someone typing the URL into the browser bar), in which case
$_POST['price'] and $_POST['number'] won't be set. This code will set
0's into $p and $n should the values not be set.

Better yet - don't put things like prices in hidden fields. It would be
very easy for me to create a form on my own machine which sets a price
of 1. You can display the price to the user, but keep critical values
like this on the server.

Remember - NOTHING from the user is ever safe and EVERYTHING needs to be
validated.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: display two values on page [message #181140 is a reply to message #181137] Thu, 18 April 2013 16:46 Go to previous message
Luuk is currently offline  Luuk
Messages: 329
Registered: September 2010
Karma: 0
Senior Member
On 18-04-2013 15:08, Jerry Stuckle wrote:
> It would be very easy for me to create a form on my own machine which
> sets a price of 1.

I would set it to zero.....

;)
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Anyone uses vTiger's webservice? I need help with webservice's response
Next Topic: Help with searching arrays of objects
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Dec 18 02:06:27 GMT 2024

Total time taken to generate the page: 0.02546 seconds