客户将填写表格并输入他们希望将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打印在数据库中),但不是输入到表单中的正确文本(即$途径)。 我想创建一个变量,因为在数据库中保存路径之后我还想在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);
?>
答案 0 :(得分:1)
如果不是这样,请检查您的用户名和密码......
<?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);
?>
答案 1 :(得分:0)
您的数据库用户名为var input = document.getElementById('id');
将Null
更改为$username = "";
答案 2 :(得分:0)
您的输入字段名称是用户名
将pathway
更改为$_POST['pathway']
才能正常工作
<form action="register.php" method="post">
Enter file pathway where CSV will be saved:
<input type="text" name="pathway" required="required"/> <br/>
<input type="submit" value="Enter"/>
</form>
答案 3 :(得分:0)
首先,您已获得用户名&#39;作为用于输入路径的字段的名称,因此将其重命名为&#39;途径&#39;。 我不知道我是否了解你,但你只是想阅读发布的内容吗? 尝试类似:
$pathway = $_POST['pathway']
我强烈建议使用面向对象的样式
$conn = new mysqli...
然后
mysqli->prepare(), mysqli->bind_param(), mysqli->execute()
有了这个,你不必处理mysqli_real_escape_string等。