Re: Re: php form action breaks script

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hey guys,

It's been a little while since I've toyed with this, and I hope you
don't mind my coming back to you for some more advice. But I've
enjoyed some limited success with David R's advice regarding adding
some strong quoting to the mix. Here is what I last tried -

 <form method="post" action="' . $_SERVER['[PHP_SELF'] .'">

The pages do work, and the form checking code does its job (empty text
displays what information is missing). Except that there is an
annoying message that appears on screen and in the logs -

Notice: Undefined index: subject in
/Library/WebServer/Documents/examples/ch03/final/makemeelvis/sendemail.php
on line 23 Notice: Undefined index: elvismail in
/Library/WebServer/Documents/examples/ch03/final/makemeelvis/sendemail.php
on line 24 Notice: Undefined index: [PHP_SELF in
/Library/WebServer/Documents/examples/ch03/final/makemeelvis/sendemail.php
on line 62

[Wed Jun 27 20:13:42 2012] [error] [client 127.0.0.1] PHP Notice:
Undefined index: [PHP_SELF in
/Library/WebServer/Documents/examples/ch03/final/makemeelvis/sendemail.php
on line 62, referer: http://localhost/elvis/


This is what the entire PHP script looks like -


<!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=utf-8" />
  <title>Make Me Elvis - Send Email</title>
  <link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
  <img src="blankface.jpg" width="161" height="350" alt=""
style="float:right" />
  <img name="elvislogo" src="elvislogo.gif" width="229" height="32"
border="0" alt="Make Me Elvis" />
  <p><strong>Private:</strong> For Elmer's use ONLY<br /><br
  Write and send an email to mailing list members.</p>

<?php

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



  $from = 'bluethundr@xxxxxxxxxxxx';
  $subject = $_POST['subject'];
  $text = $_POST['elvismail'];
  $output_form = "false";


  if (isset($_POST['Submit'])) {

     if (empty($subject) && empty($text)) {
     echo 'You forgot the email subject and body.<br />';
     $output_form = 'true';

    }


     if (empty($subject) && !empty($text)) {
     echo 'You forgot the email subject.<br />';
     $output_form="true";

    }

    if ((!empty($subject)) && empty($text)) {

    echo 'You forgot the email body text.<br />';
    $output_form="true";


    }

}  else {

      $output_form = 'true';

   }



   if ($output_form == 'true') {

  echo '<br /><br />
        <form method="post" action="' . $_SERVER['[PHP_SELF'] .'">
        <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>';

  } else {

  $dbc = mysqli_connect('127.0.0.1', 'admin', 'secret', 'elvis_store')
    or die('Error connecting to MySQL server.');

  $query = "SELECT * FROM email_list";
  $result = mysqli_query($dbc, $query)
    or die('Error querying database.');

  while ($row = mysqli_fetch_array($result)){
    $to = $row['email'];
    $first_name = $row['first_name'];
    $last_name = $row['last_name'];
    $msg = "Dear $first_name $last_name,\n$text";
    mail($to, $subject, $msg, 'From:' . $from);
    echo 'Email sent to: ' . $to . '<br />';
  }

  mysqli_close($dbc);

 }


?>

</body>
</html>

Still working on the heredoc option, hoping to get more comfortable with it.

I'd appreciate any advice you might have.

Thanks
Tim



On Fri, Jun 15, 2012 at 2:09 PM, Al <news@xxxxxxxxxxxxx> wrote:
> It is a small price to pay for large block, especially if the text has any
> quotes. Personally, I can't keep them straight and delimit them, etc.
>  Heredoc saves all that such stuff.
>
> $insert= MY_DEFINED;
>
> echo <<<hdc
> This is my $insert
> hdc;
>
>
>
> On 6/15/2012 12:39 PM, Jim Lucas wrote:
>>
>> On 06/15/2012 06:35 AM, Jim Giner wrote:
>>>
>>> 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.
>>>
>>>
>>>
>>
>> The only problem I have with HEREDOC is I cannot use constants within
>> them.
>>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>



-- 
GPG me!!

gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux