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

Yer sure.

 

http://www.what-song.com/movie/titletest2.php?Title=Moon

 

Even when your not logged in, your vote still registers. I need it so when someone who is not logged in votes. It says, you are not logged in, and the vote does not get updated.

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>

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?

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

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']; ?>

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.