SQL语法错误。 0和1

时间:2013-10-22 16:17:20

标签: php mysql sql checkbox syntax

正如标题所说,我的语法有问题。

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1', '1', '1', '1', '0', '1', '0', '0', '0', '0', '0', '0', '0', '0'' at line 38

这是我的代码。如果有人能让我知道它是什么问题,我将不胜感激。每当有人开始会话时,它会显示一个包含下面列出的所有选项的表单,然后通过单击提交显示此信息。如果我改变第32行中的东西并不重要,它总是有同样的问题。希望有人可以提供帮助。

<?php

include('test6.inc');
// Inialize session
session_start();

// Check, if username session is NOT set then this page will jump to login page
if (!isset($_SESSION['username'])) {
header('Location: test2.php');
}

?>

Welcome: <b><?php echo $_SESSION['username']; ?>


<?php

$football = isset($_POST["football"]) ? $_POST["football"] : 0;
$baseball = isset($_POST["baseball"]) ? $_POST["baseball"] : 0;
$basketball = isset($_POST["basketball"]) ? $_POST["basketball"] : 0;
$cheer = isset($_POST["cheer"]) ? $_POST["cheer"] : 0;
$xcountry = isset($_POST["xcountry"]) ? $_POST["xcountry"] : 0;
$golf = isset($_POST["golf"]) ? $_POST["golf"] : 0;
$lacrosse = isset($_POST["lacrosse"]) ? $_POST["lacrosse"] : 0;
$rodeo = isset($_POST["rodeo"]) ? $_POST["rodeo"] : 0;
$soccer = isset($_POST["soccer"]) ? $_POST["soccer"] : 0;
$tennis = isset($_POST["tennis"]) ? $_POST["tennis"] : 0;
$track = isset($_POST["track"]) ? $_POST["track"] : 0;
$volleyball = isset($_POST["volleball"]) ? $_POST["volleball"] : 0;
$wrestling = isset($_POST["wrestling"]) ? $_POST["wrestling"] : 0;
$wbasketball = isset($_POST["wbasketball"]) ? $_POST["wbasketball"] : 0;
$wcheer = isset($_POST["wcheer"]) ? $_POST["wcheer"] : 0;
$wxcountry = isset($_POST["wxcountry"]) ? $_POST["wxcountry"] : 0;
$dance = isset($_POST["dance"]) ? $_POST["dance"] : 0;
$wgolf = isset($_POST["wgolf"]) ? $_POST["wgolf"] : 0;
$wlacrosse = isset($_POST["wlacrosse"]) ? $_POST["wlacrosse"] : 0;
$wrodeo = isset($_POST["wrodeo"]) ? $_POST["wrodeo"] : 0;
$wsoccer = isset($_POST["wsoccer"]) ? $_POST["wsoccer"] : 0;
$softball = isset($_POST["softball"]) ? $_POST["softball"] : 0;
$wtennis = isset($_POST["wtennis"]) ? $_POST["wtennis"] : 0;
$wtrack = isset($_POST["wtrack"]) ? $_POST["wtrack"] : 0;
$wvolleyball = isset($_POST["wvolleyball"]) ? $_POST["wvolleyball"] : 0;
$wwrestling = isset($_POST["wwrestling"]) ? $_POST["wwrestling"] : 0;
$student_aff = isset($_POST["student_aff"]) ? $_POST["student_aff"] : 0;
$int_club = isset($_POST["int_club"]) ? $_POST["int_club"] : 0;
$hist_act = isset($_POST["hist_act"]) ? $_POST["hist_act"] : 0;
$contests = isset($_POST["contests"]) ? $_POST["contests"] : 0;
$lib_events = isset($_POST["lib_events"]) ? $_POST["lib_events"] : 0;
$vik_exch = isset($_POST["vik_exch"]) ? $_POST["vik_exch"] : 0;


mysql_query("INSERT INTO `email`(`football`,
`baseball`,
`basketball`,
`cheer`,
`xcountry`,
`golf`,
`lacrosse`,
`rodeo`,
`soccer`,
`tennis`,
`track`,
`volleyball`,
`wrestling`,
`wbasketball`,
`wcheer`,
`wxcountry`,
`dance`,
`wgolf`,
`wlacrosse`,
`wrodeo`,
`wsoccer`,
`softball`,
`wtennis`,
`wtrack`,
`wvolleyball`,
`wwrestling`,
`sudent_aff`,
`int_club`,
`hist_act`,
`contests`,
`lib_events`,
`vik_exch`) VALUES ('$football',
'$baseball',
'$basketball',
'$cheer',
'$xcountry',
'$golf',
'$lacrosse,
'$rodeo',
'$soccer',
'$tennis',
'$track',
'$volleyball',
'$wrestling',
'$wbasketball',
'$wcheer',
'$wxcountry',
'$dance',
'$wgolf',
'$wlacrosse',
'$wrodeo',
'$wsoccer',
'$softball',
'$wtennis',
'$wtrack',
'$wvolleyball',
'$wwrestling',
'$student_aff',
'$int_club',
'$hist_act',
'$contests',
'$lib_events',
'$vik_exch')") or die(mysql_error());



?>

由于

已编辑:修复了之前的错误。有新的错误。

2 个答案:

答案 0 :(得分:3)

您的上一个字段名称缺少后退结果。但是很高兴这个查询不起作用,因为在一个足够糟糕的人手中,这可能会破坏你的数据库。它很容易注射。

`vik_exch) 

'$lacrosse,

缺少结束'

答案 1 :(得分:0)

vik_exch

之后关闭引用
`vik_exch`) VALUES ('$football'