0
我有一個包含4個複選框的表單;首次亮相,擊球,不擊球。當添加,如果被選中,將數據添加與此代碼(在這種情況下,首次亮相):'else if'對於多個複選框組合
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。我在做什麼錯?
好的,這是有道理的。如果我交換訂單(所以組合出現在個人之前)是否會起作用? – cameronjonesweb
如果這是你檢查的唯一組合,是的 – soulfreshner
保留訂單,它的工作完美,非常感謝你 – cameronjonesweb