-1
首先,我看到有關此主題的其他帖子,並在創建我的代碼時考慮了這些帖子,但這不起作用,這意味着javascript或php沒有錯誤,但是文本沒有被傳輸或上傳到數據庫。這是我的代碼。謝謝,因爲這是我第一次使用這個論壇,請告訴我,如果我做錯了什麼。如何使用Javascript將contenteditable傳遞給表格
CODE:
<!DOCTYPE html>
<html>
<head>
<script>
function myFunction()
{
alert("Changes Saved");
}
function getContent()
{
document.getElementById("tdescription").value = document.getElementById("description").innerHTML;
document.getElementById("tcomments").value = document.getElementById("comments").innerHTML;
document.getElementById("tannouncements").value = document.getElementById("announcements").innerHTML;
return true;
}
</script>
</head>
<body>
<?php session_start(); ?>
<?php include("pageview.php"); ?>
<?php
if($edit == 1)
{
echo "<div class='heading' style = 'width:70%;border-radius:10px;margin-top:5px;margin-left:auto;margin-right:auto;'><h3>Announcements</h3> <form name = 'form' action = 'edit_class.php' method = 'POST' onsubmit='return getContent()'><textarea style='display:none;' id = 'tannouncements' name = 'tannouncements'></textarea><p contenteditable = 'true' class = 'content' spellcheck = 'true' id = 'announcements'>";
echo $announcement;
echo " </p></div><div class='heading' style = 'width:70%;border-radius:10px;margin-top:5px;margin-left:auto;margin-right:auto;'><h3>Description</h3> <textarea style='display:none;' name = 'tdescription' name = 'tdescription'></textarea><p contenteditable = 'true' class = 'content' spellcheck = 'true' id = 'description'>";
echo $description;
echo "</p></div><div class='heading' style = 'width:70%;border-radius:10px;margin-top:5px;margin-left:auto;margin-right:auto;'><h3>Comments</h3><textarea style='display:none;' id = 'tcomments' name = 'tcomments'></textarea><p contenteditable = 'true' class = 'content' spellcheck = 'true' id = 'comments'>";
echo $comments;
echo "</p></div> <br> <input type = 'submit' value = 'Save Changes'> </form>";
echo "<br><h3>Upload Images</h3><form name = 'file_upload' action = 'upload.php' enctype='multipart/form-data' method = 'POST'> Choose Image File: <input type = 'file' name = 'upload' style = 'font-size:14pt;'><br><br><input type = 'submit' name = 'upload_button' value = 'Upload Image'></form><br>";
$_SESSION['temp'] = $class;
}
else
{
echo "<div class='heading' style = 'width:70%;border-radius:10px;margin-top:5px;margin-left:auto;margin-right:auto;'> <h3>Announcements</h3> <p>";
echo $announcement;
echo "</p></div><div class='heading' style = 'width:70%;border-radius:10px;margin-top:5px;margin-left:auto;margin-right:auto;'> <h3>Description</h3> <p>";
echo $description;
echo "</p></div><div class='heading' style = 'width:70%;border-radius:10px;margin-top:5px;margin-left:auto;margin-right:auto;'><h3>Comments</h3><p>";
echo $comments;
echo "</p></div>";
}
?>
</body>
</html>
PHP數據庫:
<?php
session_start();
$con = new mysqli(x,x,x,x);
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$a = $_POST['tannouncements'];
$d = $_POST['tdescription'];
$c = $_POST['tcomments'];
$y = $_SESSION['temp'];
$stmt = $con->prepare("UPDATE Class_data SET announcements = ?, description = ?, comments = ? WHERE class_year = ?");
$stmt->bind_param("ssss", $a, $d, $c, $y);
mysqli_error($con);
$stmt->execute();
$stmt->close();
$header = "Location:classpage.php?class=" .$y. "";
mysqli_close($con);
header($header);
}
?>
抱歉代碼的長度... –
沒有什麼在此代碼,涉及到數據庫。 –
哦,對不起...讓我編輯一下... –