aFk Posted February 23, 2009 Author Report Posted February 23, 2009 Am I one of the lucky few who don't get a reply? lol Quote
Tino Posted February 25, 2009 Report Posted February 25, 2009 If I'm correct, you can't have whitespace like that in HTML forms, which means you would have to use name="loss" instead of name = "loss". Aside of that, I'd put everything you have after the if condition inside the code block of the if statement, rather than just the connection. Quote
aFk Posted February 25, 2009 Author Report Posted February 25, 2009 (edited) Thanks for the reply bud. I figured it out and here's what I got. $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("stats", $con); if ($score_compare[1]==$score_conmpare[2]) { mysql_query("INSERT INTO `standings` (draw) VALUES ('".$draw."')"); mysql_query ("INSERT INTO `standings` (team1) VALUES ('".$team."')"); mysql_query ("INSERT INTO `standings` (team2) VALUES ('".$team2."')"); } elseif ($score_compare[1]>$score_conmpare[2]) { mysql_query("INSERT INTO `standings` (wins) VALUES ('".$wins."')"); mysql_query ("INSERT INTO `standings` (team1) VALUES ('".$team."')"); mysql_query ("INSERT INTO `standings` (loss) VALUES ('".$loss."')"); mysql_query ("INSERT INTO `standings` (team2) VALUES ('".$loss."')"); } else { if ($score_compare[1]<$score_conmpare[2]) mysql_query ("INSERT INTO `standings` (loss) VALUES ('".$loss."')"); mysql_query ("INSERT INTO `standings` (team1) VALUES ('".$team."')"); mysql_query("INSERT INTO `standings` (wins) VALUES ('".$wins."')"); mysql_query ("INSERT INTO `standings` (team2) VALUES ('".$team2."')"); } mysql_close($con); There's probably a easier way of doing this. But I'm still learning. Edited February 25, 2009 by aFk Quote
Tino Posted February 25, 2009 Report Posted February 25, 2009 (edited) You can make that code a lot easier. Also, it's best practice to store your queries in variables. $con = mysql_connect("localhost","root",""); if (!$con){ die('Could not connect: ' . mysql_error()); } mysql_select_db("stats", $con) or die(mysql_error()); if ($score_compare[1] == $score_compare[2]) { $query = "INSERT INTO `standings` (draw,team1,team2) VALUES ('".$draw."','".$team."','".$team2."')"; $result = mysql_query($query) or die(mysql_error()); } elseif ($score_compare[1] > $score_compare[2]) { $query = "INSERT INTO `standings` (wins,team1,loss,team2) VALUES ('".$wins."','".$team."','".$loss."','".$team2."')";/ $result = mysql_query($query) or die(mysql_error()); } else { if ($score_compare[1] < $score_compare[2]) { $query = "INSERT INTO `standings` (loss,team1,wins,team2) VALUES ('".$loss."','".$team."','".$wins."','".$team2."')"; $result = mysql_query($query) or die(mysql_error()); } mysql_close($con); } Edited February 25, 2009 by Tino Quote
aFk Posted February 25, 2009 Author Report Posted February 25, 2009 Thanks for the great info Tino. I will remember that sir Quote
aFk Posted February 26, 2009 Author Report Posted February 26, 2009 Hey isn't there a way to write the same thing doing switch statment? to avoid all the if else statments? Quote
Tino Posted February 26, 2009 Report Posted February 26, 2009 Of course. Simply replace all the if, elseif, else, etc stuff with the required switch syntax Quote
aFk Posted February 26, 2009 Author Report Posted February 26, 2009 Thanks again Tino, I will play with this before I ask anymore questions. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.