Jump to content

colickyboy

Members
  • Posts

    26
  • Joined

  • Last visited

    Never

Everything posted by colickyboy

  1. As a noob PHP coder, I used to get by with variable variables but the security change in PHP 4.2 has made it much more difficult for noobs like me to do what we used to be able to do. I'm trying to create a form where I can input stats for 15 players of a softball team and then post it to a db. I used variable variables in order to use a loop for both creating the form and posting to the db. The code I'm working with is currently: [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<html> <head><link rel="stylesheet" type="text/css" href="../styles/index.css"></head> <body> <table> <tr> <td width="740" id="maincontent"> <div><br> <?php //open database $db=mysql_connect ("localhost", "user", "pw") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db("softball",$db); if ($_POST['submit']) { // update players' stats $count = $_POST['count']; for ($i = 1; $i <= $count; $i++) { echo "id$i = ${'id'.$i}<br>"; echo "AB$i = ${'AB'.$i}<br>"; $result = mysql_query('UPDATE players SET G=G+1, AB=AB+${"AB".$i}, R=R+${"R".$i}, 1B=1B+${"1B".$i}, 2B=2B+${"2B".$i}, 3B=3B+${"3B".$i}, HR=HR+${"HR".$i}, RBI=RBI+${"RBI".$i}, SF=SF+${"SF".$i}, BB=BB+$${"BB".$i}, K=K+${"K".$i}, E=E+${"E".$i} WHERE id=${"id".$i}'); } echo "Game results entered."; } else { echo "<div id='sectionheader'>Softball Update</div><br><br>"; $result = mysql_query("SELECT id, name FROM players WHERE team='Barons' AND year=2006 ORDER BY name"); $count = mysql_num_rows($result); echo '<form method="post" action="">'; if ($myrow = mysql_fetch_array($result)) { $i = 1; echo "<table><tr><td colspan='13' align='center'>Barons</td></tr><tr><td>ID</td><td>Name</td><td>AB</td><td>R</td><td>1B</td><td>2B</td><td>3B</td><td>HR</td><td>RBI</td><td>SF</td><td>BB</td><td>K</td><td>E</td></tr>"; do { $id = $myrow["id"]; $name = $myrow["name"]; echo "<tr><td><select name='id$i'><option value='$id'>$id</option></select></td>"; echo "<td><select name='name$i'><option value='$name'>$name</option></select></td>"; echo "<td><input type='text' name='AB$i' align='top' maxlength='2' size='2 '></td>"; echo "<td><input type='text' name='R$i' align='top' maxlength='2' size='2'></td>"; echo "<td><input type='text' name='1B$i' align='top' maxlength='2' size='2'></td>"; echo "<td><input type='text' name='2B$i' align='top' maxlength='2' size='2'></td>"; echo "<td><input type='text' name='3B$i' align='top' maxlength='2' size='2'></td>"; echo "<td><input type='text' name='HR$i' align='top' maxlength='2' size='2'></td>"; echo "<td><input type='text' name='RBI$i' align='top' maxlength='2' size='2'></td>"; echo "<td><input type='text' name='SF$i' align='top' maxlength='2' size='2'></td>"; echo "<td><input type='text' name='BB$i' align='top' maxlength='2' size='2'></td>"; echo "<td><input type='text' name='K$i' align='top' maxlength='2' size='2' ></td>"; echo "<td><input type='text' name='E$i' align='top' maxlength='2' size='2'></td></tr>"; $i = $i++; } while ($myrow = mysql_fetch_array($result)); echo "</table>"; } echo '<input type="hidden" name="count" value="$count">'; echo '<input type="submit" name="submit" value="Submit"><br><br>'; echo '</form>'; } ?> </div></td></tr></table> </body> </html>[/quote] Your help is greatly appreciated!
×
×
  • 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.