0

I am trying to update my table with what you choose from the drop down menu and then you put text into the text box and it will update a specific column (fixture_result). The output is telling me it's updated but when I look at the database it hasn't done it.

I don't know if this question has been asked before. I looked through a few forms related to updating and they didn't help much; but if you see what I am doing wrong I would appreciate it.

<html>
<head>
    <title>The Score</title>
</head>
<body>
    <form id="form1" name="form1" method="post">
    Fixture:
        <select name='NEW'>
            <option value="">--- Select ---</option> <br>
            <?php
                if(isset($db_name)&&$db_name!=""){
                    $select=$_POST['NEW'];
                }
            ?>
            <?php
                $list=mysql_query("select * from Fixture_Information order by fixture_id asc");

                while($row_list=mysql_fetch_assoc($list)){
            ?>
            <option value="<?php echo $row_list['fixture_id']; ?>">
                <?php if($row_list['fixture_id']==$select){ echo "selected"; } ?>
                <?php echo $row_list['fixture_name']; ?>
            </option>
            <?php
                }
            ?>
        Input Score: <input type="text" name="myusername">
        <input type="submit" value="Submit">
        <?php
            $data =$_POST['myusername'];
            $select=$_POST['NEW'];
            $sql=("UPDATE Fixture_Information
                set fixture_result = '$data'
                where fixture_name = '$select'");
            $checkresult = mysql_query($sql); 
            if ($checkresult) echo 'update query succeeded'; 
                else echo 'update query failed'; 
            mysql_close(); 
        ?>
        </select>
    </form>
</body>
</html>
halfer
  • 19,824
  • 17
  • 99
  • 186
  • 1
    [Please, don't use `mysql_*` functions in new code](http://bit.ly/phpmsql). They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the [red box](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. If you choose PDO, [here is a good tutorial](http://j.mp/PoWehJ). – John Conde Apr 17 '13 at 20:26
  • FYI, you also wide open to [SQL injections](http://stackoverflow.com/q/60174) – John Conde Apr 17 '13 at 20:27
  • Yeah I know about the injections but this is a small college project as this is the way the lecturer wants it. Can you just say where I went wrong please – user2267041 Apr 17 '13 at 20:30
  • 2
    BTW, your HTML is also very invalid. You might want to validate it before continuing. – John Conde Apr 17 '13 at 20:32
  • John what if I told you that there is a backwards countries in the world where lecturers still only teach mysql_* functions. Ireland – user2267041 Apr 17 '13 at 20:58
  • 1
    Your `` to above the `Input Score` line. – halfer Apr 17 '13 at 21:02
  • Yeah that fixed the problem of the html not showing input score thanks. – user2267041 Apr 17 '13 at 21:09

1 Answers1

2

You check only the success of the update statement, which is true in your case. But you don't check how many rows where updated. You can use mysql_affected_rows for this

if (mysql_affected_rows() > 0)
    echo 'update query succeeded';
else
    echo 'update query failed';
Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198