PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I'm new to PHP/SQL and have a simple problem - I've looked around various sites about if statements and I can't find the problem.
This bit of code is ignoring the if statements, it writes the variable $new_driver to all three fields when it should only do it on one field depending on what $new_drivers is set to.
if ($new_drivers=1) {
$query = ("UPDATE teams SET driver_one='$new_driver_id' WHERE id='$ids'";)
mysql_query($query) or die (mysql_error());
}
if ($new_drivers=2) {
$query = ("UPDATE teams SET driver_two='$new_driver_id' WHERE id='$ids'");
mysql_query($query) or die (mysql_error());
}
if ($new_drivers=3) {
$query = ("UPDATE teams SET test_driver='$new_driver_id' WHERE id='$ids'");
mysql_query($query) or die (mysql_error());
}
Any ideas?
I know the code is not very elegant but I'm learning!
switch($new_drivers) {
case 1:
$query = "UPDATE teams SET driver_one='$new_driver_id' WHERE id='$ids'";
mysql_query($query) or die (mysql_error());
break;
case 2:
$query = "UPDATE teams SET driver_two='$new_driver_id' WHERE id='$ids'";
mysql_query($query) or die (mysql_error());
break;
case 3:
$query = "UPDATE teams SET test_driver='$new_driver_id' WHERE id='$ids'";
mysql_query($query) or die (mysql_error());
break;
}
andre_c wrote:your if statement is using the assignment operator (=) instead of the equality comparison (==)
very common mistake that happens to all of us
Ah!
See, I'm used to Spectrum Basic!
Thanks guys, if not for the help from these boards I'd have given up on my game long ago.
As it is I reckon I'm 10% or so through the coding.