Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #9074 > unrolled thread

display two values on page

Started bynewbie php <s.hoitinga@gmail.com>
First post2013-04-18 02:44 -0700
Last post2013-04-18 18:46 +0200
Articles 9 — 6 participants

Back to article view | Back to comp.lang.php


Contents

  display two values on page newbie php <s.hoitinga@gmail.com> - 2013-04-18 02:44 -0700
    Re: display two values on page Tim Streater <timstreater@greenbee.net> - 2013-04-18 11:01 +0100
      Re: display two values on page Christoph Becker <cmbecker69@gmx.de> - 2013-04-18 12:14 +0200
        Re: display two values on page Tim Streater <timstreater@greenbee.net> - 2013-04-18 13:05 +0100
    Re: display two values on page Paul Herber <paul@pherber.com> - 2013-04-18 11:12 +0100
    Re: display two values on page Christoph Becker <cmbecker69@gmx.de> - 2013-04-18 12:18 +0200
    Re: display two values on page newbie php <s.hoitinga@gmail.com> - 2013-04-18 03:22 -0700
    Re: display two values on page Jerry Stuckle <jstucklex@attglobal.net> - 2013-04-18 09:08 -0400
      Re: display two values on page Luuk <luuk@invalid.lan> - 2013-04-18 18:46 +0200

#9074 — display two values on page

Fromnewbie php <s.hoitinga@gmail.com>
Date2013-04-18 02:44 -0700
Subjectdisplay two values on page
Message-ID<e154c2d7-ccdf-4058-81d5-cbfbfec20264@googlegroups.com>
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

[toc] | [next] | [standalone]


#9075

FromTim Streater <timstreater@greenbee.net>
Date2013-04-18 11:01 +0100
Message-ID<timstreater-BFF2AD.11010518042013@news.individual.net>
In reply to#9074
In article <e154c2d7-ccdf-4058-81d5-cbfbfec20264@googlegroups.com>,
 newbie php <s.hoitinga@gmail.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

[toc] | [prev] | [next] | [standalone]


#9077

FromChristoph Becker <cmbecker69@gmx.de>
Date2013-04-18 12:14 +0200
Message-ID<kkoh1h$v37$1@speranza.aioe.org>
In reply to#9075
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

[toc] | [prev] | [next] | [standalone]


#9080

FromTim Streater <timstreater@greenbee.net>
Date2013-04-18 13:05 +0100
Message-ID<timstreater-0271A5.13050318042013@news.individual.net>
In reply to#9077
In article <kkoh1h$v37$1@speranza.aioe.org>,
 Christoph Becker <cmbecker69@gmx.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

[toc] | [prev] | [next] | [standalone]


#9076

FromPaul Herber <paul@pherber.com>
Date2013-04-18 11:12 +0100
Message-ID<plhvm8d3lvq2eknakd27af2nb9j8qv934c@news.eternal-september.org>
In reply to#9074
On Thu, 18 Apr 2013 02:44:23 -0700 (PDT), newbie php <s.hoitinga@gmail.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>";

[toc] | [prev] | [next] | [standalone]


#9078

FromChristoph Becker <cmbecker69@gmx.de>
Date2013-04-18 12:18 +0200
Message-ID<kkoh96$a2$1@speranza.aioe.org>
In reply to#9074
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

[toc] | [prev] | [next] | [standalone]


#9079

Fromnewbie php <s.hoitinga@gmail.com>
Date2013-04-18 03:22 -0700
Message-ID<a12a7a1f-94a4-4ce1-971c-f200a682e1a1@googlegroups.com>
In reply to#9074
Great!

Thanks guys.

[toc] | [prev] | [next] | [standalone]


#9081

FromJerry Stuckle <jstucklex@attglobal.net>
Date2013-04-18 09:08 -0400
Message-ID<kkor2a$tm2$1@dont-email.me>
In reply to#9074
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@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#9084

FromLuuk <luuk@invalid.lan>
Date2013-04-18 18:46 +0200
Message-ID<ckk54a-7r4.ln1@luuk.invalid.lan>
In reply to#9081
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.....

;)

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web