Form to send the name for the table to create
<script>
$(document).ready(function () {
$('#cdbt').click(function (e) {
e.preventDefault();
$.post("insert.php",
{ input_value : $("#myInput").val()},
function(data) {
$('#response').html(data);
console.log("Success");
});
});
});
</script>
<form action="" id= "cdbt" method="post">
<input type="text" id="myInput" placeholder="Title...">
<input type="submit" name="submit">
</form>
insert.php
$value = $_POST['input_value'];
$sql1 = "CREATE TABLE $value";
Create database Table by user input value in php
You have to attach submit event on form:
$(document).ready(function () {
$('#cdbt').submit(function (e) {
e.preventDefault();
$.post("insert.php",
{ input_value : $("#myInput").val()},
function(data) {
$('#response').html(data);
console.log("Success");
});
});
});
Your code is vulnerable to SQL injection you should escape values like:
$value = mysqli_real_escape_string($con,$_POST['input_value'])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.