0

I wanted to update multiple records but I did not because this code updates only 99 rows. After 99 rows it will not update anything. I do not understand what is the problem in this code and where the limit is set in my code. Here is the code:

<?php
    if(isset($_POST['Submit']))
    {
    $count=count($_POST["id"]);

    for($i=0;$i<$count;$i++){

    $id= $_POST['id'][$i];
    $id2= $_POST['id2'][$i];
    $ird = $_POST['ird'][$i];
    $task_desp = $_POST['task_desp'][$i];
    $department = $_POST['department'][$i];
    $asigned = $_POST['asigned'][$i];
    $qty = $_POST['qty'][$i];
    $qty2 = $_POST['qty2'][$i];
    $persent = $_POST['persent'][$i];
    $frmdate = $_POST['frmdate'][$i];
    $todate = $_POST['todate'][$i];

    $sql="UPDATE sow2 SET id2='$id2',ird='$ird',task_desp='$task_desp', department='$department',asigned='$asigned', qty='$qty', qty2='$qty2', persent='$persent', frmdate='$frmdate', todate='$todate' WHERE id='$id'";

    $result = $con->query($sql);

    $status = "Record Updated Successfully. </br></br>";
    echo '<p style="color:#FF0000;">'.$status.'</p>';

    }
    }

    ?>
Daniel
  • 2,355
  • 9
  • 23
  • 30
user1833487
  • 145
  • 2
  • 13
  • I do not want to get into this extremely bad code code on any aspect, but please read about clean code and security. Apart from that: Have you tried executing your SQL Query directly without PHP? – DerStoffel Sep 29 '18 at 09:23
  • yes i tried SQL Query directly it was update – user1833487 Sep 29 '18 at 09:26
  • what is the result of $count=count($_POST["id"]);? Please please do not deploy this code on a public server. You are open to any kind of sql injections. – DerStoffel Sep 29 '18 at 09:27
  • yes i know it is not on public server – user1833487 Sep 29 '18 at 09:30
  • what is the result of $count=count($_POST["id"]);? Does every id exist in your db? That should help you find your solution. – DerStoffel Sep 29 '18 at 09:31
  • this $count=count($_POST["id"]); is counting number of rows – user1833487 Sep 29 '18 at 09:41
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/180983/discussion-between-derstoffel-and-user1833487). – DerStoffel Sep 29 '18 at 09:44
  • code works fine, chat shows he only puts in 99 rows to update... – DerStoffel Sep 29 '18 at 10:07
  • no i am not put 99 rows in anywhere finally i got solution – user1833487 Sep 29 '18 at 12:55
  • well, the answer you wer given below, states that you should have a look at max-input-vars, which you did. So please upvote the answer. Also, you DID limit the Input. Just not knowingly. So it still remains: Your code works fine, you only put in a limited amount of rows. – DerStoffel Sep 30 '18 at 20:18

2 Answers2

1

This code is not secure, You need to prevent SQL injection first:

How can I prevent SQL injection in PHP?

I would also suggest to create transaction to make it faster and more reliable.

The problem might be connected with max_input_vars , it's a limit for form variables number. http://www.php.net/manual/en/info.configuration.php#ini.max-input-vars

Check if there are records with it's You are trying to send, you can update only rows with existing id's

0

i am using godaddy hosting and godaddy not allow to submit more than 90 rows

here is the solution

make .htaccess php_value max_input_vars 10000

user1833487
  • 145
  • 2
  • 13