Undefined index Beginer here

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hypnotic11us
    New Member
    • Oct 2007
    • 3

    Undefined index Beginer here

    my code is:

    [code=php]
    <?php

    error_reporting (E_ALL);
    ini_set('displa y_errors', True);

    include("db.php ");

    $table = 'sondaje';

    $pollPick = $_POST['pollPick'];

    mysql_pconnect( $host, $user, $pass);

    mysql_select_db ($database);

    if ($pollPick != NULL ) {

    $query = "SELECT * FROM $table WHERE pollField = '$pollPick'";
    $result = mysql_query($qu ery);
    $num = mysql_num_rows( $result);

    if ($num > 0 ) { // if variable is ever greater than 0, we update the pollfield or insert a new one
    $query = "UPDATE $table SET pollCounter+1 WHERE pollField = '$pollPick' " ;
    mysql_query($qu ery) or die ("Couldn't Update table");


    } else { // if sum equals zero, then we will create a new row with the pollPick as the field name


    $query = "INSERT INTO $table VALUES ( '$pollPick', 1, '' )";

    mysql_query($qu ery) or die ("Couldn't insert new pollField into the table");
    }

    }


    //$query = "INSERT INTO $table VALUES ( '$pollPick', 1, '' )";
    //mysql_query($qu ery) or die ("Couldn't insert new pollField into the table");


    ?>
    [/code]

    The error message is:
    Code:
    Notice: Undefined index: pollPick in /home/***********/polls.php on line 10
    I really checked the spelling. Am I missing something? Thanks!
    Last edited by Atli; Oct 3 '07, 01:46 AM. Reason: Added [code] tags.
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi. Welcome to The Scripts!

    This is not exactly an Error. This is a Notice.
    The difference is that your code will execute fine even if you get Notices or Warnings. Although, like in your case, they can affect how your code is executed.

    You get this particular notice when an array element you are trying to read does not exists.

    In your case the $_POST['pollPick'] element on line 10 is empty.
    Your code assumes that it has been called by a HTML form element that contains a <input> named 'pollPick'. If the pages was requested without this form element you will get the notice you are receiving.

    If you are indeed calling this script from a <form>, make sure the 'pollPick' input exists (check typos in the name, and mind the case!).

    I recommend making sure that it exists before executing the code. That can be done by adding the following to the top of the code:
    [code=php]
    if(!isset($_POS T['pollPick'])) {
    die("Fatal error! The 'pollPick' input value is missing.");
    }
    [/code]

    Comment

    • hypnotic11us
      New Member
      • Oct 2007
      • 3

      #3
      Thank you for your reply! The pollPick is generated by a flash swf. I guess the problem is there, because the message i recieve after i input the code you gave me is "Fatal error! The 'pollPick' input value is missing".

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        OK I see.

        Is is possible that Flash sends the element name in lower case?
        'pollpicker' rather than 'pollPicker'?

        Those two represent different elements in PHP. Don't remember how it was in Flash.

        Comment

        Working...