Jump to content

Help with stripslashes_deep


plastik77

Recommended Posts

I'm having a bit of a problem when trying to use stripslashes or stripslashes_deep to process form data. I was previously using a standard stripslashes function to strip $_POST arrays, however it turned out this was causing an error when i wanted to process multi dimensional arrays, so I removed the function temporarily. However, I now need to fix the issue as data being posted to my database is not posting properly - i.e St Columba's is cutting off at the apostrophe. To try and rectify this, I used the stripslashes_deep function, but this is still not sorting out my problem. Can anyone help?

 

The stripslashes_deep function is as follows:

function stripslashes_deep($value)
{
    $value = is_array($value) ?
                array_map('stripslashes_deep', $value) :
                stripslashes($value);

    return $value;
}

When I process the multi-dimensional array of posted form data, the code is as follows:

//if a new fixture has been submitted
if(isset($_POST['submit_this_weeks'])) {

$count = count($_POST);
$_POST = stripslashes_deep($_POST);

for ($i=0; $i< $count; $i++){    

	$id = (int) $_POST['id'][$i]; 
	$date = mysql_real_escape_string($_POST['date'][$i]); 

	//process row as long as a date has been submitted
	if ($date!="") {

		$team = mysql_real_escape_string($_POST['team'][$i]);  
		$opposition = mysql_real_escape_string($_POST['opposition'][$i]);  
		$venue = mysql_real_escape_string($_POST['venue'][$i]);  
		$kick_off = mysql_real_escape_string($_POST['kick_off'][$i]);  
		$arrangements = mysql_real_escape_string($_POST['arrangements'][$i]);  
		$sport_id = $_POST['sport_id'][$i];
		$ref = getenv('HTTP_REFERER');

		$validator->validateDate($date,'Date');
		$validator->validateGeneral($opposition,'Opposition');
		$validator->validateGeneral($venue,'Venue');

		// Check whether the validator found any problems
		if ($validator->foundErrors()){
			$error = "<h5 class='error'>Error! There was a problem with the following field(s): <br/>-".$validator->listErrors('<br/>-')."</h5>"; // Show the errors, with a line between each
		}
		else {	
			//Use mysql_real_escape_string to escape special characters in a string for use in a SQL statement - makes statement safe
			$insertQuery = sprintf("INSERT INTO this_weeks_fixtures (date, team, opposition, venue, kick_off, arrangements, sport_id, creator) VALUES ('%s', '%s','%s','%s','%s', '%s', %d, %d)",
			$date,           
			$team,
			$opposition,
			$venue,
			$kick_off,
			$arrangements,
			$sport_id,
			$_SESSION['user_id']);  
			// Save the form data into the database
			if (!$result = $connector->query($insertQuery)){
				// It hasn't worked so stop. 
				$message = "<h5>Sorry, there was an error saving to the database</h5>";
				break;

			}
			else {
				$message = "<h4>Fixtures successfully added</h4>";

			}
		}
	}
}
}

Link to comment
Share on other sites

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.