www.webdeveloper.com
Results 1 to 3 of 3

Thread: update form array not working.

  1. #1
    Join Date
    Sep 2010
    Posts
    38

    update form array not working.

    Hi,

    My update form array does not work.



    I am trying to upload to two tables: matches and matchscores



    I need to upload to matchsores twice as it must hold information for two teams per match_id



    This is my HTML

    PHP Code:
           <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    
                    <td height="25" bgcolor="#000000" class="tableTextHeading"><div align="center">Date</div></td>
                    <td height="25" bgcolor="#000000" class="tableTextHeading"><div align="center">Home</div></td>
                    <td height="25" bgcolor="#000000" class="tableTextHeading"><div align="center">Score</div></td>
                    <td height="25" bgcolor="#000000" class="tableTextHeading"><div align="center">Away</div></td>
                    <td height="25" bgcolor="#000000" class="tableTextHeading"><div align="center">Kick-Off</div></td>
                    <td height="25" bgcolor="#000000" class="tableTextHeading"><div align="center">Venue</div></td>
                    <td height="25" bgcolor="#000000" class="tableTextHeading"><div align="center">Referee</div></td>
                    <td height="25" bgcolor="#000000" class="tableTextHeading"><div align="center">Update</div></td>
                  </tr>

                  <?php do { ?>
     <form action="<?php echo $editFormAction?>" method="POST" name="fixtures"> 
                    <tr>
                     
                      <td><div align="center"><span id="sprytextfield1">
                        <label>
                        <input name="date[]" type="text" class="date" size="8" style="text-align:center" value="<?php echo $row_match_fixtures['shortDate']; ?>" />
                        <span class="textfieldRequiredMsg">A value is required.</span>                            
                        </label>
                        </span></div></td>
                      <td><div align="center"><a href="match-player.php?id=<?php echo $row_match_fixtures['match_id']; ?>&team=<?php echo $row_match_fixtures['team1_id']; ?>"><?php echo $row_match_fixtures['team1_name']; ?></a></div></td>
                      <td><div align="center"><input name="s1[]" type="text" value="<?php echo $row_match_fixtures['score1']; ?>" size="1" style="text-align:center" /> 
                      v <input name="s2[]" type="text" value="<?php echo $row_match_fixtures['score2']; ?>" size="1" style="text-align:center" />
                      </div></td>
                      <td><div align="center"><a href="match-player.php?id=<?php echo $row_match_fixtures['match_id']; ?>&team=<?php echo $row_match_fixtures['team2_id']; ?>"><?php echo $row_match_fixtures['team2_name']; ?></a></div></td>
                      <td><div align="center"><span id="sprytextfield2">
                      <label>
                      <input name="time[]" type="text" size="3" value="<?php echo $row_match_fixtures['time']; ?>" style="text-align:center" />
                      </label>
                      <span class="textfieldInvalidFormatMsg">Invalid format.</span><span class="textfieldRequiredMsg">A value is required.</span></span></div></td>
                      <td><div align="center"><span id="spryselect1">
                        <label>
                        <select name="venue[]">
                          <?php
    do {  
    ?>
                          <option value="<?php echo $row_venue['venue_id']?>"<?php if (!(strcmp($row_venue['venue_id'], $row_venue['venue_name']))) {echo "selected=\"selected\"";} ?>><?php echo $row_venue['venue_name']?></option>
                          <?php
    } while ($row_venue mysql_fetch_assoc($venue));
      
    $rows mysql_num_rows($venue);
      if(
    $rows 0) {
          
    mysql_data_seek($venue0);
           
    $row_venue mysql_fetch_assoc($venue);
      }
    ?>
                        </select>
                        </label>
                        <span class="selectRequiredMsg">Please select an item.</span></span></div></td>
                      <td><div align="center"><span id="spryselect2">
                        <label>
                        <select name="referee[]">
                          <?php
    do {  
    ?>
                          <option value="<?php echo $row_referee['ref_id']?>"<?php if (!(strcmp($row_referee['ref_id'], $row_referee['sname']))) {echo "selected=\"selected\"";} ?>><?php echo $row_referee['fname']?> <?php echo $row_referee['sname']?></option>
                          <?php
    } while ($row_referee mysql_fetch_assoc($referee));
      
    $rows mysql_num_rows($referee);
      if(
    $rows 0) {
          
    mysql_data_seek($referee0);
           
    $row_referee mysql_fetch_assoc($referee);
      }
    ?>
                        </select>
                        </label>
                        <span class="selectRequiredMsg">Please select an item.</span></span></div></td>

                      <td><div align="center"><input name="Submit[]" type="submit" id="Submit" value="Save" /></div></td>

               
                    </tr>
             <input name="match_id[]" type="hidden" value="<?php echo $row_match_fixtures['match_id']; ?>" />
            <input name="mscore1[]" type="hidden" value="<?php echo $row_match_fixtures['mscore1']; ?>" />
            <input name="mscore2[]" type="hidden" value="<?php echo $row_match_fixtures['mscore2']; ?>" />
            <input name="team1_id[]" type="hidden" value="<?php echo $row_match_fixtures['team1_id']; ?>" />
            <input name="score1[]" type="hidden" value="<?php echo $row_match_fixtures['score1']; ?>" />
            <input name="team2_id[]" type="hidden" value="<?php echo $row_match_fixtures['team2_id']; ?>" />
            <input name="score2[]" type="hidden" value="<?php echo $row_match_fixtures['score2']; ?>" />
            
            <input type="hidden" name="MM_update" value="fixtures" />                  
    </form> 
                    <?php } while ($row_match_fixtures mysql_fetch_assoc($match_fixtures)); ?>
          
                </table></td>
              </tr>
            </table>
    PHP Code:
    $editFormAction $_SERVER['PHP_SELF'];
    if (isset(
    $_SERVER['QUERY_STRING'])) {
      
    $editFormAction .= "?" htmlentities($_SERVER['QUERY_STRING']);
    }

    if ((isset(
    $_POST["MM_update"])) && ($_POST["MM_update"] == "fixtures")) {
      
    $updateSQL sprintf("UPDATE matches SET `date`=%s, `time`=%s, referee_id=%s, venue_id=%s WHERE match_id=%s",
                           
    GetSQLValueString($_POST['date'], "date"),
                           
    GetSQLValueString($_POST['time'], "text"),
                           
    GetSQLValueString($_POST['referee'], "int"),
                           
    GetSQLValueString($_POST['venue'], "int"),
                           
    GetSQLValueString($_POST['match_id'], "int"));
                                
      
    $updateSQL sprintf("UPDATE matchscores SET match_id=%s, team=%s, score=%s WHERE matchscores_id=%s",
                           
    GetSQLValueString($_POST['match_id'], "int"),
                           
    GetSQLValueString($_POST['team1_id'], "int"),
                           
    GetSQLValueString($_POST['score1'], "int"),
                           
    GetSQLValueString($_POST['mscore1'], "int"));
                                
      
    $updateSQL sprintf("UPDATE matchscores SET match_id=%s, team=%s, score=%s WHERE matchscores_id=%s",
                           
    GetSQLValueString($_POST['match_id'], "int"),
                           
    GetSQLValueString($_POST['team2_id'], "int"),
                           
    GetSQLValueString($_POST['score2'], "int"),
                           
    GetSQLValueString($_POST['mscore2'], "int"));

      
    mysql_select_db($database_db$db);
      
    $Result1 mysql_query($updateSQL$db) or die(mysql_error());

      
    $updateGoTo "fixtures-edit.php";
      if (isset(
    $_SERVER['QUERY_STRING'])) {
        
    $updateGoTo .= (strpos($updateGoTo'?')) ? "&" "?";
        
    $updateGoTo .= $_SERVER['QUERY_STRING'];
      }
      
    header(sprintf("Location: %s"$updateGoTo));

    PHP Code:
    mysql_select_db($database_db$db);
    $query_match_fixtures "select m.match_id, date_format(m.date, '%W %D %M %Y') as mDate, date_format(m.date, '%d/%m/%Y') as shortDate, m.time, t1.team_id as team1_id, t1.division, m.report, t1.team_name as team1_name, s1.score as score1, t2.team_id as team2_id, t2.team_name as team2_name, s2.score as score2, v.venue_name, r.fname, r.sname, s1.matchscores_id as mscore1, s2.matchscores_id as mscore2 
    from matches m left join (matchscores s1 left join team t1 on t1.team_id = s1.team) on (s1.match_id = m.match_id) left join (matchscores s2 left join team t2 on t2.team_id = s2.team) on (s2.match_id = m.match_id) 
    LEFT JOIN referee r ON r.ref_id = m.referee_id LEFT JOIN venue v ON v.venue_id = m.venue_id
    where s1.team <> s2.team 
    group by match_id 
    order by m.match_id"
    ;
    $match_fixtures mysql_query($query_match_fixtures$db) or die(mysql_error());
    $row_match_fixtures mysql_fetch_assoc($match_fixtures);
    $totalRows_match_fixtures mysql_num_rows($match_fixtures); 
    Where am I going wrong?

  2. #2
    Join Date
    Sep 2010
    Posts
    38
    Can anyone tell me how to create a loop so that my form gets looped so that I have many of the same form?

    And then insert into two tables?
    I need to update one table and insert into two others

  3. #3
    Join Date
    Sep 2010
    Posts
    38
    I cannt seem to get this to work at all.
    Does anyone know a good tutorial or something that can help me?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles