Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8692197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:16:19+00:00 2026-06-13T00:16:19+00:00

I am running while loop and fetch 3 records from database. and then update

  • 0

I am running while loop and fetch 3 records from database. and then update it on same page. Every record have submit button. But after edit when i submit the form it catchs the values of last record only and update other rows with the last record values. Please if somebody help me out i’ll be very thankful. Remember it catches the exact (id) but the other parameters are only of last row.

<form method="post" action="">
    <table width="700" border="1">
       <tr><th><?php echo $_SESSION['teamtwo']; ?></th></tr>
       <tr>
         <th>Player Name</th>
         <th>Runs</th>
         <th>Edit</th>
         <th>Save</th>
       </tr>
       <?php
        $team = new DBConnection();
        $condition = "WHERE teamname = '".$_SESSION['teamtwo']."' and datecreated = CURDATE()";
        $sel_player = $team->SelectRecord(array("*"),"`match`","$condition");
        //$sel_player = mysql_query("SELECT * FROM `match` WHERE teamname = '$team1' and datecreated = CURDATE()") or die(mysql_error());
        while($get_player = mysql_fetch_array($sel_player))
        {
        $totalruns = $get_player['runs_bat'];
        $totalballs = $get_player['ball_bat'];
        @$strike = $totalruns / $totalballs * 100; 
        ?>
        <tr>
          <td><input type="text" name="player_name" value="<?php echo $get_player['player_name']; ?>" disabled="disabled" /></td>
           <td><input type="text" name="runs" value="<?php echo $get_player['runs_bat']; ?>" size="1" /></td>

           <td><button><a href="?player=<?php echo $get_player['id']; ?>">Edit</a></button></td>
           <td><input type="submit" value="Save" name="team" /></td>
             </tr>
         <?php 
        } ?>
     </table>
   </form>
<?php } ?>
 </div>
 </div>
</body>
</html>
<?php

    if(isset($_POST['team'])){
        $runs = $_POST['runs'];
        $balls = $_POST['ball'];




        $object = new DBConnection();
        $arr_Field=array("runs_bat","ball_bat","player_status","how_out","opposite_bowl","opposite_player","sr","overs","bowl_ball","runs_ball","extra","madien");
        $arr_Values=array("$runs","$balls","$status","$how_out","$opposite_bowler","$opposite_player","$sr","$over","$bowls","$score","$extra","$madien");
        $condition = "WHERE id = '".$_REQUEST['player']."'";
        //echo $_REQUEST['player'];

        //echo $runs.$balls;

        $object->UpdateRecord("`match`",$arr_Field,$arr_Values,"$condition") or die(mysql_error());
        //header("Location:extra.php?update");


    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T00:16:20+00:00Added an answer on June 13, 2026 at 12:16 am

    the problem is you are having one form and when you submit the form it will submit the last rows values because you are having same name for all 3 rows inside 1 form.

    Solution:-

    Create form element inside the while loop and close it inside the while loop itself . Like this you will have 3 forms each for 3 rows.

    Code Example:-

        while($get_player = mysql_fetch_array($sel_player))
        {
        $totalruns = $get_player['runs_bat'];
        $totalballs = $get_player['ball_bat'];
        @$strike = $totalruns / $totalballs * 100; 
        ?>
        <form>
        <tr>
          <td><input type="text" name="player_name" value="<?php echo $get_player['player_name']; ?>" disabled="disabled" /></td>
           <td><input type="text" name="runs" value="<?php echo $get_player['runs_bat']; ?>" size="1" /></td>
    
           <td><button><a href="?player=<?php echo $get_player['id']; ?>">Edit</a></button></td>
           <td><input type="submit" value="Save" name="team" /></td>
        </tr>
        </form>
         <?php 
        } ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a while loop running that is returning values from a MYSQL table.
I'm running a while loop reading each line in a file, and then fork
I'm running a while loop to print certain data from a table. Because the
In PHP I'm using mysqli_fetch_assoc() in a while-loop to get every record in a
while running: rake snorby:setup getting below error: rake aborted! You have already activated rake
While running code in production, I don't have to interact with the Ember.js runloop
Let's say I have this piece of code running inside a loop where $fid
I'm running a while loop to get the most recent message of each conversation,
I have a table setup in my database with this structure: I have running
I have a table of prices. I am running a simple while function to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.