SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Multiple Inputs

  1. #1
    SitePoint Zealot
    Join Date
    Jan 2004
    Location
    Wheelersburg
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Multiple Inputs

    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>&nbsp;</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');
    }
    
    ?>
    http://chaseschwalbach.com

  2. #2
    SitePoint Zealot
    Join Date
    Jan 2004
    Location
    Wheelersburg
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no one knows this?
    http://chaseschwalbach.com

  3. #3
    SitePoint Zealot
    Join Date
    Jan 2004
    Location
    Wheelersburg
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Got it guys:

    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');
    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>&nbsp;</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(!$name1) {
    $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'.$i.'" 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'.$i.'" class="texta" size="5"></td>
        <td width="5%" align="center"><input type="text" name="num'.$i.'" class="texta" size="4"></td>
        <td width="5%" align="center"><input type="text" name="g'.$i.'" class="texta" value="0" size="4"></td>
        <td width="5%" align="center"><input type="text" name="ab'.$i.'" class="texta" value="0" size="2"></td>
        <td width="5%" align="center"><input type="text" name="r'.$i.'" class="texta" value="0" size="2"></td>
        <td width="5%" align="center"><input type="text" name="h'.$i.'" class="texta" value="0" size="2"></td>
        <td width="5%" align="center"><input type="text" name="s'.$i.'" class="texta" value="0" size="2"></td>
        <td width="5%" align="center"><input type="text" name="2b'.$i.'" class="texta" value="0" size="2"></td>
        <td width="5%" align="center"><input type="text" name="3b'.$i.'" class="texta" value="0" size="2"></td>
        <td width="5% align="center""><input type="text" name="hr'.$i.'" class="texta" value="0" size="2"></td>
        <td width="5%" align="center"><input type="text" name="rbi'.$i.'" class="texta" value="0" size="2"></td>
        <td width="5%" align="center"><input type="text" name="bb'.$i.'" class="texta" value="0" size="2"></td>
        <td width="5%" align="center"><input type="text" name="er'.$i.'" class="texta" value="0" size="2"></td>
        <td width="5%" align="center"><input type="text" name="k'.$i.'" 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'];
    }
    echo($nump);
    for($i=1;$i<=$nump;$i++) {
    $name = $_POST['name'.$i];
    echo('HI');
    $position = $_POST['position'.$i];
    $num = $_POST['num'.$i];
    $g = $_POST['g'.$i];
    $ab = $_POST['ab'.$i];
    $r = $_POST['r'.$i];
    $h = $_POST['h'.$i];
    $s = $_POST['s'.$i];
    $twob = $_POST['2b'.$i];
    $thrb= $_POST['3b'.$i];
    $hr = $_POST['hr'.$i];
    $rbi = $_POST['rbi'.$i];
    $bb = $_POST['bb'.$i];
    $er = $_POST['er'.$i];
    $k = $_POST['k'.$i];
    $teamid = $_POST['teamid'];
    $sql=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($sql."=sql<br><br>");
    }
    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="20; URL=index.php">
    ');
    }
    } else {
    echo('Sorry only moderators can access this area');
    }
    
    ?>
    http://chaseschwalbach.com

  4. #4
    Fully Sweet Car noddy's Avatar
    Join Date
    Aug 2002
    Location
    Perth, Western Australia
    Posts
    759
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just a tip

    Instead of doing all this typing
    PHP Code:
      $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']; 
    just do this much easier

    PHP Code:
        foreach ($_REQUEST AS $key=>$value) {
          
    $param[$key] = $value;
        } 
    // emd foreach 

  5. #5
    SitePoint Zealot
    Join Date
    Jan 2004
    Location
    Wheelersburg
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what kind've output would that get me? Like what variables would be put in there for example?

    Thanks a bunch though.
    http://chaseschwalbach.com


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •