从数据库获取文件路径。我将文件路径存储到变量中,但是当我尝试将该变量解析为fopen函数时,它会抛出一个错误,说明文件名不能为空。
的login.html
<form action="a.php" method="POST">
Username: <input type="text" name="username"></br>
Password: <input type="text" name="password"></br>
Email-Address: <input type="text" name="email_address"></br>
<input type="submit">
</form>
a.php只会
$con=mysqli_connect("localhost","abc","abc","mysql");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$username= $_POST['username'];
$password= $_POST['password'];
$email= $_POST['email_address'];
$r= mysqli_query($con,"SELECT * FROM Assignment where email_address='$email'");
$row = mysqli_fetch_array($r);
$filename = mysqli_real_escape_string($con, $row['home_directory']);
if(isset($_POST['text1'])){
$file_open = fopen($filename,"w+");
fwrite($file_open, $_POST['text1']);
fclose($file_open);
}
?>
<form action="" method="POST">
<textarea class="text_edit" name="text1" id="my_text" ></textarea></br>
<input type="submit" name="button">
</form>
我想知道这里的错误是什么。为什么fopen不能使用数据库中的retreived文件路径
答案 0 :(得分:0)
使用var_dump函数检查$ filename是否为空。试试这段代码:
$filename = $row['home_directory'];
var_dump($filename);