Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6756367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:30:57+00:00 2026-05-26T13:30:57+00:00

I’ve been wrestling with this problem for an hour or so and it seems

  • 0

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!';
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:30:57+00:00Added an answer on May 26, 2026 at 1:30 pm

    Well all you’re doing is assigning a string to a variable, and you’re setting an error regardless if your condition proves true or false. I see no logic to perform any specific task IF there is an error.

    That being said, you really need to simplify things:

    try {
        $champions = array();
        $error     = null;
        for ($i = 1; $i < 6; $i++){
            $champions[] = $_POST['champ5v5name' . $i];
        }
        $dups      = array_count_values($champions);
        rsort($dups);
    
        // Check for missed assignments, assuming no champions have the word 'select' in their name
        if(in_array('select',$champions)){
            $error = 'Choose your champions!';
        }
    
        // Check for duplicate champs
        if($dups[0] != 1){
            $error = 'Champion Repeated!';
        }
    
        if($error){
            throw new Exception($error);
        }
    }
    catch (Exception $e) {
        echo $e->getMessage();
        exit(); // Probably don't exit, just show the form again.
    }
    
    // Do other stuff, everything is ok if the code gets here...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.