I’ve been wrestling with this problem for an hour or so and it seems basic but I just can’t seem to get to the bottom of it. What I’m trying to do here is create a block 5 times with contents from within my mysql database.
That works fine, but my real problem is when I try to echo out error messages. I’ve got an IF right after FOR that checks if $_POST[‘champ5v5name[1-5]’] is at its default value. If it is, it should echo out an error message saying “Choose your champions!”, yet it doesn’t (It just goes through to the next page as if it were a success). I’ve tried various different methods but none of them have worked, can anybody give me a hand?
for($i=1;$i<=5;$i++) {
$result = mysql_query("SELECT name,health,damage,armour,aspeed FROM champions");
$htmltext .= '<label>Champion '.$i.'</label><br/>';
$htmltext .= '<select name="champ5v5name'.$i.'">';
$htmltext .= '<option value="select'.$i.'">Select champion:</option>';
}
while($rowschamp = mysql_fetch_array($result,MYSQL_NUM)) {
$htmltext .= '<option value="'.$rowschamp[0].'">'.$rowschamp[0].' (HP: '.$rowschamp[1].' DMG: '.$rowschamp[2].' ARMOUR: '.$rowschamp[3].' ASPEED: '.$rowschamp[4].')</option>';
}
$htmltext .= '</select><br/><br/>';
if($_POST['champ5v5name1'] != 'Select champion:' || $_POST['champ5v5name2'] != 'Select champion:' || $_POST['champ5v5name3'] != 'Select champion:' || $_POST['champ5v5name4'] != 'Select champion:' || $_POST['champ5v5name5'] != 'Select champion:') {
if($_POST['champ5v5name1'] == $_POST['champ5v5name2'] || $_POST['champ5v5name1'] == $_POST['champ5v5name3'] || $_POST['champ5v5name1'] == $_POST['champ5v5name4'] || $_POST['champ5v5name1'] == $_POST['champ5v5name5']) $error = 'A champion is repeated.';
if($_POST['champ5v5name2'] == $_POST['champ5v5name3'] || $_POST['champ5v5name2'] == $_POST['champ5v5name4'] || $_POST['champ5v5name2'] == $_POST['champ5v5name5'] || $_POST['champ5v5name2'] == $_POST['champ5v5name1']) $error = 'A champion is repeated.';
if($_POST['champ5v5name3'] == $_POST['champ5v5name2'] || $_POST['champ5v5name3'] == $_POST['champ5v5name4'] || $_POST['champ5v5name3'] == $_POST['champ5v5name5'] || $_POST['champ5v5name3'] == $_POST['champ5v5name1']) $error = 'A champion is repeated.';
if($_POST['champ5v5name4'] == $_POST['champ5v5name2'] || $_POST['champ5v5name4'] == $_POST['champ5v5name3'] || $_POST['champ5v5name4'] == $_POST['champ5v5name5'] || $_POST['champ5v5name4'] == $_POST['champ5v5name1']) $error = 'A champion is repeated.';
if($_POST['champ5v5name5'] == $_POST['champ5v5name2'] || $_POST['champ5v5name5'] == $_POST['champ5v5name3'] || $_POST['champ5v5name5'] == $_POST['champ5v5name4'] || $_POST['champ5v5name5'] == $_POST['champ5v5name1']) $error = 'A champion is repeated.';
}
else {
$error = 'Choose your champions!';
}
Well all you’re doing is assigning a string to a variable, and you’re setting an error regardless if your condition proves
trueorfalse. I see no logic to perform any specific task IF there is an error.That being said, you really need to simplify things: