尝试将我的php表单链接到我的数据库,但是没有识别出这些值。错误消息显示:
查询无效:您的SQL语法出错;检查与MySQL服务器版本对应的手册,以便在第4行的''附近使用正确的语法。
它还表示所有值的未识别变量。
任何人都可以找到错误吗?
<?php
$dbAddress='localhost';
$dbUsername='root';
$dbPassword='xxxxxxxx';
$dbDatabasename='Studentanswers'
?>
<?php
$link = mysql_connect($dbAddress, $dbUsername, $dbPassword);
if (!$link) {
die("Could not connect");
};
print "Connected to the database server";
$db_selected = mysql_select_db($dbDatabasename, $link);
if (!$db_selected) {
die("Could not use the database");
};
print "selected a DB";
$result = mysql_query ("INSERT INTO $dbDatabasename (`faculty`, `date`, `modulecode`, `moduletitle`, `school`, `modulebookcontent`,
`moduleorganisation`, `lrcmaterials`, `moduledifficulty`, `modulesimilarity`, `contentinteresting`, `previousknowledge`,
`understoodassessmentrequirements`, `assessmentmethod`, `markedwork`, `moduleleader`, `ML_interestforsubject`, `ML_contentclear`,
`ML_appropriateteachingpace`, `ML_reachableforadvice`, `ML_helpfulfeedback`, `lecturer1`, `L1_interestforsubject`,
`L1_contentclear`, `L1_appropriateteachingpace`, `L1_reachableforadvice`, `L1_helpfulfeedback`, `lecturer2`, `L2_interestforsubject`, `L2_contentclear`,
`L2_appropriateteachingpace`, `L2_reachableforadvice`, `L2_helpfulfeedback`, `hoursofindependentstudy`, `overallattendance`,
`bestfeaturesofmodule`, `improvemodule`)
VALUES (`$faculty`, `$date`, `$modulecode`, `$moduletitle`, `$school`, `$modulebookcontent`, `$moduleorganisation`, `$lrcmaterials`, `$moduledifficulty`,
`$modulesimilarity`, `$contentinteresting`, `$previousknowledge`, `$understoodassessmentrequirements`, `$assessmentmethod`, `$markedwork', `$moduleleader`,
`$ML_interestforsubject`, `$ML_contentclear`, `$ML_appropriateteachingpace`, `$ML_reachableforadvice`, `$ML_helpfulfeedback`, `$lecturer1`, `$L1_interestforsubject`,
`$L1_contentclear`, `$L1_appropriateteachingpace`, `$L1_reachableforadvice`,`$L1_helpfulfeedback`, `$lecturer2`, `$L2_interestforsubject`, `$L2_contentclear`,
`$L2_appropriateteachingpace`, `$L2_reachableforadvice`, `$L2_helpfulfeedback`, `$hoursofindependentstudy`, `$overallattendance`, `$bestfeaturesofmodule`, `$improvemodule`)");
if (!$result) {
die('Invalid query: ' . mysql_error());
}
print "run a query against the DB";
mysql_close($link);
?>
答案 0 :(得分:3)
一些评论:
VALUES ('$faculty', '$date' ...,
mysql_*
函数已被弃用,以避免潜在的SQL注入问题。register_globals
,请不要,它是危险的并且已弃用。答案 1 :(得分:1)
使用变量时,应该这样做:
"INSERT INTO `".$dbDatabasename."` ..
VALUES ('".$faculty."', '".$date."', ..
如你所知,你必须分开这样的变量:“。$ variable。”
答案 2 :(得分:0)
修正 $ markedwork
附近的输入错误 <?php
$dbAddress='localhost';
$dbUsername='root';
$dbPassword='xxxxxxxx';
$dbDatabasename='Studentanswers'
?>
<?php
$link = mysql_connect($dbAddress, $dbUsername, $dbPassword);
if (!$link) {
die("Could not connect");
};
print "Connected to the database server";
$db_selected = mysql_select_db($dbDatabasename, $link);
if (!$db_selected) {
die("Could not use the database");
};
print "selected a DB";
$result = mysql_query ("INSERT INTO $dbDatabasename (`faculty`, `date`, `modulecode`, `moduletitle`, `school`, `modulebookcontent`,
`moduleorganisation`, `lrcmaterials`, `moduledifficulty`, `modulesimilarity`, `contentinteresting`, `previousknowledge`,
`understoodassessmentrequirements`, `assessmentmethod`, `markedwork`, `moduleleader`, `ML_interestforsubject`, `ML_contentclear`,
`ML_appropriateteachingpace`, `ML_reachableforadvice`, `ML_helpfulfeedback`, `lecturer1`, `L1_interestforsubject`,
`L1_contentclear`, `L1_appropriateteachingpace`, `L1_reachableforadvice`, `L1_helpfulfeedback`, `lecturer2`, `L2_interestforsubject`, `L2_contentclear`,
`L2_appropriateteachingpace`, `L2_reachableforadvice`, `L2_helpfulfeedback`, `hoursofindependentstudy`, `overallattendance`,
`bestfeaturesofmodule`, `improvemodule`)
VALUES (`$faculty`, `$date`, `$modulecode`, `$moduletitle`, `$school`, `$modulebookcontent`, `$moduleorganisation`, `$lrcmaterials`, `$moduledifficulty`,
`$modulesimilarity`, `$contentinteresting`, `$previousknowledge`, `$understoodassessmentrequirements`, `$assessmentmethod`, `$markedwork`, `$moduleleader`,
`$ML_interestforsubject`, `$ML_contentclear`, `$ML_appropriateteachingpace`, `$ML_reachableforadvice`, `$ML_helpfulfeedback`, `$lecturer1`, `$L1_interestforsubject`,
`$L1_contentclear`, `$L1_appropriateteachingpace`, `$L1_reachableforadvice`,`$L1_helpfulfeedback`, `$lecturer2`, `$L2_interestforsubject`, `$L2_contentclear`,
`$L2_appropriateteachingpace`, `$L2_reachableforadvice`, `$L2_helpfulfeedback`, `$hoursofindependentstudy`, `$overallattendance`, `$bestfeaturesofmodule`, `$improvemodule`)");
if (!$result) {
die('Invalid query: ' . mysql_error());
}
print "run a query against the DB";
mysql_close($link);
?>