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


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

test prog inpu tpost

Started byvjp2.at@at.BioStrategist.dot.dot.com
First post2016-01-01 01:57 +0000
Last post2016-01-07 03:19 +0000
Articles 13 — 7 participants

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


Contents

  test prog inpu tpost vjp2.at@at.BioStrategist.dot.dot.com - 2016-01-01 01:57 +0000
    Re: test prog inpu tpost Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-12-31 21:22 -0500
      Re: test prog inpu tpost Matthew Carter <m@ahungry.com> - 2015-12-31 21:40 -0500
      Re: test prog inpu tpost "J.O. Aho" <user@example.net> - 2016-01-01 09:40 +0100
      Re: test prog inpu tpost Jerry Stuckle <jstucklex@attglobal.net> - 2016-01-01 09:32 -0500
        Re: test prog inpu tpost Arno Welzel <usenet@arnowelzel.de> - 2016-01-01 18:24 +0100
          Re: test prog inpu tpost Jerry Stuckle <jstucklex@attglobal.net> - 2016-01-01 14:07 -0500
            Re: test prog inpu tpost Matthew Carter <m@ahungry.com> - 2016-01-01 21:40 -0500
              Re: test prog inpu tpost Jerry Stuckle <jstucklex@attglobal.net> - 2016-01-01 21:53 -0500
              Re: test prog inpu tpost Arno Welzel <usenet@arnowelzel.de> - 2016-01-02 11:39 +0100
              Re: test prog inpu tpost Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-01-02 22:43 +0100
    Re: test prog inpu tpost Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-12-31 21:39 -0500
    Re: test prog inpu tpost vjp2.at@at.BioStrategist.dot.dot.com - 2016-01-07 03:19 +0000

#16045 — test prog inpu tpost

Fromvjp2.at@at.BioStrategist.dot.dot.com
Date2016-01-01 01:57 +0000
Subjecttest prog inpu tpost
Message-ID<n64mdp$ppg$1@reader1.panix.com>
SHould this work? I'm stuck with lynx browser for a few days and can't tell

<html>
<head>
<title>Quadratic</title>
</head>
<body>
<?php
  $t;$b=$_POST['b'];$a=$_POST['a'];$c=$_POST['c'];$x;$y;
  $t=(pow($b,2))-(4*$a*$c);
  if($t<=0)
    $t=(-1)*$t;
  $x=(-2*$c)/($b+(sqrt($t)));
  $y=(-2*$c)/($b-(sqrt($t)));
  echo sprintf("Solution in Addition = %f  in Subtraction = %f" ,$x,$y);
?>
<form method="post">
<label>What is a? <input type="number" name="a"></label><br>
<label>What is b? <input type="number" name="b"></label><br>
<label>What is c? <input type="number" name="c"></label><br>
<input type="submit">
</form>
</body>
</html>



				    - = -
 Vasos Panagiotopoulos, Columbia'81+, Reagan, Mozart, Pindus, BioStrategist
		    http://www.panix.com/~vjp2/vasos.htm
  ---{Nothing herein constitutes advice.  Everything fully disclaimed.}---
   [Homeland Security means private firearms not lazy obstructive guards]
 [Urb sprawl confounds terror] [Phooey on GUI: Windows for subprime Bimbos]



[toc] | [next] | [standalone]


#16046

FromLew Pitcher <lew.pitcher@digitalfreehold.ca>
Date2015-12-31 21:22 -0500
Message-ID<kplhy.63798$MN2.2950@fx07.iad>
In reply to#16045
On Thursday December 31 2015 20:57, in
comp.lang.php, "vjp2.at@at.BioStrategist.dot.dot.com"
<vjp2.at@at.BioStrategist.dot.dot.com> wrote:

> 
> Should this work?

> I'm stuck with lynx browser for a few days and can't tell 

That shouldn't stop you, assuming that you have a PHP-enabled webserver to
host the page on.

Lynx, like all browsers, just renders the html sent to it by the server.

PHP code executes on the server.

If the html with PHP is served from a PHP-enabled web server, lynx will render
the results correctly.
 
> <html>
> <head>
> <title>Quadratic</title>
> </head>
> <body>
> <?php
>   $t;

What is $t ?
Why are you trying to execute it as a php statement?

>   $b=$_POST['b'];$a=$_POST['a'];$c=$_POST['c'];

Here, you should test whether the page is invoked from a GET or a POST. None
of the $_POST variables will be set on the initial GET, and your later
computation will be invalid.

>   $x;$y;  

Same question as above with $t. What is $x? What is $y? Why are you trying to
execute two variables as php statements?

>   $t=(pow($b,2))-(4*$a*$c);

Meaningless (and possibly errant) results on GET

>   if($t<=0)
>     $t=(-1)*$t;
>   $x=(-2*$c)/($b+(sqrt($t)));
>   $y=(-2*$c)/($b-(sqrt($t)));
>   echo sprintf("Solution in Addition = %f  in Subtraction = %f" ,$x,$y);

This last stmt is overly complicated. Why wouldn't you just
  printf("Solution in Addition = %f  in Subtraction = %f" ,$x,$y);
?

> ?>
> <form method="post">
> <label>What is a? <input type="number" name="a"></label><br>
> <label>What is b? <input type="number" name="b"></label><br>
> <label>What is c? <input type="number" name="c"></label><br>

I'm not entirely certain that this is the proper use for the <label> element. 

> <input type="submit">
> </form>
> </body>
> </html>


-- 
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request

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


#16048

FromMatthew Carter <m@ahungry.com>
Date2015-12-31 21:40 -0500
Message-ID<87oad6c99q.fsf@ahungry.com>
In reply to#16046
Lew Pitcher <lew.pitcher@digitalfreehold.ca> writes:

> On Thursday December 31 2015 20:57, in
> comp.lang.php, "vjp2.at@at.BioStrategist.dot.dot.com"
> <vjp2.at@at.BioStrategist.dot.dot.com> wrote:
>
>> 
>> Should this work?
>
>> I'm stuck with lynx browser for a few days and can't tell 
>
> That shouldn't stop you, assuming that you have a PHP-enabled webserver to
> host the page on.
>
> Lynx, like all browsers, just renders the html sent to it by the server.
>
> PHP code executes on the server.
>
> If the html with PHP is served from a PHP-enabled web server, lynx will render
> the results correctly.
>  
>> <html>
>> <head>
>> <title>Quadratic</title>
>> </head>
>> <body>
>> <?php
>>   $t;
>
> What is $t ?
> Why are you trying to execute it as a php statement?
>
>>   $b=$_POST['b'];$a=$_POST['a'];$c=$_POST['c'];
>
> Here, you should test whether the page is invoked from a GET or a POST. None
> of the $_POST variables will be set on the initial GET, and your later
> computation will be invalid.
>
>>   $x;$y;  
>
> Same question as above with $t. What is $x? What is $y? Why are you trying to
> execute two variables as php statements?
>
>>   $t=(pow($b,2))-(4*$a*$c);
>
> Meaningless (and possibly errant) results on GET
>
>>   if($t<=0)
>>     $t=(-1)*$t;
>>   $x=(-2*$c)/($b+(sqrt($t)));
>>   $y=(-2*$c)/($b-(sqrt($t)));
>>   echo sprintf("Solution in Addition = %f  in Subtraction = %f" ,$x,$y);
>
> This last stmt is overly complicated. Why wouldn't you just
>   printf("Solution in Addition = %f  in Subtraction = %f" ,$x,$y);
> ?
>
>> ?>
>> <form method="post">
>> <label>What is a? <input type="number" name="a"></label><br>
>> <label>What is b? <input type="number" name="b"></label><br>
>> <label>What is c? <input type="number" name="c"></label><br>
>
> I'm not entirely certain that this is the proper use for the <label> element. 
>
>> <input type="submit">
>> </form>
>> </body>
>> </html>

Lynx and other command line browsers (elinks, w3m etc.) can all send
POST requests, so shouldn't have any trouble with your page.

You can also use curl to send POST requests (even from within PHP if you
have it installed as a module) to the form action location to test the
post event.

-- 
Matthew Carter (m@ahungry.com)
http://ahungry.com

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


#16049

From"J.O. Aho" <user@example.net>
Date2016-01-01 09:40 +0100
Message-ID<demsccFq5f4U1@mid.individual.net>
In reply to#16046
On 01/01/2016 03:22 AM, Lew Pitcher wrote:
> On Thursday December 31 2015 20:57, in
> comp.lang.php, "vjp2.at@at.BioStrategist.dot.dot.com"
> <vjp2.at@at.BioStrategist.dot.dot.com> wrote:
> 
>>
>> Should this work?
> 
>> I'm stuck with lynx browser for a few days and can't tell 
> 
> That shouldn't stop you, assuming that you have a PHP-enabled webserver to
> host the page on.
> 
> Lynx, like all browsers, just renders the html sent to it by the server.
> 
> PHP code executes on the server.
> 
> If the html with PHP is served from a PHP-enabled web server, lynx will render
> the results correctly.
>  
>> <html>
>> <head>
>> <title>Quadratic</title>
>> </head>
>> <body>
>> <?php
>>   $t;
> 
> What is $t ?
> Why are you trying to execute it as a php statement?

I think the OP is trying to initiate the variable before use, so to not
get errors with uninitiated variables, but will instead generate the
error as they are uninitiated.

>>   $b=$_POST['b'];$a=$_POST['a'];$c=$_POST['c'];
> 
> Here, you should test whether the page is invoked from a GET or a POST. None
> of the $_POST variables will be set on the initial GET, and your later
> computation will be invalid.

If allowing both, you could use $_REQUEST, but you should avoid to use
that, as it makes it easier to do unintended things.

Should always validate that you have got what you wanted in a request,
so should use for example is_numeric() to verify that the value is not
something else and stop the processing already here if it's invalid data.

>
>>   if($t<=0)
>>     $t=(-1)*$t;
>>   $x=(-2*$c)/($b+(sqrt($t)));
>>   $y=(-2*$c)/($b-(sqrt($t)));
>>   echo sprintf("Solution in Addition = %f  in Subtraction = %f" ,$x,$y);
> 
> This last stmt is overly complicated. Why wouldn't you just
>   printf("Solution in Addition = %f  in Subtraction = %f" ,$x,$y);
> ?

PHP allows you to use a lot of different ways, for example

echo "Solution in Addition = {$x}  in Subtraction = {$y}";

would work in this case too.

>> ?>
>> <form method="post">
>> <label>What is a? <input type="number" name="a"></label><br>
>> <label>What is b? <input type="number" name="b"></label><br>
>> <label>What is c? <input type="number" name="c"></label><br>
> 
> I'm not entirely certain that this is the proper use for the <label> element. 

No it's malformed, the label should have been closed before the input,
for those who want to know a little bit more of the use can head to
http://www.w3schools.com/tags/tag_label.asp

-- 

 //Aho

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


#16050

FromJerry Stuckle <jstucklex@attglobal.net>
Date2016-01-01 09:32 -0500
Message-ID<n662gh$hm$1@jstuckle.eternal-september.org>
In reply to#16046
On 12/31/2015 9:22 PM, Lew Pitcher wrote:
> On Thursday December 31 2015 20:57, in
> comp.lang.php, "vjp2.at@at.BioStrategist.dot.dot.com"
> <vjp2.at@at.BioStrategist.dot.dot.com> wrote:
> 
>>
>> Should this work?
> 
>> I'm stuck with lynx browser for a few days and can't tell 
> 
> That shouldn't stop you, assuming that you have a PHP-enabled webserver to
> host the page on.
> 
> Lynx, like all browsers, just renders the html sent to it by the server.
> 
> PHP code executes on the server.
> 
> If the html with PHP is served from a PHP-enabled web server, lynx will render
> the results correctly.
>  
>> <html>
>> <head>
>> <title>Quadratic</title>
>> </head>
>> <body>
>> <?php
>>   $t;
> 
> What is $t ?
> Why are you trying to execute it as a php statement?
> 
>>   $b=$_POST['b'];$a=$_POST['a'];$c=$_POST['c'];
> 
> Here, you should test whether the page is invoked from a GET or a POST. None
> of the $_POST variables will be set on the initial GET, and your later
> computation will be invalid.
>

In addition, you should check to see if the values are actually set.
Even if it came here from a POST request, there is no guarantee the
values have been set.

  $b = isset($_POST['b']) ? $_POST['b'] : '';

puts an empty string in $b $_POST['b'] is not set.  You could also use 0
instead of '' or any other default value you wish.

>>   $x;$y;  
> 
> Same question as above with $t. What is $x? What is $y? Why are you trying to
> execute two variables as php statements?
> 
>>   $t=(pow($b,2))-(4*$a*$c);
> 
> Meaningless (and possibly errant) results on GET
>

The advantage to using '' as a default value above is you can test here:

if ($a == '' || $b == '' || $c = '') {
   $t=(pow($b,2))-(4*$a*$c);
  (rest of your code)

>>   if($t<=0)
>>     $t=(-1)*$t;
>>   $x=(-2*$c)/($b+(sqrt($t)));
>>   $y=(-2*$c)/($b-(sqrt($t)));
>>   echo sprintf("Solution in Addition = %f  in Subtraction = %f" ,$x,$y);
> 
> This last stmt is overly complicated. Why wouldn't you just
>   printf("Solution in Addition = %f  in Subtraction = %f" ,$x,$y);
> ?
> 

Then the matching } would go here.

>> ?>
>> <form method="post">
>> <label>What is a? <input type="number" name="a"></label><br>
>> <label>What is b? <input type="number" name="b"></label><br>
>> <label>What is c? <input type="number" name="c"></label><br>
> 

You can also display the values used (and allow them to be changed) with:

<label>What is a? <input type="number" name="a"
   value="<?php echo $a;?>"></label><br>

Another advantage of using '' is the first time through the field will
be empty.

> I'm not entirely certain that this is the proper use for the <label> element. 
> 
>> <input type="submit">
>> </form>
>> </body>
>> </html>
> 
> 

One thing to remember here is that your web server script is not
interactive - the entire script will be executed before it is displayed
in your browser, unlike an application program which executes some code
then waits for input.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================

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


#16051

FromArno Welzel <usenet@arnowelzel.de>
Date2016-01-01 18:24 +0100
Message-ID<5686B656.3040603@arnowelzel.de>
In reply to#16050
Jerry Stuckle schrieb am 2016-01-01 um 15:32:

> On 12/31/2015 9:22 PM, Lew Pitcher wrote:
>> On Thursday December 31 2015 20:57, in
>> comp.lang.php, "vjp2.at@at.BioStrategist.dot.dot.com"
>> <vjp2.at@at.BioStrategist.dot.dot.com> wrote:
>>
>>>
>>> Should this work?
>>
>>> I'm stuck with lynx browser for a few days and can't tell 
>>
>> That shouldn't stop you, assuming that you have a PHP-enabled webserver to
>> host the page on.
>>
>> Lynx, like all browsers, just renders the html sent to it by the server.
>>
>> PHP code executes on the server.
>>
>> If the html with PHP is served from a PHP-enabled web server, lynx will render
>> the results correctly.
>>  
>>> <html>
>>> <head>
>>> <title>Quadratic</title>
>>> </head>
>>> <body>
>>> <?php
>>>   $t;
>>
>> What is $t ?
>> Why are you trying to execute it as a php statement?
>>
>>>   $b=$_POST['b'];$a=$_POST['a'];$c=$_POST['c'];
>>
>> Here, you should test whether the page is invoked from a GET or a POST. None
>> of the $_POST variables will be set on the initial GET, and your later
>> computation will be invalid.
>>
> 
> In addition, you should check to see if the values are actually set.
> Even if it came here from a POST request, there is no guarantee the
> values have been set.
> 
>   $b = isset($_POST['b']) ? $_POST['b'] : '';
> 
> puts an empty string in $b $_POST['b'] is not set.  You could also use 0
> instead of '' or any other default value you wish.
> 
>>>   $x;$y;  
>>
>> Same question as above with $t. What is $x? What is $y? Why are you trying to
>> execute two variables as php statements?
>>
>>>   $t=(pow($b,2))-(4*$a*$c);
>>
>> Meaningless (and possibly errant) results on GET
>>
> 
> The advantage to using '' as a default value above is you can test here:
> 
> if ($a == '' || $b == '' || $c = '') {

Of course this should be the opposite as one would do the calculation
only if *all* values are set and not if any of the value is empty:

if ($a != '' && $b != '' && $c != '') {

It would also be nice to see the values entered as default in the input
elements and to have valid HTML. And finally it is not neccessary to use

echo sprintf(...)

as there is printf() as well which outputs the result directly.

So the whole script could be like this:


<!DOCTYPE html>
<html>
<head>
<title>Quadratic</title>
</head>
<body>
<?php
$a = isset($_POST['a']) ? $_POST['a'] : '';
$b = isset($_POST['b']) ? $_POST['b'] : '';
$c = isset($_POST['c']) ? $_POST['c'] : '';

if ($a != '' && $b != '' && $c != '') {
    $t=(pow($b,2))-(4*$a*$c);
    if($t<=0)
        $t=(-1)*$t;
    $x=(-2*$c)/($b+(sqrt($t)));
    $y=(-2*$c)/($b-(sqrt($t)));
    printf(
      "<p>Solution in Addition = %f in Subtraction = %f</p>",
      $x, $y);
}
?>
<form method="post">
<label>What is a?
<input type="number" name="a"
value="<?php echo htmlspecialchars($a); ?>"></label><br />

<label>What is b?
<input type="number" name="b"
value="<?php echo htmlspecialchars($b); ?>"></label><br />

<label>What is c?
<input type="number" name="c"
value="<?php echo htmlspecialchars($c); ?>"></label><br />

<input type="submit">
</form>
</body>
</html>


But next time you promise to do your homework on your own, yes? ;-)


-- 
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de
http://fahrradzukunft.de

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


#16052

FromJerry Stuckle <jstucklex@attglobal.net>
Date2016-01-01 14:07 -0500
Message-ID<n66ikt$thi$1@jstuckle.eternal-september.org>
In reply to#16051
On 1/1/2016 12:24 PM, Arno Welzel wrote:
> Jerry Stuckle schrieb am 2016-01-01 um 15:32:
> 
>> On 12/31/2015 9:22 PM, Lew Pitcher wrote:
>>> On Thursday December 31 2015 20:57, in
>>> comp.lang.php, "vjp2.at@at.BioStrategist.dot.dot.com"
>>> <vjp2.at@at.BioStrategist.dot.dot.com> wrote:
>>>
>>>>
>>>> Should this work?
>>>
>>>> I'm stuck with lynx browser for a few days and can't tell 
>>>
>>> That shouldn't stop you, assuming that you have a PHP-enabled webserver to
>>> host the page on.
>>>
>>> Lynx, like all browsers, just renders the html sent to it by the server.
>>>
>>> PHP code executes on the server.
>>>
>>> If the html with PHP is served from a PHP-enabled web server, lynx will render
>>> the results correctly.
>>>  
>>>> <html>
>>>> <head>
>>>> <title>Quadratic</title>
>>>> </head>
>>>> <body>
>>>> <?php
>>>>   $t;
>>>
>>> What is $t ?
>>> Why are you trying to execute it as a php statement?
>>>
>>>>   $b=$_POST['b'];$a=$_POST['a'];$c=$_POST['c'];
>>>
>>> Here, you should test whether the page is invoked from a GET or a POST. None
>>> of the $_POST variables will be set on the initial GET, and your later
>>> computation will be invalid.
>>>
>>
>> In addition, you should check to see if the values are actually set.
>> Even if it came here from a POST request, there is no guarantee the
>> values have been set.
>>
>>   $b = isset($_POST['b']) ? $_POST['b'] : '';
>>
>> puts an empty string in $b $_POST['b'] is not set.  You could also use 0
>> instead of '' or any other default value you wish.
>>
>>>>   $x;$y;  
>>>
>>> Same question as above with $t. What is $x? What is $y? Why are you trying to
>>> execute two variables as php statements?
>>>
>>>>   $t=(pow($b,2))-(4*$a*$c);
>>>
>>> Meaningless (and possibly errant) results on GET
>>>
>>
>> The advantage to using '' as a default value above is you can test here:
>>
>> if ($a == '' || $b == '' || $c = '') {
> 
> Of course this should be the opposite as one would do the calculation
> only if *all* values are set and not if any of the value is empty:
> 
> if ($a != '' && $b != '' && $c != '') {
> 
> It would also be nice to see the values entered as default in the input
> elements and to have valid HTML. And finally it is not neccessary to use
> 
> echo sprintf(...)
> 
> as there is printf() as well which outputs the result directly.
> 
> So the whole script could be like this:
> 
> 
> <!DOCTYPE html>
> <html>
> <head>
> <title>Quadratic</title>
> </head>
> <body>
> <?php
> $a = isset($_POST['a']) ? $_POST['a'] : '';
> $b = isset($_POST['b']) ? $_POST['b'] : '';
> $c = isset($_POST['c']) ? $_POST['c'] : '';
> 
> if ($a != '' && $b != '' && $c != '') {
>     $t=(pow($b,2))-(4*$a*$c);
>     if($t<=0)
>         $t=(-1)*$t;
>     $x=(-2*$c)/($b+(sqrt($t)));
>     $y=(-2*$c)/($b-(sqrt($t)));
>     printf(
>       "<p>Solution in Addition = %f in Subtraction = %f</p>",
>       $x, $y);
> }
> ?>
> <form method="post">
> <label>What is a?
> <input type="number" name="a"
> value="<?php echo htmlspecialchars($a); ?>"></label><br />
> 
> <label>What is b?
> <input type="number" name="b"
> value="<?php echo htmlspecialchars($b); ?>"></label><br />
> 
> <label>What is c?
> <input type="number" name="c"
> value="<?php echo htmlspecialchars($c); ?>"></label><br />
> 
> <input type="submit">
> </form>
> </body>
> </html>
> 
> 
> But next time you promise to do your homework on your own, yes? ;-)
> 
> 

Sorry, I meant the code to go in the else clause, with an empty then clause.


-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================

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


#16053

FromMatthew Carter <m@ahungry.com>
Date2016-01-01 21:40 -0500
Message-ID<87fuygd7qu.fsf@ahungry.com>
In reply to#16052
Jerry Stuckle <jstucklex@attglobal.net> writes:

> On 1/1/2016 12:24 PM, Arno Welzel wrote:
>> Jerry Stuckle schrieb am 2016-01-01 um 15:32:
>> 
>>> On 12/31/2015 9:22 PM, Lew Pitcher wrote:
>>>> On Thursday December 31 2015 20:57, in
>>>> comp.lang.php, "vjp2.at@at.BioStrategist.dot.dot.com"
>>>> <vjp2.at@at.BioStrategist.dot.dot.com> wrote:
>>>>
>>>>>
>>>>> Should this work?
>>>>
>>>>> I'm stuck with lynx browser for a few days and can't tell 
>>>>
>>>> That shouldn't stop you, assuming that you have a PHP-enabled webserver to
>>>> host the page on.
>>>>
>>>> Lynx, like all browsers, just renders the html sent to it by the server.
>>>>
>>>> PHP code executes on the server.
>>>>
>>>> If the html with PHP is served from a PHP-enabled web server, lynx will render
>>>> the results correctly.
>>>>  
>>>>> <html>
>>>>> <head>
>>>>> <title>Quadratic</title>
>>>>> </head>
>>>>> <body>
>>>>> <?php
>>>>>   $t;
>>>>
>>>> What is $t ?
>>>> Why are you trying to execute it as a php statement?
>>>>
>>>>>   $b=$_POST['b'];$a=$_POST['a'];$c=$_POST['c'];
>>>>
>>>> Here, you should test whether the page is invoked from a GET or a POST. None
>>>> of the $_POST variables will be set on the initial GET, and your later
>>>> computation will be invalid.
>>>>
>>>
>>> In addition, you should check to see if the values are actually set.
>>> Even if it came here from a POST request, there is no guarantee the
>>> values have been set.
>>>
>>>   $b = isset($_POST['b']) ? $_POST['b'] : '';
>>>
>>> puts an empty string in $b $_POST['b'] is not set.  You could also use 0
>>> instead of '' or any other default value you wish.
>>>
>>>>>   $x;$y;  
>>>>
>>>> Same question as above with $t. What is $x? What is $y? Why are you trying to
>>>> execute two variables as php statements?
>>>>
>>>>>   $t=(pow($b,2))-(4*$a*$c);
>>>>
>>>> Meaningless (and possibly errant) results on GET
>>>>
>>>
>>> The advantage to using '' as a default value above is you can test here:
>>>
>>> if ($a == '' || $b == '' || $c = '') {
>> 
>> Of course this should be the opposite as one would do the calculation
>> only if *all* values are set and not if any of the value is empty:
>> 
>> if ($a != '' && $b != '' && $c != '') {
>> 
>> It would also be nice to see the values entered as default in the input
>> elements and to have valid HTML. And finally it is not neccessary to use
>> 
>> echo sprintf(...)
>> 
>> as there is printf() as well which outputs the result directly.
>> 
>> So the whole script could be like this:
>> 
>> 
>> <!DOCTYPE html>
>> <html>
>> <head>
>> <title>Quadratic</title>
>> </head>
>> <body>
>> <?php
>> $a = isset($_POST['a']) ? $_POST['a'] : '';
>> $b = isset($_POST['b']) ? $_POST['b'] : '';
>> $c = isset($_POST['c']) ? $_POST['c'] : '';
>> 
>> if ($a != '' && $b != '' && $c != '') {
>>     $t=(pow($b,2))-(4*$a*$c);
>>     if($t<=0)
>>         $t=(-1)*$t;
>>     $x=(-2*$c)/($b+(sqrt($t)));
>>     $y=(-2*$c)/($b-(sqrt($t)));
>>     printf(
>>       "<p>Solution in Addition = %f in Subtraction = %f</p>",
>>       $x, $y);
>> }
>> ?>
>> <form method="post">
>> <label>What is a?
>> <input type="number" name="a"
>> value="<?php echo htmlspecialchars($a); ?>"></label><br />
>> 
>> <label>What is b?
>> <input type="number" name="b"
>> value="<?php echo htmlspecialchars($b); ?>"></label><br />
>> 
>> <label>What is c?
>> <input type="number" name="c"
>> value="<?php echo htmlspecialchars($c); ?>"></label><br />
>> 
>> <input type="submit">
>> </form>
>> </body>
>> </html>
>> 
>> 
>> But next time you promise to do your homework on your own, yes? ;-)
>> 
>> 
>
> Sorry, I meant the code to go in the else clause, with an empty then clause.

Also - unless you're using an outdated version of PHP for some reason,
you no longer have to write code like:

$x = isset($_GET['x']) ? $_GET['x'] : '';

You can use the null coalesce operator:

$x = $_GET['x'] ?? '';

-- 
Matthew Carter (m@ahungry.com)
http://ahungry.com

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


#16054

FromJerry Stuckle <jstucklex@attglobal.net>
Date2016-01-01 21:53 -0500
Message-ID<n67dtm$lb2$1@jstuckle.eternal-september.org>
In reply to#16053
On 1/1/2016 9:40 PM, Matthew Carter wrote:
> Jerry Stuckle <jstucklex@attglobal.net> writes:
> 
>> On 1/1/2016 12:24 PM, Arno Welzel wrote:
>>> Jerry Stuckle schrieb am 2016-01-01 um 15:32:
>>>
>>>> On 12/31/2015 9:22 PM, Lew Pitcher wrote:
>>>>> On Thursday December 31 2015 20:57, in
>>>>> comp.lang.php, "vjp2.at@at.BioStrategist.dot.dot.com"
>>>>> <vjp2.at@at.BioStrategist.dot.dot.com> wrote:
>>>>>
>>>>>>
>>>>>> Should this work?
>>>>>
>>>>>> I'm stuck with lynx browser for a few days and can't tell 
>>>>>
>>>>> That shouldn't stop you, assuming that you have a PHP-enabled webserver to
>>>>> host the page on.
>>>>>
>>>>> Lynx, like all browsers, just renders the html sent to it by the server.
>>>>>
>>>>> PHP code executes on the server.
>>>>>
>>>>> If the html with PHP is served from a PHP-enabled web server, lynx will render
>>>>> the results correctly.
>>>>>  
>>>>>> <html>
>>>>>> <head>
>>>>>> <title>Quadratic</title>
>>>>>> </head>
>>>>>> <body>
>>>>>> <?php
>>>>>>   $t;
>>>>>
>>>>> What is $t ?
>>>>> Why are you trying to execute it as a php statement?
>>>>>
>>>>>>   $b=$_POST['b'];$a=$_POST['a'];$c=$_POST['c'];
>>>>>
>>>>> Here, you should test whether the page is invoked from a GET or a POST. None
>>>>> of the $_POST variables will be set on the initial GET, and your later
>>>>> computation will be invalid.
>>>>>
>>>>
>>>> In addition, you should check to see if the values are actually set.
>>>> Even if it came here from a POST request, there is no guarantee the
>>>> values have been set.
>>>>
>>>>   $b = isset($_POST['b']) ? $_POST['b'] : '';
>>>>
>>>> puts an empty string in $b $_POST['b'] is not set.  You could also use 0
>>>> instead of '' or any other default value you wish.
>>>>
>>>>>>   $x;$y;  
>>>>>
>>>>> Same question as above with $t. What is $x? What is $y? Why are you trying to
>>>>> execute two variables as php statements?
>>>>>
>>>>>>   $t=(pow($b,2))-(4*$a*$c);
>>>>>
>>>>> Meaningless (and possibly errant) results on GET
>>>>>
>>>>
>>>> The advantage to using '' as a default value above is you can test here:
>>>>
>>>> if ($a == '' || $b == '' || $c = '') {
>>>
>>> Of course this should be the opposite as one would do the calculation
>>> only if *all* values are set and not if any of the value is empty:
>>>
>>> if ($a != '' && $b != '' && $c != '') {
>>>
>>> It would also be nice to see the values entered as default in the input
>>> elements and to have valid HTML. And finally it is not neccessary to use
>>>
>>> echo sprintf(...)
>>>
>>> as there is printf() as well which outputs the result directly.
>>>
>>> So the whole script could be like this:
>>>
>>>
>>> <!DOCTYPE html>
>>> <html>
>>> <head>
>>> <title>Quadratic</title>
>>> </head>
>>> <body>
>>> <?php
>>> $a = isset($_POST['a']) ? $_POST['a'] : '';
>>> $b = isset($_POST['b']) ? $_POST['b'] : '';
>>> $c = isset($_POST['c']) ? $_POST['c'] : '';
>>>
>>> if ($a != '' && $b != '' && $c != '') {
>>>     $t=(pow($b,2))-(4*$a*$c);
>>>     if($t<=0)
>>>         $t=(-1)*$t;
>>>     $x=(-2*$c)/($b+(sqrt($t)));
>>>     $y=(-2*$c)/($b-(sqrt($t)));
>>>     printf(
>>>       "<p>Solution in Addition = %f in Subtraction = %f</p>",
>>>       $x, $y);
>>> }
>>> ?>
>>> <form method="post">
>>> <label>What is a?
>>> <input type="number" name="a"
>>> value="<?php echo htmlspecialchars($a); ?>"></label><br />
>>>
>>> <label>What is b?
>>> <input type="number" name="b"
>>> value="<?php echo htmlspecialchars($b); ?>"></label><br />
>>>
>>> <label>What is c?
>>> <input type="number" name="c"
>>> value="<?php echo htmlspecialchars($c); ?>"></label><br />
>>>
>>> <input type="submit">
>>> </form>
>>> </body>
>>> </html>
>>>
>>>
>>> But next time you promise to do your homework on your own, yes? ;-)
>>>
>>>
>>
>> Sorry, I meant the code to go in the else clause, with an empty then clause.
> 
> Also - unless you're using an outdated version of PHP for some reason,
> you no longer have to write code like:
> 
> $x = isset($_GET['x']) ? $_GET['x'] : '';
> 
> You can use the null coalesce operator:
> 
> $x = $_GET['x'] ?? '';
> 

You *can* - but there are still a lot of installations (I would wager a
majority) which haven't been updated to PHP 7.0 yet.  Drupal and Ubuntu
come to mind, for instance.  Their stable version packages are still
back at 5.something.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================

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


#16055

FromArno Welzel <usenet@arnowelzel.de>
Date2016-01-02 11:39 +0100
Message-ID<5687A8D7.8010505@arnowelzel.de>
In reply to#16053
Matthew Carter schrieb am 2016-01-02 um 03:40:

[...]
> Also - unless you're using an outdated version of PHP for some reason,
> you no longer have to write code like:
> 
> $x = isset($_GET['x']) ? $_GET['x'] : '';
> 
> You can use the null coalesce operator:
> 
> $x = $_GET['x'] ?? '';

In fact only the latest version of PHP - 7.0 - supports this. Also see
<http://php.net/manual/en/migration70.new-features.php>.

So "outdated" is not really correct.

According to <http://php.net/supported-versions.php> PHP 5.6 is not
outdated yet and will get security fixes until 28 August 2016. Even PHP
5.5 is still getting security fixes - and both version don't support the
null coalesce operator.

There are also many older installations if PHP as well which either get
maintained by the distributors (e.g. Debian/Ubuntu) or they just don't
get upates at all.

As PHP 7.0 was just released a couple of weeks ago I also doubt that
many shared hosting provider already offer PHP 7.0. Many of them will
still use PHP 5.6 or 5.5 to avoid trouble with older PHP scripts of
their customers.


-- 
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de
http://fahrradzukunft.de

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


#16063

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2016-01-02 22:43 +0100
Message-ID<3589447.gGvhme3zgT@PointedEars.de>
In reply to#16053
Matthew Carter wrote:

> Also - unless you're using an outdated version of PHP for some reason,
> you no longer have to write code like:
> 
> $x = isset($_GET['x']) ? $_GET['x'] : '';
> 
> You can use the null coalesce operator:
> 
> $x = $_GET['x'] ?? '';

PHP 5.x is not an “outdated version” yet, and it is to be hoped that this 
expression does not generate a notice in PHP 7.0.x if $_GET has no “x” key.
 
-- 
PointedEars
Zend Certified PHP Engineer
Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.

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


#16047

FromLew Pitcher <lew.pitcher@digitalfreehold.ca>
Date2015-12-31 21:39 -0500
Message-ID<hFlhy.87305$1g3.10153@fx03.iad>
In reply to#16045
On Thursday December 31 2015 20:57, in
comp.lang.php, "vjp2.at@at.BioStrategist.dot.dot.com"
<vjp2.at@at.BioStrategist.dot.dot.com> wrote:

> 
> SHould this work? I'm stuck with lynx browser for a few days and can't tell

FWIW, here is the output from lynx


                                                                      
Quadratic
   Solution in Addition = 0.000000 in Subtraction = 0.000000 What is a?
   ____________________
   What is b? ____________________
   What is c? ____________________
   Submit















(Text entry field) Enter text. Use UP or DOWN arrows or tab to move off.
            Enter text into the field by typing on the keyboard
    Ctrl-U to delete all text in field, [Backspace] to delete a character
-- 
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request

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


#16125

Fromvjp2.at@at.BioStrategist.dot.dot.com
Date2016-01-07 03:19 +0000
Message-ID<n6klge$64o$1@reader1.panix.com>
In reply to#16045
Many Thanks to everyone. I was looking for an example program 
with quadratic, because I fugured it would be the easiest place to start.

I actually have other projects I want to code.

But I remember my first 1978 FORTRAN homework program was quadratic.



				    - = -
 Vasos Panagiotopoulos, Columbia'81+, Reagan, Mozart, Pindus, BioStrategist
		    http://www.panix.com/~vjp2/vasos.htm
  ---{Nothing herein constitutes advice.  Everything fully disclaimed.}---
   [Homeland Security means private firearms not lazy obstructive guards]
 [Urb sprawl confounds terror] [Phooey on GUI: Windows for subprime Bimbos]



[toc] | [prev] | [standalone]


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


csiph-web