无法使SQL和PHP工作

时间:2017-03-23 04:15:45

标签: php mysql session session-variables

所以我试图用SQL将文件上传到我的数据库中。以下代码在我在localhost中尝试时有效,但在我的实际服务器上没有。我测试了它与数据库的连接并且连接了,但它不会上传。

if (isset($_POST['uploadtodb'])) {
$asdupload = 0;
while ($asdupload < 25 && isset($_SESSION{"matchq0-" . $asdupload})) {
$q0upload = $_SESSION{"matchq0-" . $asdupload};
$q1upload = $_SESSION{"matchq1-" . $asdupload};
$q2upload = $_SESSION{"matchq2-" . $asdupload};
$q3upload = $_SESSION{"matchq3-" . $asdupload};
$q4upload = $_SESSION{"matchq4-" . $asdupload};
$q5upload = $_SESSION{"matchq5-" . $asdupload};
$q6upload = $_SESSION{"matchq6-" . $asdupload};
$q7upload = $_SESSION{"matchq7-" . $asdupload};
$q8upload = $_SESSION{"matchq8-" . $asdupload};
$q9upload = $_SESSION{"matchq9-" . $asdupload};
$q10upload = $_SESSION{"matchq10-" . $asdupload};
$q11upload = $_SESSION{"matchq11-" . $asdupload};
$q12upload = $_SESSION{"matchq12-" . $asdupload};
$q13upload = $_SESSION{"matchq13-" . $asdupload};
$q14upload = $_SESSION{"matchq14-" . $asdupload};
$q15upload = $_SESSION{"matchq15-" . $asdupload};
$teamnumupload = $_SESSION['teamnum'];
include 'config.php';
$sqlupload = "INSERT INTO matches(q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11, q12, q13, q14, q15, teamnum) VALUES('$q0upload', '$q1upload', '$q2upload', '$q3upload', '$q4upload', '$q5upload', '$q6upload', '$q7upload', '$q8upload', '$q9upload', '$q10upload', '$q11upload', '$q12upload', '$q13upload', '$q14upload', '$q15upload', '$teamnumupload')";
if ($db) {
    echo "connected to db";
} else {
echo "not connected to db";
}
if (mysqli_query($db, $sqlupload)) {
echo "<script>Alert.render('Successfully uploaded rows into database.', '')</script>";
unset($_SESSION{"matchq0-" . $asdupload});
unset($_SESSION{"matchq1-" . $asdupload});
unset($_SESSION{"matchq2-" . $asdupload});
unset($_SESSION{"matchq3-" . $asdupload});
unset($_SESSION{"matchq4-" . $asdupload});
unset($_SESSION{"matchq5-" . $asdupload});
unset($_SESSION{"matchq6-" . $asdupload});
unset($_SESSION{"matchq7-" . $asdupload});
unset($_SESSION{"matchq8-" . $asdupload});
unset($_SESSION{"matchq9-" . $asdupload});
unset($_SESSION{"matchq10-" . $asdupload});
unset($_SESSION{"matchq11-" . $asdupload});
unset($_SESSION{"matchq12-" . $asdupload});
unset($_SESSION{"matchq13-" . $asdupload});
unset($_SESSION{"matchq14-" . $asdupload});
unset($_SESSION{"matchq15-" . $asdupload});
$_SESSION['matchcapacity'] = 0;
} else {
echo "<script>Alert.render('Unable to upload rows into database. Check your connection, and make sure you are online.', '')</script>";  
}
    $asdupload++;
}

}

我在会话结束时有一个变量的原因是因为我有例如$_SESSION['matchq0-0']; $_SESSION['matchq0-1']; $_SESSION['matchq0-2'];等的会话。

config.php有sql连接信息

2 个答案:

答案 0 :(得分:1)

将花括号更改为方括号[]

您的会话应该像$_SESSION["matchq0-" . $asdupload]

一样

答案 1 :(得分:0)

我很抱歉,但我犯了一个大错,我的SQL表名出错了。我感谢您的帮助。抱歉,