Jump to content

[SOLVED] New Users on Submit form help please!


tmworking

Recommended Posts

Ok, I've got a script running, that allows users to submit one-liners, but I need to give them the option to add a nickname/moniker instead of just Anonymous if they aren't logged in.

 

Here's the script I've got, but I'm stuck.

<?php


if($_POST['submit']){
if(!isset($_SESSION['user']['username'])) $username = "Anonymous";
else $username = $_SESSION['user']['username'];
@$query = mysql_query("INSERT INTO `comps`(time,message,accepted,votes1,votes2,via,user,cat,numcoms,subcat) VALUES ('". time() ."', '". clean($_POST['comp']) ."', 'No', 0, 0, 'internet', '". $username ."', '". clean($_POST['cat']) ."', '0', '0')") or die(mysql_error());
echo "<strong>Your submission has been received!</strong>
<script type=\"text/javascript\"><!--
setTimeout('Redirect()',1000);
function Redirect()
{
	opener.location.href='./';
window.close();
}
// --></script>";
} else {
echo '
<form action="" method="POST">
<table id="submissionform">
<tr><td class="input" colspan=5>
<textarea onfocus="javascript:document.getElementById(\'commbox\').innerHTML=\'\';" name="comp" rows="13" height="75" cols="20" id="commbox">'. $names[4] .'</textarea>
</td></tr>
<tr><td>
<select name="cat">
';

while($category = current($catlist)){
echo '<option value="'. key($catlist) .'">'. current($catlist) .'</option>';
next($catlist);
}

echo '
</select></td></tr> <tr><td><input type="submit" name="submit" value="Submit!" class="button_login2" />
</td></tr>
</table>
   </form>';

}



?>

 

Anyone able to tell me the next step to make this possible?

 

Hi tmworking,

 

What are you stuck on?  You could do a check when drawing the form to see if the are logged in, and include a field for nickname if they are not logged in.

 

if(!$user->isLoggedIn())
{
  echo '<label for='nickname'>Nickname</label><input type="text" id="nickname" name="nickname">';
}

 

Then, during your $_POST check, if the user is not logged in:

if(isset($_POST['nickname']))
{
  $username=$_POST['nickname'];
}
else
{
  $username="Anonymous";
}

 

  • 3 weeks later...

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.