isset function stopped working

Discussion in 'PHP' started by karl_murphy, Jan 26, 2009.

  1. #1
    Hi

    The isset function has seemed to have stopped working in a few of my scripts. The example below shows it used in a form when the form is posted. The global variables used within the function seem to be blank (almost like the isset function clears any values they have). I have tried echoeing out the variables before the function and the correct values are printed to the screen. The code is as follows:

    <select name = "add_student" id = "add_student">
    		<?php while ($row = mysql_fetch_assoc($rst)) 
    		{ 
    			$individual = $row['PU_Surname'] . " " . $row['PU_Forename'] . " - " . $row['PU_AdNo'];	
    		?>
    			<option value="<?php echo $row['PU_AdNo']; ?>"><?php echo $individual; ?></option>
    		<?php } ?>
    		</select>
    		</td>
    		<td>
    			&nbsp;&nbsp;&nbsp;&nbsp;
    		</td>
    		<td>
    			<input type="submit" name="Submit" value="Submit" onclick = 'javascript: return confirm("Are you sure you want to add this student to this class?")' />
    			<input type = 'hidden' name = 'submitted' value = 'true'>
    		
    		</td>
    	</tr>
    </table>
    </form>
    <?php 
    	$ad_no = $_POST['add_student'];
    	
    	if (isset($_POST['add_student'])) 
    		{
    			echo $row['PU_AdNo'];
    		 	$sql3 = "INSERT INTO ClassStudent ( CS_CL_ClassName , CS_PU_AdNo , CS_CL_SubjectCode , CS_PU_Year, CS_GT ) VALUES ('" . $current_class . "', '" . $ad_no . "', '" . $subjectcode . "', '" . $current_year . "', '" . $current_year . "')";
    			
    			include("../includes/php/connect3.php");
    		}
    ?>
    HTML:
    The INSERT statement does work, but the $current_class, $subjectcode and $current_year variables are blank when they should contain values.

    Any help with this issue would be greatly appreciated.
     
    karl_murphy, Jan 26, 2009 IP
  2. wmtips

    wmtips Well-Known Member

    Messages:
    601
    Likes Received:
    70
    Best Answers:
    1
    Trophy Points:
    150
    #2
    It seems you have register_globals turned OFF (and it's good). Instead of using autoglobals ($current_class) use values from $_POST ($_POST('current_class']).
     
    wmtips, Jan 26, 2009 IP
  3. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #3
    Your brackets don't make sense.
     
    Kaizoku, Jan 26, 2009 IP
  4. xxKillswitch

    xxKillswitch Peon

    Messages:
    331
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You are assigning $ad_no to the $_POST before you check if that $_POST is set, change that around, check if that post isset first then assign it. Also, what are you using in your main form tag, $_SERVER['PHP_SELF'] ? Also, what does the include do at the very bottom?

    
    <select name = "add_student" id = "add_student">
         <?php 
          while ($row = mysql_fetch_assoc($rst))
           {
                $individual = $row['PU_Surname'] . " " . $row['PU_Forename'] . " - " . $row['PU_AdNo']; 
            ?>
                <option value="<?php echo $row['PU_AdNo']; ?>"><?php echo $individual; ?></option>
            <?php 
            } ?>
    </select>
    </td>
    <td>
         &nbsp;&nbsp;&nbsp;&nbsp;
    </td>
    <td>
           <input type="submit" name="Submit" value="Submit" onclick = 'javascript: return confirm("Are you sure you want to add this student to this class?")' />
           <input type = 'hidden' name = 'submitted' value = 'true'>
    </td>
    </tr>
    </table>
    </form>
    <?php
    $ad_no = '';
    if (isset($_POST['add_student']))
    {
         $ad_no = $_POST['add_student'];
         echo $row['PU_AdNo'];
         $sql3 = "INSERT INTO ClassStudent ( CS_CL_ClassName , CS_PU_AdNo , CS_CL_SubjectCode , CS_PU_Year, CS_GT ) VALUES ('" . $current_class . "', '" . $ad_no . "', '" . $subjectcode . "', '" . $current_year . "', '" . $current_year . "')";
               
                include("../includes/php/connect3.php");
            }
    ?> 
    
    Code (markup):
     
    xxKillswitch, Jan 26, 2009 IP
  5. atlantaazfinest

    atlantaazfinest Peon

    Messages:
    389
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #5
    use empty()
     
    atlantaazfinest, Jan 26, 2009 IP