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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.