So, I have an input as below:
<input type="text" id="rhc_phone" name="rhc_phone" placeholder="Phone number"/>
Which in return store as a variable:
var data = {
'phone': $('#rhc_phone').val()
};
This then can be extracted via following:
<?php
echo '
<p>Call me at ' . $_POST['phone'] . '.</p>
';
?>
However, the input can be left out.
Now, what is the if statement to check if the variable has value and if not, then show something else like below.
<?php
if (!isset($_POST['phone']) = 0) {
echo '
<p>Call me at ' . $_POST['phone'] . '.</p>
';
}else{
<p>No Number</p>
}
?>
Is it correct?
Thanks!
Use empty
if(!empty($_POST['phone'])
{
echo '<p>Call me at'. $_POST['phone'] . '</p>';
} else {
echo '<p>No Number</p>';
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With