gpt4 book ai didi

php - 使用php将数据输入mysql数据库

转载 作者:行者123 更新时间:2023-11-29 12:09:05 25 4
gpt4 key购买 nike

客户将填写表格并输入他们希望将 CSV 导出到的路径。使用 php 的顶部部分输入路径(如下):

    <form action="register.php" method="post">
Enter file pathway where CSV will be saved: <input type="text" name="username" required="required"/> <br/>
<input type="submit" value="Enter"/>
</form>
</body>

我想创建一个名为pathway的变量。目前,我可以将文本输入到 mysql 数据库中的正确行中(我可以在数据库中打印 John),但不能将文本输入到表单中(即 $pathway)。我想创建一个变量,因为在数据库中保存路径后,我还想在 export.php 中使用它。

我假设我也需要这样的东西:

if($_SERVER["REQUEST_METHOD"] == "POST"){
$pathway = mysql_real_escape_string($_POST['pathway']);
// but i can't seem to piece it altogether.


<?php
$servername = "localhost";
$username = "";
$password = "";
$dbname = "first_db";
$table_users = $row['pathway'];
$pathway = "pathway";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}

$sql = "INSERT INTO users (pathway)
VALUES ('John')";

if (mysqli_query($conn, $sql)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}

mysqli_close($conn);
?>

最佳答案

这应该有效,如果不行,请检查您的用户名和密码...

<?php
$servername = "localhost";
$username = "";
$password = "";
$dbname = "first_db";
$pathway = $_POST['username']; username - is the name of your input.

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn)
{
die("Connection failed: " . mysqli_connect_error());
}

$sql = "INSERT INTO users (pathway)
VALUES ('$pathway')";

if (mysqli_query($conn, $sql)) {
echo "New record created successfully";
}
else
{
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}

mysqli_close($conn);
?>

关于php - 使用php将数据输入mysql数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30998304/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com