我有一个带有 4 个复选框的表单;首次亮相,击球,没有和保龄球。添加时,如果选中,它将使用此代码添加数据(在本例中,首次亮相):
if(!empty($_POST["debut"])) {
try
{
$sql = 'INSERT INTO performance SET
matchid = :matchid,
playerid = :playerid,
team = :team,
debut = 1,
batted = 0,
batpos = :batpos,
runs = :runs,
ballsfaced = :ballsfaced,
fours = :fours,
sixes = :sixes,
no = 0,
howout = :howout,
fielder = :fielder,
bowler = :bowler,
bowled = 0,
ballsbowled = :ballsbowled,
maidens = :maidens,
wickets = :wickets,
runsconceded = :runsconceded,
catches = :catches,
stumpings = :stumpings,
runouts = :runouts';
$s = $pdo->prepare($sql);
$s->bindValue(':matchid', $_POST['matchid']);
$s->bindValue(':playerid', $_POST['playerid']);
$s->bindValue(':team', $_POST['team']);
$s->bindValue(':batpos', $_POST['batpos']);
$s->bindValue(':runs', $_POST['runs']);
$s->bindValue(':ballsfaced', $_POST['ballsfaced']);
$s->bindValue(':fours', $_POST['fours']);
$s->bindValue(':sixes', $_POST['sixes']);
$s->bindValue(':howout', $_POST['howout']);
$s->bindValue(':fielder', $_POST['fielder']);
$s->bindValue(':bowler', $_POST['bowler']);
$s->bindValue(':ballsbowled', $_POST['ballsbowled']);
$s->bindValue(':maidens', $_POST['maidens']);
$s->bindValue(':wickets', $_POST['wickets']);
$s->bindValue(':runsconceded', $_POST['runsconceded']);
$s->bindValue(':catches', $_POST['catches']);
$s->bindValue(':stumpings', $_POST['stumpings']);
$s->bindValue(':runouts', $_POST['runouts']);
$s->execute();
}
catch (PDOException $e)
{
$error = 'Error adding submitted performance.';
include 'error.html.php';
exit();
}
}
它工作得很好。但是,如果我尝试组合(例如首次亮相和击球),则使用以下代码不起作用:
else if(!empty($_POST["debut"]) && (!empty($_POST["batted"]))) {
try
{
$sql = 'INSERT INTO performance SET
matchid = :matchid,
playerid = :playerid,
team = :team,
debut = 1,
batted = 1,
batpos = :batpos,
runs = :runs,
ballsfaced = :ballsfaced,
fours = :fours,
sixes = :sixes,
no = 0,
howout = :howout,
fielder = :fielder,
bowler = :bowler,
bowled = 0,
ballsbowled = :ballsbowled,
maidens = :maidens,
wickets = :wickets,
runsconceded = :runsconceded,
catches = :catches,
stumpings = :stumpings,
runouts = :runouts';
$s = $pdo->prepare($sql);
$s->bindValue(':matchid', $_POST['matchid']);
$s->bindValue(':playerid', $_POST['playerid']);
$s->bindValue(':team', $_POST['team']);
$s->bindValue(':batpos', $_POST['batpos']);
$s->bindValue(':runs', $_POST['runs']);
$s->bindValue(':ballsfaced', $_POST['ballsfaced']);
$s->bindValue(':fours', $_POST['fours']);
$s->bindValue(':sixes', $_POST['sixes']);
$s->bindValue(':howout', $_POST['howout']);
$s->bindValue(':fielder', $_POST['fielder']);
$s->bindValue(':bowler', $_POST['bowler']);
$s->bindValue(':ballsbowled', $_POST['ballsbowled']);
$s->bindValue(':maidens', $_POST['maidens']);
$s->bindValue(':wickets', $_POST['wickets']);
$s->bindValue(':runsconceded', $_POST['runsconceded']);
$s->bindValue(':catches', $_POST['catches']);
$s->bindValue(':stumpings', $_POST['stumpings']);
$s->bindValue(':runouts', $_POST['runouts']);
$s->execute();
}
catch (PDOException $e)
{
$error = 'Error adding submitted performance.';
include 'error.html.php';
exit();
}
}
在这种情况下,只有首次亮相会被插入为 1。我做错了什么?