1

I have table player_points with player_name, runs, sixes, match_no, fiftys, hundreds, point_scored.

I make form with above fields where i insert runs and sixes and calculate fiftys, hundreds and point_scored using runs & sixes, give extra 10 points for every sixex after 3 six. Its works properly but when i insert runs and sixes and save it only shows calculation in fiftys, hundred and point-scored textbox not saved into database table. After i saved it second time its save into database. My code is like below:

<tr><td colspan="9"><hr style="border:1px #999 dashed;"></td></tr>
 <tr>
  <th>Player</th>
  <th>Status</th>
  <th>Runs</th>
  <th>6's</th>
  <th>50's</th>
  <th>100's</th>
  <th>TP</th>
  <th>Action</th>
 </tr>
 <tr><td colspan="9"><hr style="border:1px #999 dashed;"></td></tr>

<?php   
        $classObj->getPlayerPointTable();
        //$matchid = $_GET['mid'];
        $condpl = "player_name='".$player1."' AND match_no = '".$matchid."'";                           
        $resultpl = $classObj->selectSql($condpl);
        //$recordcount = $classObj->getAffectedRows($result);
        $rowpl = $classObj->fetchData($resultpl);

        foreach($rowpl as $rowspl)
        {
          $Status1 = $rowspl['status'];
          $runs1 = $rowspl['run_scored'];
          $sixes1 = $rowspl['sixs'];
          $fifty1 = $rowspl['fifty'];
          $hundred1 = $rowspl['hundred'];
          $total_score1 = $rowspl['Total_Score'];
          $total_points1 = $rowspl['point_scored'];
          $firstPoint1 = $rowspl['FirstPoint'];
          $allocation1 = $rowspl['allocation'];
        }
?>

<?php 
$bonus1 = 10;
$bonus2 = 20;
$bonus3 = 25;
$bonus4 = 50;
/*condition for fifty 0 & 1 start */
if ($runs1 >= 50 && $runs1 <= 99 || $runs1 >= 150 && $runs1 <= 199 || $runs1 >= 250 && $runs1 <= 299) {
    $fifty1 = 1;
} else {
    $fifty1 = 0;
}

if ($runs1 >= 50 && $runs1 <= 499) {
    $tfif1 = $runs1 + $bonus3;
} else {
    $tpor1 = $runs1;
}
/*condition for fifty 0 & 1 end */
/*condition for hundred 0 & 1 start */
if ($runs1 >= 100 && $runs1 <= 199) {
    $hundred1 = 1;
} 
else if ($runs1 >= 200 && $runs1 <= 299) {
    $hundred1 = 2;
} 
else {
    $hundred1 = 0;
}
/*condition for hundred 0 & 1 end */


/*Condition start for Six excess to 3 sixes*/
$i1 = $sixes1 - 3;
if($i1 >= 1 && $i1 <= 500)
{
    $tsix1 = $i1 * $bonus1;
}
else
{
    $tsix1 == 0;
}
/*Condition start for Six excess to 3 sixes*/

if($fifty1 == 1 && $hundred1 >= 1)
{
    $tsixhnrd1 += $bonus4;
}
/*condition for hundred 0 & 1 end */

if ($runs1 >= 100 && $runs1 <= 500) {
    $trun1 += $bonus3;
}
    $total_points1 = $tfif1+$tsix1+$tsixhnrd1+$trun1+$tpor1;
    $total_score1 = $runs1;    

/*veriable for Balling team database insertions end*/
?>

 <form enctype="multipart/form-data" method="post" name="formA1">
 <tr>
  <td><div style="width:auto;padding-left:7px;font-size:17px;"><?php echo $player1;?></div>
   <input type="hidden" name="player1" id="player1" value="<?php echo $player1;?>" />
   <input type="hidden" name="matchid" id="matchid" value="<?php echo $matchid;?>" />
  </td>
  <?php 
    if($Status1=='P'){
  ?>
  <td align="center">   
   <select id='status1' name='status1' onChange="dis_ableA1(this)">
     <option value='NP'>NP</option>
     <option value='P' selected>P</option>
     <option value='O'>Out</option>
   </select>
  </td>
  <td align="center">
   <input type="text" onkeypress="return blockNonNumbers(this, event, false, false);" style="width:50px;height:25px;text-align:right;background:#f5c0c0;" name="runs1" id="runs1" value="<?php echo $runs1;?>" size="3" maxlength="3" />
  </td>
  <td align="center">
   <input type="text" onkeypress="return blockNonNumbers(this, event, false, false);" style="width:30px;height:25px;text-align:right;background:#f5c0c0;" name="sixes1" id="sixes1" value="<?php echo $sixes1;?>" size="2" maxlength="2" />
  </td>
  <?php 
    } else if($Status1=='O'){
  ?>
  <td align="center">   
   <select id='status1' style="width:50px;height:25px;" name='status1' onChange="dis_ableA1(this)">
     <option value='NP'>NP</option>
     <option value='P'>P</option>
     <option value='O' selected>Out</option>
   </select>
  </td>
  <td align="center">
   <input type="text" onkeypress="return blockNonNumbers(this, event, false, false);" style="width:50px;height:25px;text-align:right;background:#ccc;" disabled name="runs1" id="runs1" value="<?php echo $runs1;?>" size="3" maxlength="3" />
  </td>
  <td align="center">
   <input type="text" onkeypress="return blockNonNumbers(this, event, false, false);" style="width:30px;height:25px;text-align:right;background:#CCC;" disabled name="sixes1" id="sixes1" value="<?php echo $sixes1;?>" size="2" maxlength="2" />
  </td>
  <?php } else { ?>
  <td align="center"> 
   <select id='status1' style="width:50px;height:25px;" name='status1' onChange="dis_ableA1(this)" tabindex="1">
     <option value='NP'>NP</option>
     <option value='P'>P</option>
     <option value='O'>Out</option>
   </select>
  </td>
  <td align="center">
   <input type="text" onkeypress="return blockNonNumbers(this, event, false, false);" style="width:50px;height:25px;text-align:right;" name="runs1" disabled id="runs1" value="<?php echo $runs1;?>" size="3" maxlength="3" />
  </td>
  <td align="center">
   <input type="text" onkeypress="return blockNonNumbers(this, event, false, false);" style="width:30px;height:25px;text-align:right;" name="sixes1" disabled id="sixes1" value="<?php echo $sixes1;?>" size="2" maxlength="2" />
  </td>
  <?php }?>
  <td align="center">
   <label style="width:30px;height:25px;text-align:right;"><?php echo $fifty1;?></label>
   <input style="width:30px;height:25px;text-align:right;" type="hidden" id="fifty1" name="fifty1" value="<?php echo $fifty1;?>" size='2' maxlength='2' />
  </td>
  <td align="center">
   <label style="width:30px;height:25px;text-align:right;"><?php echo $hundred1;?></label>
   <input style="width:30px;height:25px;text-align:right;" type="hidden" id="hundred1" name="hundred1" value="<?php echo $hundred1;?>" size='2' maxlength='2' />
  </td>

  <td align="center">
   <label style="width:30px;height:25px;text-align:right;"><?php echo $total_points1;?></label>
   <input style="width:30px;height:25px;text-align:right;" type="hidden" id="total_points1" name="total_points1" value="<?php echo $total_points1;?>" size='5' maxlength='5' />
   <input type="hidden" name="allocation1" id="allocation1"  value="pending" />
  </td>
  <?php 
    if($Status1=='P'){
  ?>
  <td align="center">
   <input type="submit" name="submitA1" id="submitA1" value="Save" />
  </td>
  <?php } else { ?>
  <td align="center">
   <input type="submit" disabled="disabled" name="submitA1" id="submitA1" value="Save" />
  </td>
  <?php } ?>
 </tr>
 </form>
 <tr><td style="height:5px"></td></tr>
<!-- Insert Code Starts Submit1-->
<?php 
 if(isset($_POST['submitA1']))
 {
    $classObj->getPlayerPointTable();
    $matchid = $_GET['mid'];
    $cond = "player_name='".$player1."' AND match_no = '".$matchid."'";                         
    $result = $classObj->selectSql($cond);
    $count = $classObj->getAffectedRows($result);
    //echo $count;
    if($count > 0)
    {
        $player1up['status'] = $postedData['status1'];
        //$player1up['player_name'] = $postedData['player1'];
        $player1up['run_scored'] = $postedData['runs1'];
        $player1up['sixs'] = $postedData['sixes1'];
        $player1up['fifty'] = $postedData['fifty1'];
        $player1up['hundred'] = $postedData['hundred1'];
        $player1up['Total_Score'] = $postedData['total_score1'];
        $player1up['point_scored'] = $postedData['total_points1'];
        $player1up['allocation'] = $postedData['allocation1'];
        $player1up['FirstPoint'] = $postedData['total_points1'];
        $classObj->getPlayerPointTable();
        $classObj->userPostedData = $player1up;
        $cond = "match_no= '".$matchid."' AND player_name='".$player1."'";
        $insert_query = $classObj->updateData($cond);

          echo "<script> alert ('Player 1 update successfully.')</script>";
          echo "<script>window.location='FirstIn.php?mid=$matchid'</script>";
    }
    else if($count <= 0)
    { 
        $player['player_name'] = $postedData['player1'];
        $player['match_no'] = $postedData['matchid'];
        $player['status'] = $postedData['status1'];
        $player['run_scored'] = $postedData['runs1'];
        $player['sixs'] = $postedData['sixes1'];
        $player['fifty'] = $postedData['fifty1'];
        $player['hundred'] = $postedData['hundred1'];
        $player['Total_Score'] = $postedData['total_score1'];
        $player['point_scored'] = $postedData['total_points1'];
        $player['FirstPoint'] = $postedData['total_points1'];

        $classObj->userPostedData = $player;
        $insert_query = $classObj->insertData();

            if($insert_query == 'success')
            {
            echo "<script> alert('Player 1 score added.')</script>";
            echo "<script>window.location='score.php?mid=$matchid'</script>";
            }
    }
    else
    {
    echo "<script> alert ('Error Occured')</script>";
    }

 }  
?>

1 Answer 1

1

Assuming that your class' getAffectedRows() method really fetches the affected rows from the last statement, it must be noted that a SELECT does not set this, it will be zero.

If you want to know how many lines were selected, use something like mysqli_num_rows.

Sign up to request clarification or add additional context in comments.

2 Comments

It works, i echo that count. It save runs and sixes values in one click into database, but remaining fields saved after second click.
Then I have a problem understanding your problem description.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.