OK, here's the problem. I've got a form with an unknown number of text fields on it. I know how many there are by storing the DB id's of each record in a hidden field and exploding that. I can (should) access the $_POST variable to get each text value corresponding to an ID. So here's the code: $ids=$_POST['ids']; $ids=explode(" ",$ids); if (strlen($ids[0] != 0)) { for ($i=0;$i<count($ids);$i++) { $key='note_'.$ids[$i]; $note_text=$_POST[$key]; //Just some escaping stuff for SQL Server $note_text=str_replace($note_text,"\'","''"); $sql="UPDATE kanbans set note='".$note_text."' WHERE id=".$ids[$i]; echo $sql."<br>"; //@mssql_query($sql); } } Code (markup): The trouble is, the $_POST[$key] is returning an empty string. However, it works fine if I index the $_POST directly using: $test=$_POST['note_117']; //echo "Test ".$test."<br>"; $test=$_POST['note_116']; //echo "Test ".$test."<br>"; Code (markup): The concatenating of the id's to the note_ is working fine as the sql string looks just fine. Anyone got any idea what's going on here?
Looks like your str_replace parameters are in the wrong order. try: $note_text = str_replace("'","''",$note_text); Code (markup):
Nahh.. I've done that before.. Its hard to remember sometimes with PHP functions which comes first... some PHP functions have the source string first, some last...
I think you are not getting the array of Id in the second page. Try but just looping through the id array only. If you are collecting the ids from db then you can get that value in the second page also from the db so no need to get them through the form. ( or I am missing something here ) There are many situations where we don't know the number of input boxes we will populate , so in that case best is to use the input box as an array. Here is one example of check boxes ( not input boxes in your case ) and result is received as array and that we can loop through. ( external URLs not allowed in my post so one example of check box posting here) <input type=checkbox name=box[] value='112'> <input type=checkbox name=box[] value='117'> Not sure it helps or I made it more complex for you
the problem is evident there. you are using, $_POST[$key] which will be substituted as $_POST[note_117] and not $_POST['not_117'] , got it? use $_POST['$key'] instead.
No, the first guy had it, parameters in wrong order for str_replace. Everything else works perfectly.