tmworking Posted August 5, 2009 Share Posted August 5, 2009 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? Link to comment https://forums.phpfreaks.com/topic/169011-solved-new-users-on-submit-form-help-please/ Share on other sites More sharing options...
machiavelli1079 Posted August 5, 2009 Share Posted August 5, 2009 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"; } Link to comment https://forums.phpfreaks.com/topic/169011-solved-new-users-on-submit-form-help-please/#findComment-891723 Share on other sites More sharing options...
tmworking Posted August 26, 2009 Author Share Posted August 26, 2009 Thanks, This really helped! Link to comment https://forums.phpfreaks.com/topic/169011-solved-new-users-on-submit-form-help-please/#findComment-907131 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.