php-general Digest 15 Jun 2012 13:35:51 -0000 Issue 7855

Topics (messages 318244 through 318248):

Re: php form action breaks script
        318244 by: Paul Halliday
        318246 by: Al
        318247 by: marco.behnke.biz
        318248 by: Jim Giner

Re: global array
        318245 by: marco.behnke.biz

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
On Thu, Jun 14, 2012 at 10:17 PM, David Robley <robl...@aapt.net.au> wrote:
> Tim Dunphy wrote:
>
>> Hello list,
>>
>>  I was just wondering if I could get some opinions on a snippet of
>> code which breaks a php web page.
>>
>>  First the working code which is basically an html form being echoed by
>>  php:
>>
>> if ($output_form) {
>>
>>   echo '<br /><br /><form action="sendemail.php>" method="post"  >

<form action="sendemail.php>"

should be:

<form action="sendemail.php" ...

>>   <label for="subject">Subject of email:</label><br />
>>   <input id="subject" name="subject" type="text" size="30" /><br />
>>   <label for="elvismail">Body of email:</label><br />
>>    <textarea id="elvismail" name="elvismail" rows="8"
>> cols="40"></textarea><br />
>>    <input type="submit" name="Submit" value="Submit" />
>>   </form>';
>>
>>
>>   }
>>
>> However if I change the form action to this, it breaks the page
>> resulting in a white screen of death:
>>
>>
>>   if ($output_form) {
>>
>>   echo '<br /><br /><form action="<?php echo $_SERVER['PHP_SELF']; ?>"
>> method="post"  >
>>   <label for="subject">Subject of email:</label><br />
>>   <input id="subject" name="subject" type="text" size="30" /><br />
>>   <label for="elvismail">Body of email:</label><br />
>>    <textarea id="elvismail" name="elvismail" rows="8"
>> cols="40"></textarea><br />
>>    <input type="submit" name="Submit" value="Submit" />
>>   </form>';
>>
>>
>>   }
>>
>> Reverting the one line to this:
>>
>> echo '<br /><br /><form action="sendemail.php" method="post"  >
>>
>> gets it working again. Now I don't know if it's an unbalanced quote
>> mark or what's going on. But I'd appreciate any advice you may have.
>>
>>
>> Best,
>> tim
>>
> If you check your apache log you'll probably see an error message. But the
> problem seems to be that your string you are trying to echo is enclosed in
> single quotes, and contains a string in <?php tags. Try something like
>
> echo '<br /><br /><form action="' . $_SERVER['PHP_SELF'] . '"
> method="post"> ...etc
>
>
>
> Cheers
> --
> David Robley
>
> "I haven't had any tooth decay yet," said Tom precariously.
> Today is Sweetmorn, the 20th day of Confusion in the YOLD 3178.
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>



-- 
Paul Halliday
http://www.squertproject.org/

--- End Message ---
--- Begin Message ---


On 6/14/2012 7:28 PM, Tim Dunphy wrote:
Hello list,

  I was just wondering if I could get some opinions on a snippet of
code which breaks a php web page.

  First the working code which is basically an html form being echoed by php:

if ($output_form) {

   echo '<br /><br /><form action="sendemail.php>" method="post">
   <label for="subject">Subject of email:</label><br />
   <input id="subject" name="subject" type="text" size="30" /><br />
   <label for="elvismail">Body of email:</label><br />
    <textarea id="elvismail" name="elvismail" rows="8"
cols="40"></textarea><br />
    <input type="submit" name="Submit" value="Submit" />
   </form>';


   }

However if I change the form action to this, it breaks the page
resulting in a white screen of death:


   if ($output_form) {

   echo '<br /><br /><form action="<?php echo $_SERVER['PHP_SELF']; ?>"
method="post">
   <label for="subject">Subject of email:</label><br />
   <input id="subject" name="subject" type="text" size="30" /><br />
   <label for="elvismail">Body of email:</label><br />
    <textarea id="elvismail" name="elvismail" rows="8"
cols="40"></textarea><br />
    <input type="submit" name="Submit" value="Submit" />
   </form>';


   }

Reverting the one line to this:

echo '<br /><br /><form action="sendemail.php" method="post">

gets it working again. Now I don't know if it's an unbalanced quote
mark or what's going on. But I'd appreciate any advice you may have.


Best,
tim

heredoc is best for this

if ($output_form){
  $report = <<<sty
<br /><br />
<form action="sendemail.php>" method="post"  >
<label for="subject">Subject of email:</label>
<br />
<input id="subject" name="subject" type="text" size="30" />
<br />
<label for="elvismail">Body of email:</label>
<br />
<textarea id="elvismail" name="elvismail" rows="8"cols="40"></textarea>
<br />
<input type="submit" name="Submit" value="Submit" />
</form>
sty;
}





--- End Message ---
--- Begin Message ---

Al <n...@ridersite.org> hat am 15. Juni 2012 um 14:29 geschrieben:

>
>
> On 6/14/2012 7:28 PM, Tim Dunphy wrote:
> > However if I change the form action to this, it breaks the page
> > resulting in a white screen of death:


error_reporting(E_ALL);
ini_set('display_errors', 'On');

And what is the error message?

--- End Message ---
--- Begin Message ---
Hear, Hear for heredocs.  The only way to code up your html.  Took me a few 
months to discover it and haven't looked back since. 



--- End Message ---
--- Begin Message ---

Jeff Burcher <j...@allredmetal.com> hat am 14. Juni 2012 um 14:23 geschrieben:

> You're a genius!! Thank you. Uppercase 'R', sheesh. PHP is sooo picky. I
> worked for two days trying to figure that one out. Anyway, for future
> reference, you can pass the entire array as a variable like that?? and do you
> know if the '+=' statement will create an array entry if one doesn't exist?


If you are using a higher loglevel, you'll get a notice for a not existing array
key.
In the othercase

$array[$mykey] += 1;

will work without notice. But as the key does not exist, the value will be null
and right now I am not sure what

null + 1

evaluates to?

Well, works....

maro@marco-behnke:~$ php -a
Interactive shell

php > $array = array();
php > $array['foo'] += 1;
PHP Notice:  Undefined index: foo in php shell code on line 1
PHP Stack trace:
PHP   1. {main}() php shell code:0
php > var_dump($array);
array(1) {
  ["foo"]=>
  int(1)
}

BUT I stronly recommend not to do that.

make it this way:

$array[$mykey] = array_key_exists($mykey, $array) ? $array[$mykey] += 1 :
$array[$mykey] = 1;

or better:

if (array_key_exists($mykey, $array)) {
   $array[$mykey] += 1;
} else {
   $array[$mykey] = 1;
}

>
> Thanks,
>
> Jeff Burcher - IT Dept
> Allred Metal Stamping
> PO Box 2566
> High Point, NC 27261
> (336)886-5221 x229
> j...@allredmetal.com
>
>
> > -----Original Message-----
> > From: ma...@behnke.biz [mailto:ma...@behnke.biz]
> > Sent: Thursday, June 14, 2012 8:04 AM
> > To: php-gene...@lists.php.net; j...@allredmetal.com
> > Subject: Re: [PHP] global array
> >
> >
> >
> >
> > Jeff Burcher <j...@allredmetal.com> hat am 14. Juni 2012 um 13:55
> > geschrieben:
> >
> > >
> > > function Part_BOM($PartID, $need, $phase) {
> > >
> > >
> > >
> > >                 global $Invreq;
> >
> >
> > uppercase R !!!
> > And much better is adding it as another parameter and inject it:
> >
> > function Part_BOM($PartID, $need, $phase, $InvReq) { ....
> > }
> >
> > // call it
> > Part_BOM(..., ..., ..., $InvReq);
> >
> > And please read about foreach() and what you can do with it.
> >
> > --
> > PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
> > http://www.php.net/unsub.php
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
Marco Behnke
Dipl. Informatiker (FH), SAE Audio Engineer Diploma
Zend Certified Engineer PHP 5.3

Tel.: 0174 / 9722336
e-Mail: ma...@behnke.biz

Softwaretechnik Behnke
Heinrich-Heine-Str. 7D
21218 Seevetal

http://www.behnke.biz

--- End Message ---

Reply via email to