php - insert query not working more than 20 times -
i using html , php save data in database unfortunately insert query not executed not more 20 times. in web interface have created row of input fields name, father name , 1 pdf file uploading. there 2 buttons @ bottom, 1 button used adding 1 more row of fields , other saving. code working 100% fine when user enters not more 20 records when user enters more 20 records insert query executed 20 times, , rest of records ignored. here sample code
html code
<td height="30"><input type="text" name="a[]" size="5" /></td> <td><input type="text" name="b[]" size="10" /></td> <td><input type="text" name="c[]" size="40" /></td> <td><input type="text" name="d[]" size="10" /></td> <td><input type="text" name="e[]" size="10" /></td> <td><input type="text" name="f[]" size="10" /></td> <td><input type="text" name="g[]" class="datepick" id="exdate" size="15" onclick="function()"/></td> <td><input type="file" name="h[]" size="15" id="file" accept="application/msexcel, application/msword, application/pdf, image/gif, image/png, image/jpg, image/jpeg" />
php code
$recs = count($_post["a"]); for($i = 0; $i <= $recs - 1; $i++) { $a = $i + 1; $file_name = $_files["file"]["name"][$i]; $ext = strrchr($file_name, "."); $path = "bb/".$newname."-".$a.$ext; $status = 1; $date = date("y-m-d",strtotime($_post["ex"][$i])); $query = "insert abc (a,b,c,d,e,f,g,g,i,j,k) values ( '".$_post["a"][$i]."', '".$_post["b"][$i]."', '".$_post["c"][$i]."', '".$_post["d"][$i]."', '".$newname."', '".$_post["e"][$i]."', '".$path."', '".$f."', '".$_post["g"][$i]."', '".$date."', '".$h."' );"; mysql_query($query) or die("mistake in query"); move_uploaded_file($_files["file"]["tmp_name"][$i], $path); } } header("location: save.php?saved=true"); }
i unable understand whether there default size of input box restricting or there mistake in php code
your code has multiple flaws:
$f
,$h
not being set- you inserting
(a,b,c,d,e,f,g,g,i,j,k)
. noticeg
there twice. - you don't escape input, making apostrophe
'
in of fields break code. usemysql_real_escape_string()
... or better yet, don't usemysql_
functions @ all, rather usemysqli_
functions orpdo
functions. - uploading many files hit max post value set php and/or webserver. (check values in php.ini , httpd.conf if using apache.)
Comments
Post a Comment