$value = $_POST['directions'];
$value2 = $_POST['inventory'];
$value3 = $_POST['item'];
$value4 = $_POST['vendor'];
$sql = "INSERT INTO a1 (directions,inventory,item,vendor) VALUE ('$value','$value2','$value3','$value4')";
现在我正在通过单独页面中的教科书输入来更新mysql数据库。然而,如果它说“INSERT INTO a1”id就像使“a1”成为像“$ table”这样的变量我从同一页面定义我输入
中的所有其他值答案 0 :(得分:0)
这个问题需要更清楚,但根据我的理解,你可以使用类似这样的代码:
// should be defined like this inside each page.
$table = mysql_real_escape_string($_POST['tablename']);
$params = array();
foreach($_POST as $key => $val){
if($key!='tablename'){
$params[]= "$key='".mysql_real_escape_string($val)."'";
}
}
if(count($params) > 0) {
$params = implode(",",$params);
$sql = "INSERT INTO $table SET $params";
} else {
die "Error submitting the data!";
}