Hey guys,
I have some code where I am going to have a couple forms, and it works great, except when inserting into mysql I only get the last form. I understand why it's not working, but I can't figure out a way to make it work? Sorry, kinda confusing, but I am just wondering how to insert all the form information to mysql..here is my code:
Code:<?php include('processinfo.php'); if($pos == 'moderator') { $name = $_POST['name']; $position = $_POST['position']; $num = $_POST['num']; $nump = $_POST['nump']; $g = $_POST['g']; $ab = $_POST['ab']; $r = $_POST['r']; $h = $_POST['h']; $s = $_POST['s']; $twob = $_POST['2b']; $thrb= $_POST['3b']; $hr = $_POST['hr']; $rbi = $_POST['rbi']; $bb = $_POST['bb']; $er = $_POST['er']; $k = $_POST['k']; $teamid = $_POST['teamid']; if(!$nump) { include('modheader.php'); echo(' <style> .texta { font-size: 10px; color: #ffffff; background-color: #336699; } .submit { font-size: 10px; color: #ffffff; background-color: #336699; } </style> <span class="small"> How many players do you want to enter?: <br> <form action="addplayer.php" method="post"> <table> <tr> <tr> <td><span class="small">Players:</td><td> </span><input type="text" name="nump" value="1" class="texta"> </tr> </tr> <tr><td><input type="submit" value="Proceed" class="submit"> </td> </tr> </table> </form> </span>'); } elseif(!$name) { $sql = mysql_query("SELECT * FROM userbase WHERE username='$user' AND password='$pass'"); while ($row = mysql_fetch_array($sql)) { $class = $row['teamclass']; $manid = $row['ID']; } include('modheader.php'); echo(' <style> .texta { font-size: 10px; color: #ffffff; background-color: #336699; } .submit { font-size: 10px; color: #ffffff; background-color: #336699; } </style> Enter Information for your player(s): <table width="100%" border="1"> <tr> <th width="18%">Name</td> <th width="12%">Team</td> <th width="5%">Pos</td> <th width="5%">#</td> <th width="5%">Games</td> <th width="5%">AB</td> <th width="5%">R</td> <th width="5%">H</td> <th width="5%">S</td> <th width="5%">2B</td> <th width="5%">3B</td> <th width="5%">HR</td> <th width="5%">RBI</td> <th width="5%">BB</td> <th width="5%">ER</td> <th width="5%">K</td> </tr>'); for($i=1;$i<=$nump;$i++) { echo(' <form action="addplayer.php" method="post"><input type="hidden" name="nump" value="$nump"> <tr> <td width="18%"><input type="text" name="name" class="texta" size="35"></td> <td width="12%" NOWRAP>'); $sql = mysql_query("SELECT * FROM teams WHERE manid='$manid'"); while ($row = mysql_fetch_array($sql)) { echo($row['name']); $teamid = $row['id']; } echo('</td> <input type="hidden" name="teamid" value=$teamid> <td width="15"><input type="text" name="position" class="texta" size="5"></td> <td width="5%" align="center"><input type="text" name="num" class="texta" size="4"></td> <td width="5%" align="center"><input type="text" name="g" class="texta" value="0" size="4"></td> <td width="5%" align="center"><input type="text" name="ab" class="texta" value="0" size="2"></td> <td width="5%" align="center"><input type="text" name="r" class="texta" value="0" size="2"></td> <td width="5%" align="center"><input type="text" name="h" class="texta" value="0" size="2"></td> <td width="5%" align="center"><input type="text" name="s" class="texta" value="0" size="2"></td> <td width="5%" align="center"><input type="text" name="2b" class="texta" value="0" size="2"></td> <td width="5%" align="center"><input type="text" name="3b" class="texta" value="0" size="2"></td> <td width="5% align="center""><input type="text" name="hr" class="texta" value="0" size="2"></td> <td width="5%" align="center"><input type="text" name="rbi" class="texta" value="0" size="2"></td> <td width="5%" align="center"><input type="text" name="bb" class="texta" value="0" size="2"></td> <td width="5%" align="center"><input type="text" name="er" class="texta" value="0" size="2"></td> <td width="5%" align="center"><input type="text" name="k" class="texta" value="0" size="2"></td> </tr>'); } echo('</table><br><input type="submit" value="Proceed" class="submit"> </form>'); } else { $sql = mysql_query("SELECT * FROM teams WHERE manid='$manid'"); while ($row = mysql_fetch_array($sql)) { $teamid = $row['id']; } $sql = mysql_query("SELECT * FROM userbase WHERE username='$user' AND password='$pass'"); while ($row = mysql_fetch_array($sql)) { $manid = $row['ID']; } mysql_query("INSERT INTO players SET name='$name', teamid='$teamid', k='$k', er='$er', bb='$bb', rbi='$rbi', hr='$hr', r='$r', ab='$ab', 2b='$twob', 3b='$thrb', s='$s', h='$h', g='$g', num='$num', pos='$position'"); echo('<br><br><br><br><center><span class="small">Thank you for submitting a new player<br> You will now be returned to the enter information page. </span> <META HTTP-EQUIV="refresh" content="1; URL=index.php"> '); } } else { echo('Sorry only moderators can access this area'); } ?>
If you don't understand or don't want to look at allll that code, here is a bit shorter version without the html..
Code:<?php $dtime = date("m.d.y g:i a"); include('processinfo.php'); if($pos == 'moderator') { $name = $_POST['name']; $position = $_POST['position']; $num = $_POST['num']; $nump = $_POST['nump']; $g = $_POST['g']; $ab = $_POST['ab']; $r = $_POST['r']; $h = $_POST['h']; $s = $_POST['s']; $twob = $_POST['2b']; $thrb= $_POST['3b']; $hr = $_POST['hr']; $rbi = $_POST['rbi']; $bb = $_POST['bb']; $er = $_POST['er']; $k = $_POST['k']; $teamid = $_POST['teamid']; if(!$nump) { include('modheader.php'); // a form asking how many players to be added($nump) } elseif(!$name) { $sql = mysql_query("SELECT * FROM userbase WHERE username='$user' AND password='$pass'"); while ($row = mysql_fetch_array($sql)) { $class = $row['teamclass']; $manid = $row['ID']; } include('modheader.php'); // styles and beginning of input table for($i=1;$i<=$nump;$i++) { // all the inputs would show up here } else { $sql = mysql_query("SELECT * FROM teams WHERE manid='$manid'"); while ($row = mysql_fetch_array($sql)) { $teamid = $row['id']; } $sql = mysql_query("SELECT * FROM userbase WHERE username='$user' AND password='$pass'"); while ($row = mysql_fetch_array($sql)) { $manid = $row['ID']; } mysql_query("INSERT INTO players SET name='$name', teamid='$teamid', k='$k', er='$er', bb='$bb', rbi='$rbi', hr='$hr', r='$r', ab='$ab', 2b='$twob', 3b='$thrb', s='$s', h='$h', g='$g', num='$num', pos='$position'"); // redirect here } } else { echo('Sorry only moderators can access this area'); } ?>





Bookmarks