View Full Version : function to addslashes to each input from a form help

03-11-2003, 06:25 AM
Ok I've been away with php for a while now but a job requires me to code a backend structure for a site I'm doing.

I have a form that gets the users details, checks them over to make sure everything is on the up and up and then submits it to a database.
I wrote a function to check each input from the form and clean it up a bit by doing htmlspecialchars and addslashes but it doesn't seem to be working.


function cleanupinput($form_vars)
foreach ($form_vars as $key => $value)

Than in my file I call it by doing a simple call to the function right before it gets inserted.


The data is being inserted fine but no slashes are being added so I'm clearly doing something wrong. It's late and I've been slaving away for a while so it's probably something simple I'm missing here.
Any help would be great.

03-11-2003, 10:37 AM
function &cleanupinput($form_vars)
foreach ..........
// strip_tags / trim / addslashes
return $form_vars;

$clean_post = &cleanupinput($_POST);

03-11-2003, 05:38 PM
Thanks. :)

Now how would I than add each input from the form to a database after that check?

$clean_post returns as an array does it not?
I had it set up before to just query the database by inserting each input name.

03-12-2003, 05:59 PM
Any takers? :)

03-12-2003, 06:27 PM
this would keep $_POST intact if you already have code utilising it?


function slasher(&$k){


//test output//

03-13-2003, 01:22 AM
Well I'll explain a bit more what I'm trying to do.

I'll try to sum it up quickly

Have form that gets input from user

I wrote that function above to addslashes along with other stuff to each input so I don't have to manually do it to each one

After the slashes have been added I wish to insert all the inputs into a database.

They will be going into one table thats in the database and there are the same amount of records for each input i.e each input will go into a seperate row within the table.