简体   繁体   English

输入框值将保存到mysql数据库

[英]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: 这是一个正在运行的代码...我想知道什么代码可以通过使用以下代码将每个文本框的值放入mysql数据库mybe中:

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

but how... 但是怎么...

Add this line in your generate.php. 在您的generate.php中添加这一行。 You will be able to get the value of the textboxs along with the id of the textbox in a string. 您将能够在字符串中获取文本框的值以及文本框的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

?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM