Im using a form which i create in PHP. First im getting two rows from the DB which i submit values to them using the form . Im using the same form for both of them. The values go into the DB ok but after some clicks the first row stops updating. Idk Whats going on. I include a video of my problem --> http://www.youtube.com/watch?v=uTFzfmJh8jU

Code is below :::

<?php

session_start();

 include("connect.php");

    $query = "SELECT * FROM test ORDER BY `id` ASC LIMIT 2";
    $result = mysql_query($query);

    echo "<h2>Seria A</h2><hr/>";

    while($row = mysql_fetch_array($result)){

        $id = $row['id'];
        $home = $row['home'];
        $away = $row['away'];
        $win = $row['win'];
        $draw = $row['draw'];
        $lose = $row['lose'];


        echo "<br/>",$id,") " ,$home, " - ", $away;

        echo "

        <form action='seria.php' method='post' id='$id'>

        <input type='radio' name='select' value='1'>1
        <input type='radio' name='select' value='X'>X
        <input type='radio' name='select' value='2'>2
        <input type='hidden' name='id' value='".$row['id']."'/>
        <input type='submit' name='submit<?php echo $id; ?>' value='Submit'/>

        <br/>

        </form>";            

        echo "Totali ", $sum = $win+$lose+$draw, "<br/><hr/>"; 

    } 

    if (!empty($_POST)) {

      $id=isset($_POST['id'])&&is_numeric($_POST['id']) ? $_POST['id']:false;

      $select = isset($_POST['select']) ? $_POST['select']:false;

      switch ($select) {

        case 1:
        $select = $win + $select;
        mysql_query("UPDATE test SET win='$select' WHERE id='$id'");
        break;

        case 'X':
        $select = '1';
        $select = $draw + $select;
        mysql_query("UPDATE test SET draw='$select' WHERE id='$id'");
        break;

        case 2:
        $select = '1';
        $select = $lose + $select;
        mysql_query("UPDATE test SET lose='$select' WHERE id='$id'");
        break;

        default:

      }


      header('Location: ../seria.php');

    }

    ?>

This is called debugging and it's a skill that you need to learn if you are going to write code. The simplistic version would be to insert a few (extra) echo's into your code so you can follow the path of what it is doing. You will no-doubt find by doing this that it isn't following the path that you expected. Once you understand why it is doing this, you can make changes and try again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.