jbresette Posted June 23, 2007 Share Posted June 23, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/56863-solved-help-trying-to-get-a-form-to-run-with-php-and-mysql/ Share on other sites More sharing options...
jbresette Posted June 23, 2007 Author Share Posted June 23, 2007 you can test it by going to http://www.jbresette.com/mysql2/dataentryoutput.php and then clicking on "Add Entry" Quote Link to comment https://forums.phpfreaks.com/topic/56863-solved-help-trying-to-get-a-form-to-run-with-php-and-mysql/#findComment-280967 Share on other sites More sharing options...
jbresette Posted June 23, 2007 Author Share Posted June 23, 2007 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); } Quote Link to comment https://forums.phpfreaks.com/topic/56863-solved-help-trying-to-get-a-form-to-run-with-php-and-mysql/#findComment-280971 Share on other sites More sharing options...
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.