Jump to content

doesn't put few datas in table


AV

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.