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 として挿入されます。何が間違っていますか?