Jump to content

Do not insert FORM if User field is empty?


tomm098

Recommended Posts

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

Link to comment
Share on other sites

ok try this

 

<td>
<?php

if ($_SESSION['MM_Username']) {
   echo '<form action="" method="post" name="form5" id="form5"><p class="style6"><select name="Vote" id="Vote">
                <option value="1">1 (Abysmal)</option>
                <option value="2">2</option>
                <option value="3">3 (Poor)</option>
                <option value="4">4</option>
                <option value="5" selected="selected">5 (Average)</option>
                <option value="6">6</option>
                <option value="7">7 (Good)</option>
                <option value="8">8</option>

                <option value="9">9 (Beautiful)</option>
                <option value="10">10 (Mesmorizing)</option>
              </select>
                <input name="MusicID" type="hidden" id="MusicID" value="6651" readonly="readonly" />
              <input name="User" type="hidden" id="User" value="" />
  <input type="submit" name="Submit" id="Submit" value="Vote" />
  <input type="hidden" name="MM_update" value="form5" />
              </p>       
          </form>';
} else {
  echo "<a href='loginscript.php'>You must login to vote</a>";
}

?>
</td>

Link to comment
Share on other sites

Oh k, cool, well i'll leave it for now. Ill check on them later. Also, your code had this line,

 

                <input name="MusicID" type="hidden" id="MusicID" value="6651" readonly="readonly" />

 

But i need the value to be this:

 

<?php echo $row_MusicBody['ID']; ?>

 

But when I put it back in a get this error

 

http://www.what-song.com/movie/titletest2.php?Title=Hangover,%20The

 

Do you know what is happening?

Link to comment
Share on other sites

i copied your html source so im guessing you are calling php compiler twice.

 

try:


$outputStuff = "<everything before that input>";
$outputStuff .= "<input name='MusicID' type='hidden' id='MusicID' value='" . $row_MusicBody['ID'] . " readonly='readonly' />";
$outputStuff .= "<everthing after>";

echo $outputStuff;

 

also that input should be a class since there is more than one on the page

Link to comment
Share on other sites

Ahhh, i cant figure this out. I dont understand. haha.

 

Should all that code be red? Doesn't that mean something is wrong?

 

Your first code worked? How do I get it to work but with this value instead of your '6651'?

 

<?php echo $row_MusicBody['ID']; ?>

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.