Hey everyone. I have a form, but I want it so that only logged in users can enter information with it. This is the code for the user field. <input name="User" type="hidden" id="User" value="<?php echo $_SESSION['MM_Username']; ?>" /> How can i make it, so that if the user field is empty, ie. the user is not logged in, the form will not get inserted? Thanks
Hey it worked. What if I wanted it to say 'you must be logged in to vote' when they're not logged in? like some kind of 'else' statement?
Yes ofcourse.. You should learn the basics, if you don't know how to do an else statement you really shouldn't be making any adjustments yourself.. <?php if (..): ?> <?php else: ?> <?php endif; ?> PHP:
Can you show me how to write the else statement I did this but it didnt work.. <?php else: echo 'You Must Be Logged In' ?> Thanks
Try to use this: <? if (!empty($_SESSION['MM_Username'])) { // continue the script } else { // stop the script echo "You Must Be Logged In"; } ?> PHP:
Nah sorry that didnt work. I have some condition where it must be 2 seperate PHP sections. It has to be <?php if (!empty($_SESSION['MM_Username'])): ?> AT THE START then; <?php else: ?> AT THE END but I need to know how to write this else statement, to simply say, 'login to vote'
Try again this script: <? if (!empty($_SESSION['MM_Username'])) { ?> // continue anything <? } else { ?> // stop the script <b>You Must Be Logged In !</b> <p> login to vote <? // If you want it stop here, delete command at die() bellow: #die(); } ?> PHP: