Jump to content

Newb needing assistance


aFk

Recommended Posts

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.

Link to comment
Share on other sites

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. :P

Edited by aFk
Link to comment
Share on other sites

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 by Tino
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...