我不知道爲什麼我receving這個錯誤,但它一直聲稱我有一個未定義的指數:上的AudioFile線35以下代碼:
<?php
ini_set('display_errors',1);
session_start();
?>
<body>
<?php
// connect to the database
include('connect.php');
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
die();
}
unlink("AudioFiles/" . $_SESSION['AudioFile']);
$delete = $mysqli->prepare('DELETE FROM Audio WHERE AudioId = ?');
$delete->bind_param("i",$_SESSION['lastAudioID']);
$delete->execute();
$deleteaud = $mysqli->prepare('DELETE FROM Audio_Question WHERE AudioId = ?');
$deleteaud->bind_param("i",$_SESSION['lastAudioID']);
$deleteaud->execute();
?>
</body>
</html>
我不太理解爲什麼我收到這個索引錯誤。有誰知道我爲什麼接受這個錯誤?
我在audioupload.php頁面其低於
<?php
ini_set('session.gc_maxlifetime',12*60*60);
ini_set('session.gc_divisor', '1');
ini_set('session.gc_probability', '1');
ini_set('session.cookie_lifetime', '0');
require_once 'init.php';
session_start();
?>
<!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" />
</head>
<body>
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
// connect to the database
include('connect.php');
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
die();
}
$result = 0;
if ((($_FILES["fileAudio"]["type"] == "audio/wav")
|| ($_FILES["fileAudio"]["type"] == "audio/wma")
|| ($_FILES["fileAudio"]["type"] == "audio/mp3")
|| ($_FILES["fileAudio"]["type"] == "audio/m3u")
|| ($_FILES["fileAudio"]["type"] == "audio/iff")
|| ($_FILES["fileAudio"]["type"] == "audio/mid")
|| ($_FILES["fileAudio"]["type"] == "audio/m4a")
|| ($_FILES["fileAudio"]["type"] == "audio/mpa")
|| ($_FILES["fileAudio"]["type"] == "audio/aif")
|| ($_FILES["fileAudio"]["type"] == "audio/wa"))
&& ($_FILES['fileAudio']['size'] > 0))
{
if(file_exists("AudioFiles/".$_FILES['fileAudio']['name'])) {
$parts = explode(".",$_FILES['fileAudio']['name']);
$ext = array_pop($parts);
$base = implode(".",$parts);
$n = 2;
while(file_exists("AudioFiles/".$base."_".$n.".".$ext)) $n++;
$_FILES['fileAudio']['name'] = $base."_".$n.".".$ext;
move_uploaded_file($_FILES["fileAudio"]["tmp_name"],
"AudioFiles/" . $_FILES["fileAudio"]["name"]);
$result = 1;
}
else
{
move_uploaded_file($_FILES["fileAudio"]["tmp_name"],
"AudioFiles/" . $_FILES["fileAudio"]["name"]);
$result = 1;
}
$audiosql = "INSERT INTO Audio (AudioFile)
VALUES (?)";
if (!$insert = $mysqli->prepare($audiosql)) {
// Handle errors with prepare operation here
}
//Dont pass data directly to bind_param store it in a variable
$insert->bind_param("s",$aud);
//Assign the variable
$aud = 'AudioFiles/'.$_FILES['fileAudio']['name'];
$insert->execute();
if ($insert->errno) {
// Handle query error here
}
$insert->close();
$lastAudioID = $mysqli->insert_id;
$_SESSION['lastAudioID'] = $lastAudioID;
$_SESSION['AudioFile'] = $_FILES["fileAudio"]["name"];
$sessid = $_SESSION['id'] . ($_SESSION['initial_count'] > 1 ? $_SESSION['sessionCount'] : '');
$sessionquery = "SELECT SessionId FROM Session WHERE (SessionName = ?)";
if (!$sessionstmt = $mysqli->prepare($sessionquery)) {
// Handle errors with prepare operation here
echo __LINE__.': '.$mysqli->error;
}
// Bind parameter for statement
$sessionstmt->bind_param("s", $sessid);
// Execute the statement
$sessionstmt->execute();
if ($sessionstmt->errno)
{
// Handle query error here
echo __LINE__.': '.$sessionstmt->error;
break 1;
}
// This is what matters. With MySQLi you have to bind result fields to
// variables before calling fetch()
$sessionstmt->bind_result($sessionid);
// This populates $optionid
$sessionstmt->fetch();
$sessionstmt->close();
$audioquestionsql = "INSERT INTO Audio_Question (AudioId, SessionId, QuestionId)
VALUES (?, ?, ?)";
if (!$insertaudioquestion = $mysqli->prepare($audioquestionsql)) {
// Handle errors with prepare operation here
echo "Prepare statement err audioquestion";
}
$qnum = (int)$_POST['numaudio'];
$insertaudioquestion->bind_param("iii",$lastAudioID, $sessionid, $qnum);
$insertaudioquestion->execute();
if ($insertaudioquestion->errno) {
// Handle query error here
}
$insertaudioquestion->close();
}
?>
<script language="javascript" type="text/javascript">window.top.stopAudioUpload(<?php echo $result; ?>, '<?php echo $_FILES['fileAudio']['name'] ?>');</script>
</body>
</html>
'$ _SESSION ['AudioFile']'在任何地方定義? – andrewsi
這意味着session變量不包含索引'AudioFile'。你在哪裏設置'AudioFile'('$ _SESSION ['AudioFile'] = ...;'')的會話變量? – n00dle
我已經在另一個頁面中定義了會話變量,我已經包含代碼或在上面更新的問題 – user1763986