我使用PHP和我返回此值时:$_SESSION['sessionNum']
和我得到一个错误:
Notice: Undefined index: sessionNum.
这个错误是什么意思?
下面是引用的页面(create_session2.php)我的车的PHP代码
<?php
session_start();
?>
<script type="text/javascript">
function validation() {
var isDataValid = true;
var sessionNoO = document.getElementById("sessionNo");
var errSessionNoMsgO = document.getElementById("sessionNoAlert")
if(sessionNoO.value == ""){
errSessionNoMsgO.innerHTML = "Please Set the Number of Sessions";
isDataValid = false;
}
else if (sessionNoO.value == 0){
errSessionNoMsgO.innerHTML = "Number of Sessions Must be More than 0";
isDataValid = false;
}
else {
errSessionNoMsgO.innerHTML = "";
}
return isDataValid;
}
function showConfirm(){
var confirmMsg=confirm(
"Make sure that your details are correct, once you proceed after " +
"this stage you would not be able to go back and change any " +
"details towards your Session." +
"\n" + "\n" + "Are you sure you want to Proceed?" + "\n");
if (confirmMsg==true){
submitform();
}
}
function submitform(){
var sessionFormO = document.getElementById("sessionForm");
sessionFormO.submit();
}
</script>
</head>
<body>
<h1>CREATING A NEW SESSION</h1>
<br/>
<form action="QandATable2.php"
method="post" id="sessionForm">
<p><strong> Number of Sessions you Require:</strong>
<input type="text"
id="sessionNo"
name="sessionNum"
onkeypress="return isNumberKey(event)"
maxlength="5" /><br/>
<span id="sessionNoAlert"></span>
</p>
<p><input class="questionBtn"
type="submit"
value="Prepare Questions"
name="prequestion" onClick="myClickHandler(); return false;"/>
</p>
<!-- Prepare Questions here-->
</form>
<script type="text/javascript">
function myClickHandler(){
if(validation()){
showConfirm();
}
}
</script>
</body>
下面是当前页面的代码(QandATable2.php)
<script type="text/javascript">
function showConfirm(){
var confirmMsg=confirm(
"Make sure that your details are correct, once you proceed after " +
"this stage you would not be able to go back and change any details " +
"towards Questions, Options and Answers for your Session." +
"\n" + "\n" + "Are you sure you want to Proceed?" + "\n");
if (confirmMsg==true){
submitform();
}
}
function submitform(){
var sessionMarksO = document.getElementById("sessionMarks");
sessionMarksO.submit();
}
</script>
<body>
<form id="enter"
action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>"
method="post" onsubmit="return validateForm(this);" >
<p>
<input id="submitBtn" name="submitDetails"
type="submit"
value="Submit Details"
onClick="myClickHandler(); return false;" />
</p>
</form>
<script type="text/javascript">
function myClickHandler(){
if(validation()){
showConfirm();
}
}
</script>
<?php
session_start();
$outputDetails = "";
$outputDetails .= "
<table id='sessionDetails' border='1'>
<tr>
<th>Number of Sessions:</th>
<th>$_SESSION['sessionNum'] = $_POST['sessionNum'];</th>
</tr>";
$outputDetails .= " </table>";
echo $outputDetails;
?>
在尝试访问'$ _SESSION'之前,您是否调用'session_start();'?您可以使用'isset($ _ SESSION [“sessionNum”])''函数检查您的元素是否已设置。 – Crontab 2012-03-27 12:05:28
你在链接中粘贴了一个错误的URL – Saikios 2012-03-27 12:05:46
你在哪里初始化会话? – scibuff 2012-03-27 12:05:55