Jump to content

Unable to add some logic to support system of site


Go to solution Solved by QuickOldCar,

Recommended Posts

 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 by r3wt

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');
	}
}

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.