Jump to content

Unable to add some logic to support system of site


r3wt

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("[email protected]","",$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("[email protected]","",$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? 

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("[email protected]","",$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.

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.