imperium2335
imperium2335

Reputation: 24122

Good way to process field data into mysql database

What is the most efficient way to get input, select and textarea values into my database?

Would giving all the fields ids that correspond to that of the columns in the tables the values are going to be placed in?

This is what I normally do, but can't help feeling that there must be a more efficient way:

function saveAll() {
    var postString = '' ;
    $('#manageCustomerDialog select option:selected, #manageCustomerDialog input').each(function(){
        currentField = $(this).attr('id') ;
        if(!currentField)
        {
            currentField = $(this).parent().attr('id') ;
        }
        currentVal = encodeURIComponent($(this).val()) ;
        postString += '&'+currentField+'='+currentVal ;
    })

    simpleJAX(CONTROLER, 'mode=SAVE_DATA'+postString, function(data){
        alert('Saved!') ;
    })
}​

CONTROLER is the url of the PHP file.

I would then translate the $_POST data in the PHP file to get the values into the columns.


Not sure I understand. Do you mean create a hidden form input with the SQL query as the value and passing that instead?

Upvotes: 0

Views: 95

Answers (1)

Mic1780
Mic1780

Reputation: 1794

Start off by creating the query inside of a variable with other variables inside it representing a query string or $_REQUEST vars. That way, you can assign all vars before you create the query string. It will be more legible and it works! =))

Upvotes: 1

Related Questions