Reputation: 1
I am here again. I have lots of trouble but this is my main problem now.
I can successfully add dynamic rows to my html form then add it to my database. What I am doing now is, I retrieved the data, auto-populate my EDIT form. My problem is, I can't even add now to my table a row that already has 2 or 3 rows in it. What should I do? I just copy paste my code from my newform.php to editform.php. PLease help me. :(
Upvotes: 0
Views: 1218
Reputation: 1793
I don't know what is your code but One way to achieve it.
1.create fields having name with unique id of rows from table. and a hidden field combine with all unique ids associate with a character or string like =||=.
<input type ="text" name = "naame_1" id = "name_1" value = "test" />
<input type ="text" name = "naame_5" id = "name_5" value = "test1" />
<input type="hidden" name = "allids" id = "allids" value = "1=||=5" />
And now in PHP file
<?php
if(isset($_POST)){
$ids = explode("=||=" , $_POST['allids']);
foreach($ids As $id){
$query = "update tblename set fieldname = '".$_POST['name_'.$id]."' where id = ".$id;
mysql_query($query);
}
}
?>
Please try this , If this may helpful for you.
thanks
Upvotes: 0
Reputation: 1414
I think you are trying to do a CRUD(Create,Read,Update or EDIT,Delete) example using HTML/PHP.
If that is the case you can find many tutorials on googling.
Here is one which is quite good to start with. http://speckyboy.com/2011/02/17/getting-started-with-crud-in-php/
Hope it helps.Happy Coding
Upvotes: 1