Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jun 2002
    Location
    hamilton,ontario
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Arrow function to addslashes to each input from a form help

    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
    PHP Code:
    function cleanupinput($form_vars)
    {
    foreach (
    $form_vars as $key => $value)
            {
                
    addslashes($value);
            }

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

    PHP Code:
    cleanupinput($_POST); 
    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.
    whittys.com
    Nomsane?
    That is all

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    function &cleanupinput($form_vars)
    {
    foreach ..........
    {
    // strip_tags / trim / addslashes
    }
    return $form_vars;
    }


    $clean_post = &cleanupinput($_POST);
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.

  • #3
    New Coder
    Join Date
    Jun 2002
    Location
    hamilton,ontario
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    whittys.com
    Nomsane?
    That is all

  • #4
    New Coder
    Join Date
    Jun 2002
    Location
    hamilton,ontario
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Any takers?
    whittys.com
    Nomsane?
    That is all

  • #5
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,095
    Thanks
    11
    Thanked 101 Times in 99 Posts
    this would keep $_POST intact if you already have code utilising it?

    PHP Code:
    <?
    $_POST
    ['test']="hel'lo'a";
    $_POST['test2']="h'el'lo'a";

    function 
    slasher(&$k){
        
    $k=addslashes($k);
    }

    $rets=array_walk($_POST,slasher);

    //test output//
    print_r($_POST);
    ?>
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #6
    New Coder
    Join Date
    Jun 2002
    Location
    hamilton,ontario
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    whittys.com
    Nomsane?
    That is all


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •