Jump to content

Recommended Posts

THIS IS THE CODE FOR MY FORM

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>User Entry</title>
</head>

<body>

<h2>Data Collection</h2><p>
<form action="userform.php" method="post">
<table>
<tr><td>Weight:</td><td><input type="text" name="Weight" /></td></tr>
<tr><td>WinnerFirst:</td><td><input type ="text" name = "WinnerFirst" /></td></tr>
<tr><td>WinnerLast:</td><td><input type="text" name="WinnerLast" /></td></tr>
<tr><td>LoserFirst:</td><td><input type ="text" name = "LoserFirst" /></td></tr>
<tr><td>LoserLast:</td><td><input type ="text" name = "LoserLast" /></td></tr>
<tr><td>WonBy:</td><td><input type ="text" name = "WonBy" /></td></tr>
<tr><td>Score/FallTime:</td><td><input type ="text" name = "ScoreFallTime" /></td></tr>
<tr><td>Date:</td><td><input type ="text" name = "Date" /></td></tr>
<tr><td colspan="2" align="center"><input type="submit" /></td></tr>
</table>
</form>


</body>
</html>

 

 

AND THIS IS THE CODE FOR MY PHP PART(userform.php)

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>User Form</title>
</head>

<body>

<?php

$Weight = $_POST['Weight'];
$WinnerFirst = $_POST['WinnerFirst'];
$WinnerLast = $_POST['WinnerLast'];
$LoserFirst = $_POST['LoserFirst'];
$LoserLast = $_POST['LoserLast'];
$WonBy = $_POST['WonBy'];
$ScoreFallTime = $_POST['ScoreFallTime'];
$Date = $_POST['Date'];

$con = mysql_connect($localhost,$username,$password);
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("db73");

$sql1="INSERT INTO Matches VALUES ('','','$Weight','$WinnerFirst','$WinnerLast','$LoserFirst'
,'$LoserLast','$WonBy','$ScoreFallTime','$Date')";

if (!mysql_query($sql1,$con))
  {
  die('Error: ' . mysql_error());
  }

echo "1 record added to Matches";
print "<br><br><br><br>";
print " <a href=\"http://www.jbresette.com/mysql2/dataentryoutput.php\">Results</a><br><br>";

$sql2 = "SELECT count(*) FROM Wrestlers WHERE First = '".$WinnerFirst."' AND Last = '".$WinnerLast."'";
$sql3 = "SELECT count(*) FROM Wrestlers WHERE First = '".$LoserFirst."' AND Last = '".$LoserLast."'";
$sql4 = "INSERT INTO Wrestlers VALUES('$WinnerFirst','$WinnerLast','UPDATE',0,1,0,'UP')";
$sql5 = "UPDATE Wrestlers SET Wins = Wins + 1 WHERE First = '".$WinnerFirst."' AND Last = '".$WinnerLast."'";
$sql6 = "INSERT INTO Wrestlers VALUES('$LoserFirst','$LoserLast','UPDATE',0,0,1,'UP')";
$sql7 = "UPDATE Wrestlers SET Losses = Losses + 1 WHERE First = '".$LoserFirst."' AND Last = '".$LoserLast."'";
$sql8 = "UPDATE Wrestlers SET Pins = Pins + 1 WHERE First = '".$WinnerFirst."' AND Last = '".$WinnerLast."'";

if(mysql_query($sql2))
{
print "Insert Winner<br>";
mysql_query($sql4);
}
else
{
print "Update Winner Works<br>";
mysql_query($sql5);
}

if(mysql_query($sql3))
{
print "Insert Loser<br>";
    mysql_query($sql6);
}
else
{
print "Update Loser works<br>";
mysql_query($sql7);
}

if($WonBy=='PIN')
{
print "The pin update is working<br>";
mysql_query($sql8);
}



mysql_close($con);
?>
</body>
</html>

 

My problem is it will insert the two wrestlers that have competed against each other and update their records the first time, but it isn't egetting into the else statement the second time those wrestlers names are entered. 

I Just solved the problem.  My if statements were wrong. 

 

Changed it to:

 

$sql2 = "SELECT count(*) AS  counted1 FROM Wrestlers WHERE First = '".$WinnerFirst."' AND Last = '".$WinnerLast."'";
$RESULT1 = mysql_query($sql2) or die(mysql_error());
$sql3 = "SELECT count(*) AS counted2 FROM Wrestlers WHERE First = '".$LoserFirst."' AND Last = '".$LoserLast."'";
$RESULT2 = mysql_query($sql3) or die(mysql_error());
$sql4 = "INSERT INTO Wrestlers VALUES('$WinnerFirst','$WinnerLast','UPDATE',0,1,0,'UP')";
$sql5 = "UPDATE Wrestlers SET Wins = Wins + 1 WHERE First = '".$WinnerFirst."' AND Last = '".$WinnerLast."'";
$sql6 = "INSERT INTO Wrestlers VALUES('$LoserFirst','$LoserLast','UPDATE',0,0,1,'UP')";
$sql7 = "UPDATE Wrestlers SET Losses = Losses + 1 WHERE First = '".$LoserFirst."' AND Last = '".$LoserLast."'";
$sql8 = "UPDATE Wrestlers SET Pins = Pins + 1 WHERE First = '".$WinnerFirst."' AND Last = '".$WinnerLast."'";


$row1 = mysql_fetch_assoc($RESULT1);
$row2 = mysql_fetch_assoc($RESULT2);

if($row1['counted1']==0)
{
print "Insert Winner<br>";
mysql_query($sql4);
}
else
{
print "Update Winner Works<br>";
mysql_query($sql5);
}

if($row2['counted2']==0)
{
print "Insert Loser<br>";
    mysql_query($sql6);
}
else
{
print "Update Loser works<br>";
mysql_query($sql7);
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.