Advanced Search

Page 3 of 3 FirstFirst 123
Results 21 to 25 of 25

Thread: Notice: Undefined variable: _post in mit textarea

  1. #21
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    11,787
    Thanks
    225
    Thanked 657 Times in 645 Posts

    Default

    As far as I know, there isn't a set() function, because you just use the equals sign $var = 'value'; method. It's part of the syntax, not a function.

    I don't think this should work:
    $_POST[''] = '';
    You are setting a null entry in the $_POST array to an empty string. Instead, I think you mean this:
    $_POST = ''; (or $_POST = array(); for an empty array)

    But why do you need to change it anyway? The values in $_POST are there for a reason and very, very rarely (in cases of complex redirects for example) would you want to change them manually. They only last for one page load and during that time, it is standard to know what was submitted via post methods in $_POST, just like using $_GET for the URL query string variables and $_COOKIE for cookie information, plus $_SERVER for information about the request and server settings.

    If you need to unset $_POST, then honestly you are probably doing something wrong overall. If you want to create a temporary variable that you can later delete (a working variable), then you can just copy $var = $_POST['var'];, then you can do whatever you want with $var, but you shouldn't be changing $_POST directly (in almost all circumstances).



    Regarding set() not producing an error:
    1. It might be an alias for the = method for setting a variable. It's not listed in the manual, though, so I'd avoid it regardless. It is correct syntax, but an undefined function usually triggers a fatal error.
    2. Check that your error reporting settings are set to report all errors (and probably notices/warnings as well). This way you'll know your code is working well, that you're writing standard code without any deprecated usages, and that it should generally work on other servers if you ever need to move it. PHP error reporting (although sometimes confusing) is a great feature that I think is very helpful once you learn to use it (again, it can be confusing).
    Last edited by djr33; 08-21-2012 at 12:03 AM. Reason: typo
    Daniel - Freelance Web Design | <?php?> | <html>| Deutsch | italiano | español | português | català | un peu de français | Ninasoma Kiswahili | 日本語の学生でした。| درست العربية

  2. #22
    Join Date
    Jan 2008
    Posts
    4,103
    Thanks
    18
    Thanked 615 Times in 611 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by djr33 View Post
    $_POST = ''; (or $_POST[''] = array(); for an empty array)
    I think you mean $_POST = array();

  3. #23
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    11,787
    Thanks
    225
    Thanked 657 Times in 645 Posts

    Default

    Yes, I did... cut and paste error. Fixed now. Thanks.
    Daniel - Freelance Web Design | <?php?> | <html>| Deutsch | italiano | español | português | català | un peu de français | Ninasoma Kiswahili | 日本語の学生でした。| درست العربية

  4. #24
    Join Date
    Aug 2012
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by djr33 View Post
    Yes, I did... cut and paste error. Fixed now. Thanks.
    Hi

    well I just do not write anything. It's not necessary, really.

    I have another form where I want to delete the content of the onput on upload. So there I put every single variable on empty string, but not in the same function, but after reading out DB Content. So it cannot be sent twice.
    I have an existing script which I change for my needs.
    Is it correct, in the below script I could delete the first 3 lines ?
    LG J.


    PHP Code:
    <?PHP
     
    /*1*/    if (!isset($_POST['form_datum'])) $_POST['form_datum'] = '';
     
    /*2*/    if (!isset($_POST['form_email'])) $_POST['form_email'] = '';
     
    /*3*/    if (!isset($_POST['form_text'])) $_POST['form_text'] = '';
     
    /*4*/    if (!isset($status)) $status '';

    if (isset(
    $_POST['upload']))  {
      if (isset(
    $_POST['form_datum']) && ($_POST['form_email']) &&  ($_POST['form_text']))

       {
            
    $sql "INSERT INTO gaestebuch (datum, email, text) VALUES (
                    '"
    .$_POST['form_datum']."',
                    '"
    .$_POST['form_email']."',
                    '"
    .$_POST['form_text']."'
                   )"
    ;
            
    $result mysql_query($sql);
            if(
    $result) {
              
    $status "...eingetragen";


        }
        else {
                
    $status "...fehlgeschlagen '".mysql_error()."'";
        }
      }
      else {
              
    $status '...Fehler! Fehlende Daten ';
      }
    }

     
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html lang="de">
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta name="description"         content="">
    <meta name="keywords"                 content="">
    <meta name="Robots"                 content="INDEX,FOLLOW">
    <meta name="Revisit"                 content="After 30 days">
    <link href="scripts/....css" rel="stylesheet" type="text/css">
    <script type="text/JavaScript">


    </script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script src="/scripts/jquery.ez-bg-resize.js" type="text/javascript"></script>
    <script type="text/javascript">
                    $(document).ready(function() {
                            $("body").ezBgResize({
                                    img     : "/grafik/hintergrund_gaestebuch.gif", // Relative path example.  You could also use an absolute url ([url]http://.[/url]..).
                                    opacity : 1, // Opacity. 1 = 100%.  This is optional.
                                    center  : true // Boolean (true or false). This is optional. Default is true.
                            });
                    });
             </script>

    </head>

    <body >
            <div id="main">
            <div id="logo"><img src="grafik/anna_logo.gif" alt="" border="0" width="212" height="45"></div>
            <div align="left" id="navi">
            <a href="index.php"> home</a>
            <a href="biografie.php">biografie</a>
            <a href="musik.php">musik</a>
            <a href="videos.php">videos</a>
            <a href="galerie.php">galerie</a>
    <a href="gaestebuch.php">g&auml;stebuch</a>
    <a href="pressetext.php">pressetext</a>
    <a href="kontakt.php">kontakt</a>
              </div>

           <div id="gaestebuch">

           <h1  id="inhtitel">G&auml;stebuch</h1>

           <div id="gtexte"><?PHP
           $i 
    "0";
            
    $sql "SELECT datum, email, text FROM gaestebuch ORDER BY id DESC";
            
    $result mysql_query($sql) or die(mysql_error());
            while (
    $row mysql_fetch_assoc($result)) {
            
    $i++;
                    if(
    $i%== 0) {echo '<tr>';}
                    else {echo 
    '<tr>';}
                    echo 
    '<td width="30%" align="left">'.$row['datum'].'<br/></td></tr>';
                    echo 
    '<tr><td width="70%" align="left">'.$row['text'].'.&nbsp;&nbsp;'.$row['email'].'<br/></td>';
                    echo 
    '</tr>';

            }
             
    $_POST['form_datum'] = '';
             
    $_POST['form_email'] = '';
           
    $_POST['form_text']  = '';

            
    ?>
              </div>

        <div id="guestin" >  <hr>      <form action="<?= $_SERVER['REQUEST_URI'?>" method="post" enctype="multipart/form-data" name="gaestebuch">
      Datum:&nbsp;
      <input name="form_datum" type="text" id="form_datum" size="15" maxlength="20" value="<?= $_POST['form_datum'?>">
      &nbsp;&nbsp;Name:&nbsp;<input name="form_email" type="text" id="form_email" size="30" maxlength="40" value="<?= $_POST['form_email'?>">
      <br>
      Dein Text:<br /><textarea name="form_text" cols="53" rows="3" id="form_text"> <?= $_POST['form_text'?></textarea>
      &nbsp;<input type="submit" name="upload" value="Upload">
    </form>  </div>
    Last edited by jscheuer1; 08-22-2012 at 03:04 PM. Reason: Format

  5. #25
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    11,787
    Thanks
    225
    Thanked 657 Times in 645 Posts

    Default

    If you delete the first three lines and the form has been submitted immediately before this page load (as the request for this page), then those values would exist. But $_POST values are reset every time the page loads-- the only last through one page, and they are not there permanently.

    Also, you can delete the fourth line without any problems at all. $status is never set above that, so it will never have a value-- isset($status) will always be false, so it won't do anything.


    The exception here is if you're using include() to bring this code into another page. If that's the case, then the situation is very different:
    1. $status might be set, and you can unset it if you'd like. But I'd recommend using a new variable instead, to avoid confusion. Use $status2 if you'd like, or anything else.
    2. I still would not recommend unsetting $_POST variables. Keep those accurate for what was submitted. Instead, either: 1) use a new variable name in the code below (because this way you will NEVER have a $_POST['form_datum'] value), or 2) at the beginning of your code create $form_datum and use that instead of $_POST[...], and unset $form_datum if you want.



    By the way, I suggest unset($var) instead of $var = ''. The '' method will still result in a value, but just a null value. Using unset() will actually entirely remove that variable from existence. This normally won't be very different, but it can sometimes matter if you're later using isset() for example.
    (The only time that using $var = '' makes sense is when you want to give a blank value for a string, such as one that you plan to echo later, and you don't want an error for 'undefined variable'.)
    Daniel - Freelance Web Design | <?php?> | <html>| Deutsch | italiano | español | português | català | un peu de français | Ninasoma Kiswahili | 日本語の学生でした。| درست العربية

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •