Jump to content

Php if null do code


Grantmau5

Recommended Posts

Sorry guys i hate this registering for an answer then leaving but i really need help. heres my code.

 

if(isset($_POST['send'])){
// Take user's name and say hello START
$rname = $_POST['rname'];
$dname = $_POST['dname'];
if($rname == null){
ob_start();
echo "JPi Encountered an error. Please try entering your real name again.";
$page = "preferences.html";
header("Refresh: 5; URL=\"" . $page . "\""); 
ob_flush();		
} 
else {
echo "Welcome, " . $rname . " to the JPi BOT. \r\n";
echo "Your current Display name is: " . $dname . ". \r\n";
// Take user's name and say hello END
	}
}

 

Basically if field equals null then give error and return to page

 

else print the welcome message.

 

For some reason it isn't working and i really can't spot my flaw.

 

Any help guys ?

 

 

Ps. I have also tried using empty, !isset, is_null...

Link to comment
https://forums.phpfreaks.com/topic/180489-php-if-null-do-code/
Share on other sites

Thank you for the suggestion. However the header isnt the problem here.

On the previous page i have two input fields: one for the user's real name and the other for a display name.

 

Im trying to redirect them back if the real name input field is empty (null) .

Otherwise i greet them announcing them by name.

 

and no i tried the empty() function but still doesnt work. Looking at my code im sure it should work  :wtf: :'(

Link to comment
https://forums.phpfreaks.com/topic/180489-php-if-null-do-code/#findComment-952162
Share on other sites

Never mind the code was correct. As you rightly pointed out it was an issue with the html, not the name part but i had onClick="value=' '" << i had a space inside the single quotes. Ah it's because it's midnight here, my heads not on properly. Thanks for the knock on the head i needed :P

Link to comment
https://forums.phpfreaks.com/topic/180489-php-if-null-do-code/#findComment-952167
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.