大家下午好。非常感谢你对我上一个问题的回答。这对我真的很有帮助。今天我有另一个问题,从不同的html页面访问我的变量。我想我的表单页面连接到富文本框页面,从那里的内容应适用于表单页面。我试图通过在表单页面中插入'action'来完成,但是富文本框页面显示了未定义的变量。我希望任何人都能帮我说出我的错。提前谢谢。
表单页:
<?php
session_start();
$_SESSION['message'] = '';
$mysqli=new MySQLi('127.0.0.1','root','','accounts');
if($_SERVER["REQUEST_METHOD"] == "POST") {
$option1 = $mysqli->real_escape_string($_POST['option1']);
$option2 = $mysqli->real_escape_string($_POST['option2']);
$option3 = $mysqli->real_escape_string($_POST['option3']);
$option4 = $mysqli->real_escape_string($_POST['option4']);
$option5 = $mysqli->real_escape_string($_POST['option5']);
$option6 = $mysqli->real_escape_string($_POST['option6']);
$sql ="INSERT INTO menubar(option1,option2,option3,option4,option5,option6)"
."VALUES ('$option1','$option4','$option3','$option4','$option5','$option6')";
if($mysqli->query($sql)=== true) {
$_SESSION['message'] = 'Registration successful!
Added $username to the database!';
header("location:confirmnormal.php");
}
else {
$_SESSION['message'] = "User could not be added to the database!";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Normal</title>
</head>
<body>
<form method="post" enctype="multipart/form-data" autocomplete="off">
<table align="center" >
<tr>
<td>
Enter Menu Bar:
</td>
<td>
<input type="text" placeholder="Personal Information" name="option1" />
<tr><td></td><td><input type="text" placeholder="Career Aspirations" name="option2" /></td></tr>
<tr><td></td><td> <input type="text" placeholder="Educational Background" name="option3" required /></td></tr>
<tr><td></td> <td> <input type="text" placeholder="Skills" name="option4" required /></td></tr>
<tr><td></td> <td><input type="text" placeholder="Language Proficiency" name="option5" required /></td></tr>
<tr><td></td><td><input type="text" placeholder="Job Preference" name="option6" required /></td>
</td></tr>
</tr>
</tr>
</form>
</tr>
<div>
<?= $_SESSION['message']?>
<form method="POST" action="richtext.php">
<tr>
<td>
Content
</td>
</tr>
<td>
Content 1 :
</td>
<td>
<a href="richtextbox.php">
<input type="text" placeholder="Resume" name="content1"<?=$_SESSION['content1']?> />
</a>
</td>
<tr>
<td>
Content 2 :
<td>
<a href="richtextbox.php"><? $_SESSION['content2']?>
<input type="text" placeholder="Personal" name="content2" />
</a>
</td>
</td>
</tr>
<tr>
<td>
Content 3 :
<td>
<a href="richtextbox.php"><? $_SESSION['content3']?>
<input type="text" placeholder="Resume" name="content3" />
</a>
</td>
</td>
</tr>
<tr>
<td>
Content 4 :
<td>
<a href="richtextbox.php"><? $_SESSION['content4']?>
<input type="text" placeholder="Personal" name="content4" />
</a>
</td>
</td>
</tr>
<tr>
<td>
Content 5 :
<td>
<a href="richtextbox.php">
<input type="text" placeholder="Resume" name="content5" <?=$_SESSION['content5']?>/>
</a>
</td>
</td>
</tr>
<tr>
<td>
Content 6 :
<td>
<a href="richtextbox.php">
<input type="text" placeholder="Personal" name="content6" <?=$_SESSION['content6']?>/>
</a>
</td>
</td>
</tr>
<tr>
<td align="center">
<input type="submit" name="login" value="login" class="btn-login"/>
</td>
</tr>
</tr>
</td>
</tr>
</form>
</tr>
</table>
</body>
</html>
RichTextbox page
<?php
session_start();
$_SESSION['message'] = '';
$mysqli=new MySQLi('127.0.0.1','root','','accounts');
if($_SERVER["REQUEST_METHOD"] == "POST") {
$content2=$_POST['content2'];
$content3=$_POST['content3'];
$content4=$_POST['content4'];
$content5=$_POST['content5'];
$content6=$_POST['content6'];
$sql ="INSERT INTO menubar(content1,content2,content3,content4,content5,content6)"
."VALUES ('$content1','$content2','$content3','$content4','$content5','$content6')";
if($mysqli->query($sql)=== true) {
$_SESSION['content1'] = $content1;
$_SESSION['content2'] = $content1;
$_SESSION['content3'] = $content1;
$_SESSION['content4'] = $content1;
$_SESSION['content5'] = $content1;
$_SESSION['content6'] = $content1;
header("location:confirmnormal.php");
}
else {
$_SESSION['message'] = "User could not be added to the database!";
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Rich text editor in js</title>
<script src="https://use.fontawesome.com/cfc0a97614.js"></script>
</head>
<body onload="enableEditMode();">
<div>
<?= $_SESSION['message']?>
<form class="form" action="" method="POST">
<button onclick="execCmd('bold');"><strong>B</strong></button>
<button onclick="execCmd('italic');"><em>I</em></button>
<button onclick="execCmd('underline');"><i class="fa fa-underline"></i></button>
<button onclick="execCmd('strikeThrough');"><i class="fa fa-strikethrough"></i></button>
<button onclick="execCmd('justifyLeft');"><i class="fa fa-align-left"></i></button>
<button onclick="execCmd('justifyCenter');"><i class="fa fa-align-center"></i></button>
<button onclick="execCmd('justifyRight');"><i class="fa fa-align-right"></i></button>
<button onclick="execCmd('justifyFull');"><i class="fa fa-align-justify"></i></button>
<button onclick="execCmd('copy');"><i class="fa fa-copy"></i></button>
<button onclick="execCmd('indent');"><i class="fa fa-indent"></i></button>
<button onclick="execCmd('outdent');"><i class="fa fa-dedent"></i></button>
<button onclick="execCmd('superscript');"><i class="fa fa-superscript"></i></button>
<button onclick="execCmd('undo');"><i class="fa fa-undo"></i></button>
<button onclick="execCmd('redo');"><i class="fa fa-repeat"></i></button>
<button onclick="execCmd('insertUnorderedList');"><i class="fa fa-list-ul"></i></button>
<button onclick="execCmd('insertOrderedList');"><i class="fa fa-list-ol"></i></button>
<br />
<select onchange = "execCommandWithArg('formatBlock',this.value);">
<option value="H1">H1</option>
<option value="H2">H2</option>
<option value="H3">H3</option>
<option value="H4">H4</option>
<option value="H5">H5</option>
<option value="H6">H6</option>
</select>
<button onclick="execCmd('insertHorizontalRule');">HR</button>
<button onclick="execCommandWithArg('createLink',prompt('Enter a URL','http://'));"><i class="fa fa-link"></i></button>
<button onclick="execCmd('unlink');"><i class="fa fa-unlink"></i></button>
<button onclick="toggleSource();"><i class="fa fa-code"></i></button>
<button onclick="toggleEdit();">Toggle Edit</button>
<select onchange = "execCommandWithArg('fontName',this.value);">
<option value="Arial">Arial</option>
<option value="Comic Sans MS">Comic Sans MS</option>
<option value="Courier">Courier</option>
<option value="Georgia">Georgia</option>
<option value="Tahoma">Tahoma</option>
<option value="Times New Roman">Times New Roman</option>
<option value="Verdana">Verdana</option>
</select>
<select onchange = "execCommandWithArg('fontSize',this.value);">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
</select>
<br />
Fore Color:<input type="color" onchange = "execCommandWithArg('forecolor',this.value);">
Background: <input type="color" onchange = "execCommandWithArg('hiliteColor',this.value);">
<button onclick="execCommandWithArg('InsertImage',prompt('Enter the image URL',''));"><i class="fa fa-file-image-o"></i></button>
<button onclick="execCmd('selectAll');">Select All</button>
</div>
<iframe name="richTextField" style="width:500px; height: 500px;"></iframe>
<script type="text/javascript">
var showinSourceCode = false;
var isInEditMode = true;
function enableEditMode () {
richTextField.document.designMode = 'On';
}
function execCmd (command) {
richTextField.document.execCommand(command, false, null);
}
function execCommandWithArg(command,arg){
richTextField.document.execCommand(command, false, arg);
}
function toggleSource () {
if(showingSourceCode) {
richTextField.document.getElementsByTagName('body')[0].innerHTML = richTextField.document.getElementsByTagName('body')[0].textContent;
showingSourceCode = false;
}else {
richTextField.document.getElementsByTagName('body')[0].textContent = richTextField.document.getElementsByTagName('body')[0].innerHTML;
showingSourceCode = true;
}
function toggleEdit() {
if(isInEditMode){
richTextField.document.designMode = 'Off';
isInEditMode = false;
} else {
richTextField.document.designMode = 'On';
isInEditMode = true;
}
}
}
</script>
<br />
<a href="nORMAL.php"> <input type="submit" name="login" value="login" class="btn-login" /></a>
</body>
</html>
1条答案
按热度按时间vnzz0bqm1#
有一些语法问题。请检查下面的代码。