Robert John Concepcion
Robert John Concepcion

Reputation: 237

input box value will save to mysql database

<SCRIPT LANGUAGE="JavaScript">

var i=0,j=0;

var t1= [];

function add(){

    i++;

    var parent = document.forms[0];

    var div = document.createElement('div');

    var input = document.createElement('input');

    input.type='text';

    input.name='text'+i;

    input.value = "text"+i;

    input.size = 10;

    t1.push(input);

    div.appendChild(input);

    var removeButton = document.createElement("button");

    removeButton.innerHTML = "Remove";

    removeButton.onclick = function(e) {

        this.parentNode.parentNode.removeChild(this.parentNode);
        return(false);

    };

    div.appendChild(removeButton);

    var mybr=document.createElement("br");

    div.appendChild(mybr);

    parent.appendChild(div);

}
</SCRIPT>

<button onclick="add()">+</button>

<form action='generate.php' method='get'>

<input type='submit' name='button' value='save'>

</form>

This is a running code... I wonder what code can put the value of each textbox to a mysql database mybe by the use of this:

$sql = "UPDATE `sampledb` SET  `text1` =  'anyvaluethatuserinputs' && `text2` =  'anyvaluethatuserinputs' && `text3` =  'anyvaluethatuserinputs'";

but how...

Upvotes: 0

Views: 1460

Answers (1)

MD. Sahib Bin Mahboob
MD. Sahib Bin Mahboob

Reputation: 20534

Add this line in your generate.php. You will be able to get the value of the textboxs along with the id of the textbox in a string.

<?php

$sql = "UPDATE `sampledb` SET  ";


if(isset ($_GET))
{

    foreach ($_GET as $key => $value) 
        $sql .= "$key = '$value'  , ";

}

$sql= substr_replace ($sql , '', strlen($sql) -2 , 1);
echo $sql;

    //here establish the connection and pass the $sql as the query

?>

Upvotes: 1

Related Questions