在我的项目中,当按下阅读按钮时,文件的内容应该被加载到文本区域,然后用户将对该文本进行更改,然后他们应该通过单击保存按钮保存该文件的更改...问题是我可以将文件打开到textarea但是无法保存它。请看看我的代码并回答我
这是我的代码:
netcodetesting.php
<html>
<head>
<link rel="Stylesheet" type="text/css" href="styleee.css" />
<script src="basicbutton.js"></script>
</head>
<body>
<?php
include('insert.php');
$con=mysqli_connect("localhost","abcde","dfdfdfdfdfd","mysql");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$username = mysqli_real_escape_string($con, $_POST['username']);
$password = mysqli_real_escape_string($con, $_POST['password']);
$email = mysqli_real_escape_string($con, $_POST['email_address']);
$r= mysqli_query($con,"SELECT * FROM o_assignment where email_address='$email'");
$row = mysqli_fetch_array($r);
$filename = mysqli_real_escape_string($con, $row['home_directory']);
$file= "$filename";
if(isset($_POST['text1'])){
$file_open = fopen($file,"a+");
fwrite($file_open, $_POST['text1']);
fclose($file_open);
mysqli_close($con);
}
?>
<form name="form1" action="<?=$PHP_SELF?>" method ="POST" >
<button title="bold" onclick="mod_selection('\\bf{','}')" type="button"><b>B</b></button>
<button title="italic" onclick="mod_selection('\\it{','}')" type="button"><i>I</i></button>
<button title="underline" onclick="mod_selection('\\ul{','}')" type="button"><u>U</u></button>
<button title="subscript" onclick="mod_selection('\sub{','}')" type="button"><sub>subscript</sub></button>
<button title="subscript" onclick="mod_selection('\sup{','}')" type="button"><sup>supscript</sup></button>
<button title="undo" onmousedown="undo(document.form1.text1);" type="button">undo</button>
<button title="redo" onmousedown="redo(document.form1.text1);" type="button">redo</button>
<input type="button" value="Clear" onclick="eraseText('my_text');">
<input type="button" value="read" onclick="clientSideInclude('my_text','<?php echo openingfile(); ?>')"/>
<input type="submit" value="save"/>
</br> <textarea class="text_edit" name="text1" id="my_text" onkeydown="countclik(document.form1.text1);" ></textarea></br></form>
</body>
</html>
insert.php
<?php
function openingfile(){
$con=mysqli_connect("localhost","abcde","dfdfdfdfdfd","mysql");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$username = mysqli_real_escape_string($con, $_POST['username']);
$password = mysqli_real_escape_string($con, $_POST['password']);
$email = mysqli_real_escape_string($con, $_POST['email_address']);
$r= mysqli_query($con,"SELECT * FROM o_assignment where email_address='$email'");
$row = mysqli_fetch_array($r);
$filename = mysqli_real_escape_string($con, $row['home_directory']);
$file= "$filename";
echo $file;
mysqli_close($con);
}
?>
的login.html
<html>
<body>
<form action="netcodetesting.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>
</body>
</html>
basicbutton.js
function clientSideInclude(id, url) {
var req = false;
// For Safari, Firefox, and other non-MS browsers
if (window.XMLHttpRequest) {
try {
req = new XMLHttpRequest();
}
catch (e) {
req = false;
}
}
else if (window.ActiveXObject) {
// For Internet Explorer on Windows
try {
req = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
req = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
req = false;
}
}
}
var element = document.getElementById(id);
var str = "";
if (!element) {
alert("Bad id " + id +
"passed to clientSideInclude." +
"You need a div or span element " +
"with this id in your page.");
return;
}
if (req) {
// Synchronous request, wait till we have it all
req.open('GET', url, false);
req.send(null);
str = req.responseText;
str=str.replace(/\\'/g,"'");
str=str.replace(/\\'/g,"'");
str=str.replace(/\\"/g,'"');
str=str.replace(/\\\\/g,'\\');
str=str.replace(/\\0/g,'\0');
element.innerHTML = str;
} else {
element.innerHTML =
" -- ";
}
我的代码中出现了什么错误?为什么文件在更改后没有保存?