这是一行代码,如果没有SESSION,文本区域应为空白。如果有SESSION,请将内容放入textarea。这里真的有错误,还是仅仅是虚拟主机的问题?
<form id="translateform" action="processTranslation.php" method="post"><?php
echo "<textarea maxlength='3000' id='inputField' placeholder='Enter your Lorem Ipsum text here:' name='translate'>";
if(isset($_SESSION['text'])){
echo $_SESSION['text'];
}
echo "</textarea>";
?>
错误消息:&#34; Uncaught SyntaxError:Unexpected Identifier&#34;。这几乎是整个代码:
<form id="translateform" action="process.php" method="post"><?php
if(!empty($_SESSION['text'])){
echo "<textarea maxlength='3000' id='inputField' placeholder='Enter your Lorem Ipsum text here:' name='translate'>" . $_SESSION['text'] . "</textarea>";
}
else{
echo "<textarea maxlength='3000' id='inputField' placeholder='Enter your Lorem Ipsum text here:' name='translate'></textarea>";
}
?>
<input type="submit" name="submit" id="submit" value="Submit!">
</form>
<a href="projects.html"><div id="back"><p id="goback">Back!</p></div></a>
<script>
if(document.referrer=="msolonko.net16.net/projects.html"){
document.cookie="navigatedFromSite=agreed";
}
else if(document.referrer!="msolonko.net16.net/projects.html"&&document.referrer!="msolonko.net16.net/LoremIpsum.php"){
document.cookie = "navigatedFromSite="no";
}
var x=document.cookie;
if(x.search("navigatedFromSite")!=-1&&x.search("agreed")!=-1){
document.getElementById("back").style.display="initial";
}
</script>
<?php
echo "<div id='containertranslation'><p id='translation'>";
if(isset($_SESSION['translation'])){echo $_SESSION['translation'];}//if translated
else{echo "Translation: ";}//if not, empty field
echo "</p></div>";//adds div with translation
?>
如您所见,我设置cookie以查看用户导航的页面。如果是来自网站,则应显示后退按钮。这适用于cloud9,但不在此托管中。以下是错误消息: 这是第109行:
echo "<textarea maxlength='3000' id='inputField' placeholder='Enter your Lorem Ipsum text here:' name='translate'></textarea>";
这是第119行:
else if(document.referrer!="msolonko.net16.net/projects.html"&&document.referrer!="msolonko.net16.net/LoremIpsum.php"){
答案 0 :(得分:0)
使用empty($_SESSION)
代替isset($_SESSION)
检查$_SESSION
变量是否为空。
// checks if the variable is empty or not
if (!empty($_SESSION['text'])) {
// display inside <textarea>
echo "<textarea>" . $_SESSION['text'] . "</textarea>";
}