我正在为学校做一个项目。 这是一个发票计划,但我卡住了,任何人都可以帮助我 弄清楚如何从多个文本框/字段中获取值 并将它们插入我的数据库。 这就是它的样子。 用户可以选择将插入数据库的文本字段数量。
答案 0 :(得分:0)
简单的例子:
<?php
$host=''; //define host
$user='xxx'; //define username
$pass='xxx'; //define password
$db_name='xxx'; //define db name
$db = new mysqli($host, $user, $pass, $db_name);
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
if(isset($_POST['status'])) { //code called when user sent form
$status = mysqli_escape_string($db, ($_POST['status']));
//same way to save other fields, just rename "status" to your value
$sql = "INSERT INTO /* table name here */ (status, /* define other line in DB here */) VALUES ('$status', /* define other variables to save here */)"; //save into database, see the example below
//example: $sql = "INSERT INTO mydatabase (status, email, name) VALUES ('$status', '$email', '$name')";
if ($db->query($sql) === TRUE) {
echo "Saved.";
}
else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
?>
<form enctype="multipart/form-data" action="<?php $_PHP_SELF ?>" method="POST">
<label for="status">Status: </label>
<input id="status" name="status" value="" />
//add other fields here, just rename "status" to your value
<input type="submit" name="submit" value="Send form" /></form>
这可能就是你要找的东西,只是自己调整一下。