Click here to Skip to main content
15,893,663 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm using a form created in PHP. First I am getting two rows from the DB which I submit values to them using the form. I am using the same form for both of them. The values go into the DB but after some clicks the first row stops updating. I don't know what's going on.

I include a video of my problem. -->http://www.youtube.com/watch?v=uTFzfmJh8jU[^]

PHP
<?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');
    }
?>
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900