Jump to content

Recommended Posts

Hey everybody,

I made script to add match results, it has dynamically generated dropdown menu to select teams. Here's the code:

 

add_match.php:

<form method="post" action="add_match.php">
        <img src="../templates/ico/flag_red.png" alt="Alpha">
        <select name="tag_a">
        <option>--------------</option>
            <?php
            $result = mysql_query("SELECT * FROM clans") or die(mysql_error());
            
              while($row = mysql_fetch_array( $result )) {
                  echo '<option value="'.$row['tag'].'" name="tag_a">'.$row['tag'].'</option>';
              }
            ?>
        </select>
         vs.
        <select name="tag_b">
        <option>--------------</option>
            <?php  
            $result = mysql_query("SELECT * FROM clans") or die(mysql_error());
                          
              while($row = mysql_fetch_array( $result )) {
                  echo '<option value="'.$row['tag'].'" name="tag_b">'.$row['tag'].'</option>';
              }
            ?>
        </select> 
        <img src="../templates/ico/flag_blue.png" alt="Bravo">
        <br /><br />
        <input type="text" name="score_a" class="login"> :
        <input type="text" name="score_b" class="login">
        <br /><br />
        <input type="submit" name="submit" value="Post" class="login_button">
        </form>
        <?php
        if(isset($_POST['submit'])) {

            $tag_a = $_POST['tag_a'];
            $tag_b = $_POST['tag_b'];
            $score_a = $_POST['score_a'];
            $score_b = $_POST['score_b'];
            
            if(!empty($score_a) && !empty($score_b)) { 
                $query = mysql_query("INSERT INTO matches SET id=NULL, date=CURDATE(), team_a='$team_a',
                team_b='$team_b', score_a='$score_a', score_b='$score_b'")
                or die(mysql_error());
                
                if($score_a > $score_b){ // ALPHA WON
                    mysql_query("INSERT INTO clans SET won='1' WHERE='$tag_a'")
                    or die(mysql_error());
                    mysql_query("INSERT INTO clans SET lost='1' WHERE='$tag_b'")
                    or die(mysql_error());
                }elseif($score_a = $score_b){ // DRAW
                    mysql_query("INSERT INTO clans SET draw='1' WHERE='$tag_a'")
                    or die(mysql_error());
                    mysql_query("INSERT INTO clans SET draw='1' WHERE='$tag_b'")
                    or die(mysql_error());
                }elseif($score_a < $score_b){ // BRAVO WON
                    mysql_query("INSERT INTO clans SET lost='1' WHERE='$tag_a'")
                    or die(mysql_error());
                    mysql_query("INSERT INTO clans SET won='1' WHERE='$tag_b'")
                    or die(mysql_error());
                }
                
                echo 'Done Successfully!';
            }else{ echo 'FILL OUT ALL FIELDS, d00d!'; }
        }
// $tag_a = team1 tag
// $tag_b = team2 tag
// $score_a = team1 score
// etc.

When executing this I get error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE='team1'' at line 1

 

Any ideas what's wrong? It doesn't put $tag_a and $tag_b datas into the table

Link to comment
https://forums.phpfreaks.com/topic/99669-doesnt-put-few-datas-in-table/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.