【发布时间】:2015-06-23 09:00:16
【问题描述】:
客户将填写一份表格并输入他们希望将 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>
我想创建一个名为 path 的变量。目前,我可以将文本输入到 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);
?>
【问题讨论】: