onthespot Posted July 11, 2009 Share Posted July 11, 2009 Ok so i have a form that when processed has action ="". Therefore it is coming back to the same page. The code: <?php $user=$_POST['awarduser']; $comment=$_POST['awardcomment']; $type=$_POST['awardtype']; $query="INSERT INTO ".TBL_AWARDS." VALUES (NULL, '$type','$user', now(), '$comment')"; if(!$comment || strlen($comment = trim($comment)) == 0) echo "Comment not entered"; else if(!$comment || strlen($comment = trim($comment)) < 10) echo "Comment too short, must be 10 characters at least"; else if (!$comment || strlen($comment = trim($comment)) > 10){ echo "".$_SESSION['username'].", you have added an award to ".$_POST['awarduser']."'s Profile. "; mysql_query($query);} ?> <h4>Award player</h4> <form action="" method="POST"> Type:<select name="awardtype"> <option value="league1">League winner</option> <option value="league2">League runner up</option> <option value="league3">Leauge 3rd/play off winner</option> </select> Award: <select name="awarduser"> <?php $res=mysql_query("SELECT username FROM ".TBL_USERS."") or die(mysql_error()); while($row=mysql_fetch_assoc($res)){ $username=htmlspecialchars($row['username']); echo "<option value=\"$username\">$username</option>"; } ?> </select> Comment:<textarea name="awardcomment" rows="2" cols="30" ></textarea> <div align="right"><input type="submit" name="submit" value="Award Player"></div> </form> The problem is, the comment not entered comes up as soon as i load the page, as there is no comment entered. Whats the best way around this that enables the form and processing to be done on the same page? thanks Quote Link to comment https://forums.phpfreaks.com/topic/165616-solved-really-dont-know-the-subject-of-this/ Share on other sites More sharing options...
Alex Posted July 11, 2009 Share Posted July 11, 2009 Use isset() to check if the form has been submitted. eg. if(isset($_POST['submit'])) { //Do whatever.. } Quote Link to comment https://forums.phpfreaks.com/topic/165616-solved-really-dont-know-the-subject-of-this/#findComment-873570 Share on other sites More sharing options...
ignace Posted July 11, 2009 Share Posted July 11, 2009 Validate first that their was actually something submitted: if (!empty($_POST)) { // processing logic } Quote Link to comment https://forums.phpfreaks.com/topic/165616-solved-really-dont-know-the-subject-of-this/#findComment-873572 Share on other sites More sharing options...
wildteen88 Posted July 11, 2009 Share Posted July 11, 2009 Not understanding what you said here The problem is, the comment not entered comes up as soon as i load the page, as there is no comment entered. Also please wrap your code in tags rather than quote tags Quote Link to comment https://forums.phpfreaks.com/topic/165616-solved-really-dont-know-the-subject-of-this/#findComment-873573 Share on other sites More sharing options...
onthespot Posted July 11, 2009 Author Share Posted July 11, 2009 Could someone help with where to put that in? I have tried entering it but cant get it working Quote Link to comment https://forums.phpfreaks.com/topic/165616-solved-really-dont-know-the-subject-of-this/#findComment-873588 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.