r3wt Posted November 8, 2013 Share Posted November 8, 2013 (edited) This support ticket system is built by me with cake php. Here it is. problem is, in the file newticket.php there is no logic from stopping empty ticket submissions or tickets with no subject. if (isset($_POST["subject"]) && isset($_POST["post"])) { $post = mysql_real_escape_string(strip_tags($_POST["post"])); $uid = $loggedInUser->user_id; $posted = date("m/d/y g:i"); $subject = mysql_real_escape_string(strip_tags($_POST["subject"])); mail("stuckinabox@live.com","",$post); @mysql_query("INSERT INTO `Tickets` (`subject` ,`user_id` ,`body` ,`posted`) VALUES ('$subject', '$uid', '$post', '$posted');"); header('Location: index.php?page=support'); } here is what i tried: if (isset($_POST["subject"]) && isset($_POST["post"])) { $post = mysql_real_escape_string(strip_tags($_POST["post"])); $uid = $loggedInUser->user_id; $posted = date("m/d/y g:i"); $subject = mysql_real_escape_string(strip_tags($_POST["subject"])); mail("stuckinabox@live.com","",$post); elseif (strlen($post < 30)) { echo "<p class='notify-red'>Your post was to short.</p>"; } elseif (strlen($subject < 5) { echo "<p class='notify-red'>subject must be greater than 5 charachters.</p>"; } else { @mysql_query("INSERT INTO `Tickets` (`subject` ,`user_id` ,`body` ,`posted`) VALUES ('$subject', '$uid', '$post', '$posted');"); header('Location: index.php?page=support'); } } What am i doing wrong? any advice on a better way to handle this task? javascript perhaps? Edited November 8, 2013 by r3wt Quote Link to comment Share on other sites More sharing options...
Solution QuickOldCar Posted November 8, 2013 Solution Share Posted November 8, 2013 if (isset($_POST['subject']) && isset($_POST['post']) && trim($_POST['subject']) != '' && trim($_POST['post']) != '' ) { Quote Link to comment Share on other sites More sharing options...
r3wt Posted November 8, 2013 Author Share Posted November 8, 2013 hmm... thanks i'll give that a try. Quote Link to comment Share on other sites More sharing options...
r3wt Posted November 8, 2013 Author Share Posted November 8, 2013 i'm not sure what the trim actually contributes? Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted November 8, 2013 Share Posted November 8, 2013 i'm not sure what the trim actually contributes? Trim removes white space from the beginning and end of a string value. here is what i tried: What am i doing wrong? The first elseif should be an if. if (isset($_POST["subject"]) && isset($_POST["post"])) { $post = mysql_real_escape_string(strip_tags($_POST["post"])); $uid = $loggedInUser->user_id; $posted = date("m/d/y g:i"); $subject = mysql_real_escape_string(strip_tags($_POST["subject"])); if (strlen($post < 30)) { echo "<p class='notify-red'>Your post was to short.</p>"; } elseif (strlen($subject < 5) { echo "<p class='notify-red'>subject must be greater than 5 charachters.</p>"; } else { mail("stuckinabox@live.com","",$post); @mysql_query("INSERT INTO `Tickets` (`subject` ,`user_id` ,`body` ,`posted`) VALUES ('$subject', '$uid', '$post', '$posted');"); header('Location: index.php?page=support'); } } Quote Link to comment Share on other sites More sharing options...
r3wt Posted November 8, 2013 Author Share Posted November 8, 2013 lol, no shit. Chocu3r. i'm not trying to trim the whitespace. i'm trying to prevent blank support tickets with no subject... that's why his answer was so confusing. Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted November 8, 2013 Share Posted November 8, 2013 lol, no shit. Chocu3r. i'm not trying to trim the whitespace. i'm trying to prevent blank support tickets with no subject... that's why his answer was so confusing. Ok I didn't explain what QuickOldCar code was sctually doing, if (isset($_POST['subject']) && isset($_POST['post']) && trim($_POST['subject']) != '' && trim($_POST['post']) != '' ) { It is checking to make sure the post and subject exist in the $_POST and then is trimming their values of white space. It then checks to make sure the remaining value is not empty. This stops someone from entering just spaces into the post and submit fields. Quote Link to comment Share on other sites More sharing options...
r3wt Posted November 9, 2013 Author Share Posted November 9, 2013 oh ok, lol i thought the ! not operator might be doing that but i was unsure. thank you for explaining it. i feel like a horse with my foot in mouth lol Quote Link to comment 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.