i thought i knew how to deal with this notice, but i guess i'm wrong.

i learned early on in my PHP studies a way to use IF logic (typically in the first few lines of code on a page) to test for $POST['value'] to determine which part of a script to execute, based on the value of that $POST data. it works very well, except if:

[INDENT]a) i execute the page as a "standalone", in which case there is no $_POST data yet existing for this value

b) the page is opened by another page OTHER THAN that which sends the $_POST data used in this IF logic comparison[/INDENT]

because in either of those cases, i get a

Notice: Undefined index: 'value' in [filename] on [line name]

because that $_POST data has not yet been defined.

what can i do to avoid this notice? someone once suggested that i use $value = ""; to avoid that notice, but i CAN'T do $value = ''; to declare the variable because that would make NULL any value which is passed from $_POST during normal operation of this IF logic in the app.

EDIT: i'm taking a guess, from somthing that i'm reading now-- trying to figure this out. is THIS the answer?:
$value = True;

i'm afraid i'm missing some critical, basic PHP functioning rules here. what does it appear that i need to learn-- so i could have figured this out on my own!? surely there's a simple solution to this. what is it, and why am i missing it?

(okay, be nice-- please hold back the urge to say "because you're a numbskull!")

    it helps if you post the code that is giving you the grief, but in general, just check a variable is set before you try and use it.

    if (isset($_POST['value'])) {
      // do something with $_POST['value']
    }
    

      i've tried isset . why is that the answer? i'd swear it didnt' work for me!

        here's the code. i was trying to spare you:

        if ($_POST['op'] != "add") {
        // IF START (A)
        
        // TESTING MATCH FOR HIDDEN FORM FIELD ABOVE. 
        // this tests for the FORM submit button
        // IT WILL ALWAYS FAIL FIRST TIME SO THE FORM IS IN FACT DISPLAYED
        
        	// GET PARTS OF RECORDS - CREATE FUNCTION FOR RE-USING THIS SQL QUERY
        
        function getartists() {
        	$get_artist_ids = "select artist_id, artist_name from artist_info order by artist_name";
        	$artist_id_result = mysql_query($get_artist_ids) or die(mysql_error());
        		return $artist_id_result;
        	}
        
        
        // if LOGIC - CHECK FOR EXISTENCE OF CONCERT RECORDS.
        	// NO RESULTS = DISPLAY SORRY NO RECORDS.
        	// RECORDS = SHOW CONCERT RECORDS IN SELECTOR FORM.
        	$numrows = getartists();
        
        if (mysql_num_rows($numrows) < 1) {
        								  // IF START (B)
        	// NO RECORDS
        	$display_block .= "<p><em>Sorry, no artists exist to select!</em></p>
        						<p>Please <a href=\"addartist.php\">go add the Artists first</a>, then come back and
        						add the Concert Date</p>";
        }
        // IF END (B)
         else {
         // ELSE START (B)
        
        $display_block = "<h1>Add a Date:</h1>
        <form method=\"post\" action=\"$_SERVER[PHP_SELF]\" >

          well... i dont see anywhere in that code where you check to see if $_POST['op'] has been set before you try and use it?

            if ($_POST['op'] != "add") {
            // IF START (A)
            
            // TESTING MATCH FOR HIDDEN FORM FIELD ABOVE. 
            // this tests for the FORM submit button
            // IT WILL ALWAYS FAIL FIRST TIME SO THE FORM IS IN FACT DISPLAYED
            
            	// GET PARTS OF RECORDS - CREATE FUNCTION FOR RE-USING THIS SQL QUERY
            
            function getartists() {
            	$get_artist_ids = "select artist_id, artist_name from artist_info order by artist_name";
            	$artist_id_result = mysql_query($get_artist_ids) or die(mysql_error());
            		return $artist_id_result;
            	}
            
            
            // if LOGIC - CHECK FOR EXISTENCE OF CONCERT RECORDS.
            	// NO RESULTS = DISPLAY SORRY NO RECORDS.
            	// RECORDS = SHOW CONCERT RECORDS IN SELECTOR FORM.
            	$numrows = getartists();
            
            if (mysql_num_rows($numrows) < 1) {
            								  // IF START (B)
            	// NO RECORDS
            	$display_block .= "<p><em>Sorry, no artists exist to select!</em></p>
            						<p>Please <a href=\"addartist.php\">go add the Artists first</a>, then come back and
            						add the Concert Date</p>";
            }
            // IF END (B)
             else {
             // ELSE START (B)
            
            $display_block = "<h1>Add a Date:</h1>
            <form method=\"post\" action=\"$_SERVER[PHP_SELF]\" >
            
            	<p><strong>Headliner:</strong>
            	<br />
            	<select name=\"artist_id1\">
            		<option value=\"\">-- Select Headliner --</option>";
            
            // RUN FUNCTION FOR OPTION VALUES PULL DOWN		
            $resultArtist1 = getartists();
            while ($rowArtist = mysql_fetch_array($resultArtist1)) {
            														// START WHILE (A)
            	$id = $rowArtist['artist_id'];
            	$name = $rowArtist['artist_name'];
            
            	$display_block .= "<option value=\"$id\">
            			$name</option>
            			<input type=\"hidden\" name=\"name1\" value=\"$name\">";
            }
            // END WHILE (A)	
            
            	$display_block .= "</select>
            
            	<p><strong>First Supporting Act:</strong>
            	<br />
            	<select name=\"artist_id2\">
            		<option value=\"\">-- Select First Support --</option>";
            
            $resultArtist2 = getartists();
            while ($rowArtist = mysql_fetch_array($resultArtist2)) {
            														// START WHILE (B)
            	$id2 = $rowArtist['artist_id'];
            	$name2 = $rowArtist['artist_name'];
            
            	$display_block .= "<option value=\"$id2\">
            			$name2</option>
            			<input type=\"hidden\" name=\"name2\" value=\"$name2\">";
            
            }	
            // END WHILE (B)
            
            	$display_block .= "</select>
            
            	<p><strong>Second Supporting Act:</strong>
            	<br />
            	<select name=\"artist_id3\">
            		<option value=\"\">-- Select Second Support --</option>";
            
            $resultArtist3= getartists();
            while ($rowArtist = mysql_fetch_array($resultArtist3)) {
            														// START WHILE (C)
            	$id3 = $rowArtist['artist_id'];
            	$name3 = $rowArtist['artist_name'];
            
            	$display_block .= "<option value=\"$id3\">
            			$name3</option>
            			<input type=\"hidden\" name=\"name3\" value=\"$name3\">";
            
            }	
            // END WHILE (C)
            // AND FINISH MAKING FORM CONCATONATING INTO VARIABLE DISPLAY_BLOCK
            
            
            
            	$display_block .= "</select>	
            
            	<p><strong>Show Date:</strong>
            	<br />
            	<input type=\"text\" name=\"show_date\" size=\"20\" maxlength=\"25\" value=\"yyyy-mm-dd\" />
            	</p>
            
            	<p><strong>Show Time:</strong>
            	<br />
            	<input type=\"text\" name=\"show_time\" size=\"20\" maxlength=\"25\" value=\"HH:MM\" />
            	</p>
            
            	<p><strong>Ticket Price Date of Show:</strong>
            	<br />
            	<input type=\"text\" name=\"tix_dos\" size=\"20\" maxlength=\"25\" value=\"00.00\" />
            	</p>
            
            	<p><strong>Tickets in Advancee:</strong>
            	<br />
            	<input type=\"text\" name=\"tix_adv\" size=\"20\" maxlength=\"25\" value=\"$00.00\" />
            	</p>
            
            
            	<p><strong>All Ages?</strong>
            	<br />
            
            	<input type=\"radio\" name=\"age_req\" value=\"yes\" checked=\"checked\" /> yes
            	<input type=\"radio\" name=\"age_req\" value=\"no\" /> no
            	</p>
            
            	<input type=\"hidden\" name=\"clear\" value=\"\" />
            
            	<p><strong>Alcohol Served?</strong>
            	<br />
            	<input type=\"radio\" name=\"alcohol\" value=\"yes\" checked=\"checked\" /> yes
            	<input type=\"radio\" name=\"alcohol\" value=\"no\" /> no
            	</p>
            
            	<p><strong>Concert Date Notes:</strong>
            	<br />
            	<textarea name=\"concert_notes\" cols=\"35\" rows=\"5\" wrap=\"virtual\">notes on this concert
            	</textarea>
            	</p>
            
            	<input type=\"hidden\" name=\"op\" value=\"add\" />
            
            	<p><input type=\"submit\" name=\"submit\" value=\"Add Date\" />
            	</p>
            
            	</form>
            	<p>Back to <a href=\"control.htm\">main control</a></p>";
            
            } 
            // END ELSE B (OF IF B) 
            	}
            // END IF 'A' CAUSE FORM IS DONE AND HIDDEN VALUE TESTED AGAIN	
            
            if ($_POST['op'] == "add") {
            							// IF START 'D'
            	// IF INSIDE OF IF
            	// CHECKS FOR FIELDS REQUIRED TO SUBMIT THE FORM. IF MISSING DATA, FORM WILL RELOAD
            		if (($_POST['artist_id1'] == "") || ($_POST['show_date'] == "")) {
            																		 // IF START 'E'
            			header("Location: add_date.php");
            			exit;
            		}
            		// IF END 'E'
            
            // INSERTING NEW DATA INTO TABLE -NOW-
            //	CONNECT TO DATABASE
            $conn = mysql_connect("localhost", "private", "private")
            	or die(mysql_error());
            mysql_select_db("cb_shows1", $conn) or die(mysql_error());
            
            // SQL IS STORED INTO VARIABLE
            // TO ADD FORM $POST DATA TO ARTIST_INFO TABLE
            
            $add_artist = "insert into concerts values ('', '$_POST[artist_id1]', '$_POST[artist_id2]', '$_POST[artist_id3]', '$_POST[date_added]', '', '$_POST[show_date]', '$_POST[show_time]', '$_POST[tix_dos]', '$_POST[tix_adv]', '$_POST[age_req]', '$_POST[alcohol]', '$_POST[concert_notes]')"; 
            
            // PUT POST DATA INTO SEPARATE VARIABLES FOR SCREEN OUTPUT
            
            $artist1 = $_POST['name1'];
            $artist2 = $_POST['name'];
            $artist3 = $_POST['name3'];
            $todayadd = date('l dS \of F Y h:i A');
            $show_date = $_POST['show_date'];
            $show_time = $_POST['show_time'];
            $tix_dos = $_POST['tix_dos'];
            $tid_adv = $_POST['tix_adv'];
            $age = $_POST['age_req'];
            $alcohol = $_POST['alcohol'];
            $concert_notes = $_POST['concert_notes'];
            
              thorpe wrote:

              check to see if $_POST['op'] has been set before you try and use it?

              precisely-- so how is that done? can you explain ISSET to me please? i'm obviously missing something at php.net! or i was using it improperly.

                if (isset($_POST['foo'])) {
                	echo $_POST['foo'];
                } else {
                	echo 'foo not set';
                }

                  okay, i guess this is the problem-- the way i see it

                  laserlight wrote:
                  if (isset($_POST['foo'])) {
                  	echo $_POST['foo'];
                  } else {
                  	echo 'foo not set';
                  }

                  in the case of my code, isset would return false. so, how does that help? i already know that it's false-- it's what the logic of the IF statement is based on-- the "reason" that it works here, right? because there ISn't a value of 'op', and therefore, it must execute the appropriate code, accordign to the IF logic. yes? no?

                    Then change your condition to:
                    isset($POST['op']) && $POST['op'] != "add"

                    Or whatever it needs to be. Basically, dont use $POST['op'] unless isset($POST['op']) returns true.

                      cool! now, there's something that i can use! 😉
                      laserlight, can you tell me why you decided on that solution?

                      aside: this code, entered into mine now results in parse error, unexpected T_FUNCTION , but i think i've left out an ELSE in there. do you see it? (this is "old" code, i'm coming back to after a break-- looks like i missed a couple things)

                      EDIT: oh! wait... i have to use if (isset... [laserlight's code]) yes?

                        Post your new code.

                        By the way, I suggest taking your getartists() out of the block.

                          laserlight wrote:

                          Basically, dont use $POST['op'] unless isset($POST['op']) returns true.

                          so, this is the basic function of ISSET? i'm still a bit confused here. hmmm. maybe it will come to me if i go back to php.net now.

                            there is no new code. all i did was replace mine w/ yours, laserlight, as in:

                            if (isset($POST['op']) && $POST['op'] != "add" ) {

                            EDIT:
                            sorry, forgot to mention that i fixed something (i originall pasted laserlight's code OVER my IF statement, instead of OVER the IF Condition)... now the error is different:

                            Notice: Undefined index: op in C:\Apache\Apache2\htdocs\wwwroot\Crowbar\web_app\add_date.php on line 158

                            Notice: Undefined variable: display_block in C:\Apache\Apache2\htdocs\wwwroot\Crowbar\web_app\add_date.php on line 242

                            ALSO:
                            now i'm getting NO output, whereas before, at least i was getting the select boxes, etc.

                              i'm getting the idea that there's more wrong w/ this page than just that undefined index error?

                                this is the basic function of ISSET?

                                Yes. You cannot use a variable unless it exists. isset() is one way of checking that a variable exists.

                                now i'm getting NO output, whereas before, at least i was getting the select boxes, etc.

                                You apparently dont know what you are doing. Put your code aside, and try and understand the current concept. Write the smallest and simplest script that demonstrates (and then fixes) this problem.

                                  laserlight wrote:

                                  You cannot use a variable unless it exists. isset() is one way of checking that a variable exists.

                                  okay-- so, we check that it exists-- isset determines that it doesn't exist-- and then the code can proceed just because isset checked for it? there's got to be more to it than that.

                                  laserlight wrote:

                                  You apparently dont know what you are doing.

                                  laserlight get's the understatement of the day award! heehee

                                    then the code can proceed just because isset checked for it?

                                    Sort of. If you mean that the code can continue using the variable, then it is an obvious no, unless you handle the non-existence of the variable by assigning it some default value.

                                    //check that $_POST['foo'] exists
                                    if (isset($_POST['foo'])) {
                                    	//$_POST['foo'] exists
                                    	$foo = $_POST['foo']; //we might perform input validation here
                                    } else {
                                    	//$_POST['foo'] does not exist
                                    	$foo = ''; //assign a default value
                                    }
                                    
                                    //use $foo
                                    echo $foo;