0

Trying to Update the MySQL Tables but nothing is being updated, I'm sure I'm just not seeing the tiny issue, would love some help. Thanks

So its a trade block for a hockey pool, if you want the player on the trade block then you just check the CHECKBOX in the form and submit and it should change the value in the database to value of "1".

FORM:

echo "<table border='1'>";

echo "<tr><th>NAME</th> <th>POS</th> <th>BLOCK</th></tr>";

$counter = 1;

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

echo "<tr><td>"; 

echo "{$row['f_name']}" . " " . "{$row['l_name']}";

echo "</td><td><input name='pl_id[$counter]' type='hidden' value='{$row['pl_id']}'>";

echo "{$row['pos']}";

echo "</td><td><input name='pos[$counter]' type='hidden' value='{$row['pos']}'>";                                   


    echo "<input type='checkbox' name='block[$counter]' size='1' value='1'";

    if($row['block'] == '1')
    {
        echo "checked='checked'";
    }

    echo "></td></tr>";                 

$counter++;

} 
echo "</table>";

SUBMIT PHP PAGE:

mysql_connect("localhost", "user", "pass") or die(mysql_error());
mysql_select_db("mbbcom1_fantrax") or die(mysql_error());

$i = 1;
while ($i < 26) {

$block = $_POST['block'][$i];
$pl_id = $_POST['pl_id'][$i];

$query = mysql_query("UPDATE 'players'
                     SET  `block` = '$block' 
                     WHERE `players`.`pl_id` = '$pl_id'");                  
mysql_query($query); 

$i++; }

echo mysql_close();
6
  • Do echo mysql_error(); before mysql_close(); so we can see what error MySQL is giving. Commented Aug 2, 2012 at 17:00
  • You put your database username/password into the question. I've edited it out, but you should change them. Commented Aug 2, 2012 at 17:02
  • may be you should remove the quotes wrapping the table name(players) in the last update statement and use grave accent instead. just guessing because i remember facing the same trouble Commented Aug 2, 2012 at 17:04
  • little tip: optimize your while loop. Instead of using while and for you can do enough by only using while: while ($i < $formSize && $i < 26){ YOUR STATEMENTS $i++; } Commented Aug 2, 2012 at 17:08
  • Ok so I updated it with all the suggestions but still no luck, I modified the code here as well. Cant believe how fast you guys are thought. Thank you so much Commented Aug 2, 2012 at 17:28

2 Answers 2

2

Remove comma before WHERE

mysql_query("UPDATE 'players' SET block = '$block' WHERE players.pl_id = '$pl_id'");

Sign up to request clarification or add additional context in comments.

Comments

0

You have a } to less, so the PHP code doesn't run.

You do a while loop and a foreach loop, but you are only closing the for loop.

And of course you don't need a , before the WHERE statement

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.