[TLDR] 我想从我的网站托管服务提供的mySQL数据库中输入从每行数据到我网站目录中的单独文件的输出,该文件可以通过物理,打印的二维码 [TLDR]
我想采取一定数量的物理打印QR码(20到30),将它们链接到我网站的文件。 (例如:QR码----> mywebsite.comli.com/file1)并且能够从mySQL数据库向这些多个文件添加信息,并且还具有从这些数据库中删除数据的功能,同时我删除,发送电子邮件到已删除的文件内的电子邮件。
我无法想到一种从数据库中获取数据并将其“放入”每个文件的方法。我可以使用重定向运算符(>,>>)将数据库的输出替换或附加到多个文件中吗?但我总是被困在如何准确地引用每个可能的文件。可以注册。表达发挥作用?
我真的不是一个程序员,所以我不得不从网上来源复制大部分代码。可能有很多基本错误/安全问题,但我想知道我是否可以获得一般工作,然后再解决这些问题。
这是我的mail_handler.php文件的代码,该文件也连接到数据库并打印出echo语句中的内容,但只打印到同一个文件中。
<?php
session_start();
if(isset($_POST['submit'])){
$to = "email@example.com"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$subject = "Form submission";
$subject2 = "Copy of your form submission";
$message = $first_name . " " . $last_name . " wrote the following:" . "\n\n" . $_POST['message'];
$message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message'];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
// You can also use header('Location: thank_you.php'); to redirect to another page.
// You cannot use header and echo together. It's one or the other.
}
$servername = "mywebhost.com";
$username = "username";
$password = "password";
$dbname = "mydb";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
else {
echo "Succcccessssful concection \n\n";
}
// sql to create table
$sql = "CREATE TABLE MyGuests (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAMP
)";
if (mysqli_query($conn, $sql)) {
echo "Table MyGuests created successfully";
} else {
echo "Error creating table: " . mysqli_error($conn);
}
$sql = "INSERT INTO MyGuests (firstname, lastname, email, message)
VALUES ('$first_name', '$last_name', '$from', '$message')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully ";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
// sql for dispplayying info
$sql = "SELECT id, firstname, lastname, email, message FROM MyGuests";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "id:" . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "- email " . $row["email"]. " -message " . $row["message"]. "<br>";
}
} else {
echo "0 results";
}
mysqli_close($conn);
?>
这是我的index.php文件的代码
<!DOCTYPE html>
<head>
<title>Form Plant submission</title>
</head>
<body>
<form action="mail_handler.php" method="post">
First Name: <input type="text" name="first_name"><br>
Last Name: <input type="text" name="last_name"><br>
Email: <input type="text" name="email"><br>
Message:<br><textarea rows="5" name="message" cols="30"></textarea><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>