<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>
这是一个正在运行的代码......我想知道什么代码可以将每个文本框的值放到mysql数据库中 mybe使用这个:
$sql = "UPDATE `sampledb` SET `text1` = 'anyvaluethatuserinputs' && `text2` = 'anyvaluethatuserinputs' && `text3` = 'anyvaluethatuserinputs'";
但是如何...
答案 0 :(得分:1)
在generate.php中添加此行。您将能够在字符串中获取文本框的值以及文本框的ID。
<?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
?>