Jump to content

PHP Form with MySQL


rwachowiak

Recommended Posts

Ok, so what im trying to achieve is this... you come to this page: http://www.hutcommunity.com/Database/playercard.php

 

You click on a player... and his information is loaded into the table.

 

You can then add "training cards" to the players stats... eg, +5skt or +9 skt, etc, to get them higher stats.

 

each player has a set amount of training slots.

 

below is my code, and its pretty close, but when you do a +9skt and +9hnd, its adding +9 and +9 to stats 1 and 2 instead of 9 for each one... because of the code... so how would i be able to achieve this?? i feel like im really close!!!

 

<!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=utf-8" />
<title>Player Card</title>
    <script type="text/javascript" src="jquery-1.3.2.js"></script> 
    <script type="text/javascript" src="jquery.form.js"></script>
    <script type="text/javascript"> 
        // wait for the DOM to be loaded 
        $(document).ready(function() { 
            // bind 'myForm' and provide a simple callback function 
            $('#myForm').ajaxForm(function() { 
                alert("Thank you for your comment!"); 
            }); 
        }); 
    </script>
</head>

<body>
<table cellpadding="0" cellspacing="0" class="display" id="example">
          <thead>
            <tr>
              <th></th>
              <th align="left">FIRST NAME</th>
              <th align="left">LAST NAME</th>
              <th align="center">OVR</th>
              <th align="center">POT</th>
              <th align="left">TEAM</th>
              <th align="left">LEAGUE</th>
              <th align="center">SKT</th>
              <th align="center">SHT</th>
              <th align="center">HND</th>
              <th align="center">CHK</th>
              <th align="center">DEF</th>
              <th>SALARY</th>
              <th>CAREER</th>
              <th align="center">POSITION</th>
              <th>TYPE</th>
              <th>SLOTS</th>
            </tr>
          </thead> 
          <tbody>
<?
$username="???";
$password="???";
$database="???";

mysql_connect('hutcommunity.db.6977873.hostedresource.com',$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM Players WHERE Team='Buffalo Sabres'";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

$i=0;
while ($i < $num) {

$First_Name=mysql_result($result,$i,"First_Name");
$Last_Name=mysql_result($result,$i,"Last_Name");
$Team=mysql_result($result,$i,"Team");
$League=mysql_result($result,$i,"League");
$Career_Games=mysql_result($result,$i,"Career_Games");
$Salary=mysql_result($result,$i,"Salary");
$Position=mysql_result($result,$i,"Position");
$Player_Type=mysql_result($result,$i,"Player_Type");
$Training_Slots=mysql_result($result,$i,"Training_Slots");
$Stat_1=mysql_result($result,$i,"Stat_1");
$Stat_2=mysql_result($result,$i,"Stat_2");
$Stat_3=mysql_result($result,$i,"Stat_3");
$Stat_4=mysql_result($result,$i,"Stat_4");
$Stat_5=mysql_result($result,$i,"Stat_5");
$Overall=mysql_result($result,$i,"Overall");
$Potential=mysql_result($result,$i,"Potential");
$Mugshot=mysql_result($result,$i,"Mugshot");

echo "<tr>
              <td><img src=\"http://cdn.nhl.com/photos/mugs/thumb/$Mugshot.jpg\" width=\"37\" height=\"47\" /></td>
		  <td><strong><span class=\"Name\"><a href=\"playercard.php?id=$Mugshot\">$First_Name</a></strong</span></td>
              <td><strong><span class=\"Name\"><a href=\"playercard.php?id=$Mugshot\">$Last_Name</a></strong</span></td>
              <td align=\"center\"><span class=\"Overall\"><strong>$Overall</strong></span></td>
              <td align=\"center\"><span class=\"Potential\"><strong>$Potential</strong></span></td>
              <td>$Team</td>
              <td align=\"center\">$League</td>
              <td align=\"center\"><strong>$Stat_1</strong></td>
              <td align=\"center\"><strong>$Stat_2</strong</td>
              <td align=\"center\"><strong>$Stat_3</strong</td>
              <td align=\"center\"><strong>$Stat_4</strong</td>
              <td align=\"center\"><strong>$Stat_5</strong</td>
              <td align=\"center\">$Salary</td>
              <td align=\"center\">$Career_Games</td>
              <td align=\"center\">($Position)</td>
              <td align=\"center\">$Player_Type</td>
              <td>0 / $Training_Slots</td>
            </tr>
";

$i++;
}

?>

          </tbody>
        </table>

<?
$username="???";
$password="???";
$database="???";

$id = $_GET['id']; 


$Slot1=$_POST['Slot1'];
$Slot2=$_POST['Slot2'];
$Slot3=$_POST['Slot3'];
$Slot4=$_POST['Slot4'];
$Slot5=$_POST['Slot5'];
$Slot6=$_POST['Slot6'];
$Slot7=$_POST['Slot7'];
$Slot8=$_POST['Slot8'];
$Slot9=$_POST['Slot9'];
$Slot10=$_POST['Slot10'];
$Slot11=$_POST['Slot11'];
$Slot12=$_POST['Slot12'];

mysql_connect('hutcommunity.db.6977873.hostedresource.com',$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM Players WHERE Mugshot='$id'";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

$i=0;
while ($i < $num) {

$First_Name=mysql_result($result,$i,"First_Name");
$Last_Name=mysql_result($result,$i,"Last_Name");
$Team=mysql_result($result,$i,"Team");
$League=mysql_result($result,$i,"League");
$Career_Games=mysql_result($result,$i,"Career_Games");
$Salary=mysql_result($result,$i,"Salary");
$Position=mysql_result($result,$i,"Position");
$Player_Type=mysql_result($result,$i,"Player_Type");
$Training_Slots=mysql_result($result,$i,"Training_Slots");
$Stat_1=mysql_result($result,$i,"Stat_1");
$Stat_2=mysql_result($result,$i,"Stat_2");
$Stat_3=mysql_result($result,$i,"Stat_3");
$Stat_4=mysql_result($result,$i,"Stat_4");
$Stat_5=mysql_result($result,$i,"Stat_5");
$Overall=mysql_result($result,$i,"Overall");
$Potential=mysql_result($result,$i,"Potential");
$Mugshot=mysql_result($result,$i,"Mugshot");

$S1M99 = 99-$Stat_1;
$S2M99 = 99-$Stat_2;
$S3M99 = 99-$Stat_3;
$S4M99 = 99-$Stat_4;
$S5M99 = 99-$Stat_5;

$SKATE5=5;
$SKATE7=7;
$SKATE9=9;
$HAND5=5;
$HAND7=7;
$HAND9=9;
$SKATETOTAL = $Stat_1+$Slot1+$Slot2;
$HANDTOTAL = $Stat_2+$Slot1+$Slot2;

echo "
<table width=\"500\" border=\"2\" cellspacing=\"2\" cellpadding=\"2\">
   <tr>
     <td colspan=\"3\" rowspan=\"3\"><img src=\"http://cdn.nhl.com/photos/mugs/$Mugshot.jpg\"/></td>
     <td width=\"294\">$League</td>
   </tr>
   <tr>
     <td>$Team</td>
   </tr>
   <tr>
     <td>$Overall $Potential</td>
   </tr>
   <tr>
     <td colspan=\"4\">$First_Name $Last_Name</td>
   </tr>
   <tr>
     <td width=\"67\">SKT</td>
     <td width=\"58\">$Stat_1</td>
     <td width=\"43\">$S1M99</td>
     <td>$SKATETOTAL</td>
   </tr>
   <tr>
     <td>SHT</td>
     <td>$Stat_2</td>
     <td>$S2M99</td>
     <td>$HANDTOTAL</td>
   </tr>
   <tr>
     <td>HND</td>
     <td>$Stat_3</td>
     <td>$S3M99</td>
     <td> </td>
   </tr>
   <tr>
     <td>CHK</td>
     <td>$Stat_4</td>
     <td>$S4M99</td>
     <td> </td>
   </tr>
   <tr>
     <td>DEF</td>
     <td>$Stat_5</td>
     <td>$S5M99</td>
     <td> </td>
   </tr>
</table>
";

$i++;
}
?>

<form id="myForm" method="post">
<?
$username="???";
$password="???";
$database="???";

$id = $_GET['id'];

mysql_connect('hutcommunity.db.6977873.hostedresource.com',$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM Players WHERE Mugshot='$id'";

$result=mysql_query($query);

$var = $Training_Slots;
foreach(range(1,$var) as $num) {
    echo "Training Slot $num: <select name=\"Slot$num\" id=\"Slot$num\">
    <option value=\"\">Choose Training</option>
    <option value=\"$SKATE5\">+5 SKT</option>
    <option value=\"$SKATE7\">+7 SKT</option>
    <option value=\"$SKATE9\">+9 SKT</option>   
    <option value=\"$HAND5\">+5 HND</option>
    <option value=\"$HAND7\">+7 HND</option>
    <option value=\"$HAND9\">+9 HND</option> 
  </select><br>
";
}

?>
<input type="Submit">
</form>


</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/219231-php-form-with-mysql/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.