私Answere @ RandD-SexyBoy-。クエリは、彼が出てVALUES (:nameID_column)
と$sql = "INSERT INTO $tables[$i](nameID_column);
を使用していRandD-SexyBoy- @異なっている私のSQLは、ここで$sql->prepare("INSERT INTO ".$v." (name_id) VALUES (?)"
を使用しているされた3例では、ユーザが最初に
場合に応答します:ユーザーは、単一のテーブル
を選択することができ
大文字小文字の区別:ユーザーは複数の表を選択できます。ここでは、ループと動的SQLクエリforeach()
を使用する必要があります。第
場合:
`
<html>
<head>
</head>
<body>
<form action="" method="post">
<input type="text" name="name_id" required>
<p>select your table to add data</p>
<input type="checkbox" name="tables[]" value="tblA">Table A<br>
<input type="checkbox" name="tables[]" value="tblB">Table B<br>
<input type="checkbox" name="tables[]" value="tblC">Table C<br>
<input type="checkbox" name="tables[]" value="tblD">Table D<br>
<input type="checkbox" name="tables[]" value="tblE">Table E<br>
<input type="submit" name="submit">
</form>
</body>
</html>
`
PHPファイル:ユーザーは、この場合、任意のテーブルを選択しないことがあり、我々は、ユーザにメッセージtable not selected
HTMLフォームを与えなければなりません
<?php
$con = new mysqli('localhost','root','admin','demo');
if(!$con){
die("Connection ".$con->connect_error);
}
if(isset($_POST['submit'])){
$name_id = $_POST['name_id'];
$tables = $_POST['tables'];
if(!empty($tables)){
foreach($tables as $key=>$v){
$sql = $con->stmt_init();
if($sql->prepare("INSERT INTO ".$v." (name_id) VALUES (?)")){
$sql->bind_param($name_id);
$sql->execute();
echo "DATA INSERTED";
}
else
{
echo "Error".$con->error;
}
}
}
else
{
echo "You have not selected tables";
}
}
?>
1ではなく5つのテーブルがあるのはなぜですか? – Strawberry