I have some questions about isset() function.
isset() function checks if variable is set or not set or in other words it checks if value of variable is not NULL.
But what if I do something like this:
<?php
isset($var);
?>
What happens when I use isset() function on a variable that doesnt exist/isnt declared/isnt defined or whatever you call that?
I am asking because I am writing some code
<?php
function renderForm($firstName = '', $lastName = '' , $error = '', $id = ''){
?>
<div id='recordsForm'>
<h1><?php if($id != '' ){ echo "Edit Record"; } else { echo 'Create New Record'; } ?></h1>
<?php if($error != ''){ echo $error; } ?>
<form action='records.php' method='POST'>
<?php
if($id != ''){
?>
<input type='hidden' name='id' value='<?php echo $id; ?>'>
<?php
echo "<h3>Record ID: {$id}</h3>";
}
echo "First Name: <input type='text' name='firstname' value='".$firstName."' />";
echo "<br>";
echo "Last Name: <input type='text' name='lastname' value='".$lastName."' /> ";
echo "<br>";
echo "<input type='submit' name='submit' value='submit' />";
?>
</form>
</div>
<?php
}
if(isset($_GET['id']) && is_numeric($_GET['id'])){
// edit record
renderForm(NULL,NULL,NULL,$_GET['id']);
} else {
// add new record
if(isset($_POST['submit'])){
// Do some form processing stuff
} else {
renderform();
}
}
?>
?>
As you can see I wrote isset($_POST['submit']) even if $_POST['submit'] doesnt exist since i didnt called renderForm() function.
So does this means that isset() only checks if variable is not null even if variable doesnt exist like in my case?
I hope i didnt confused you :D