dirkobrien56 Posted October 5, 2009 Share Posted October 5, 2009 SO i have form page test.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head profile="http://gmpg.org/xfn/11"> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <title>Here 9is title</title> <link rel="stylesheet" href="style.css" type="text/css" media="screen" /> <script language=\"javascript\"> function absenden(p) { document.form1.variable.value = p; document.form1.submit; } </script> </head> <body> <div id="pagecenter"> <div style="margin-left:100px; margin-top:40px; margin-bottom:30px;"> <a href="link.php"><img src='image.png' alt="alt" /></a> </div><br /> <div id="header"> <div class="menulinks"> <ul> <li> <a href="link2.php">Linktext</a> </li> </ul> </div> </div> <div class="topicheader" style="margin-top:90px">Text</div> <?php echo '<form id="form1" name="form1" method="post" action="timer.php">'; $i=0; $handle = fopen ("file.csv","r"); while ( ($data = fgetcsv ($handle, 1000, ",")) !== FALSE ) { $i++; } fclose ($handle); echo "<div class='topicbody'>"; echo '<input type="text" name="name'.$i.'" id="id" value="" size="80"/>'; echo '<input type="text" name="name1'.$i.'" id="id" value="" size="2"/>'; echo '<input type="hidden" name="timer" id="id" value="'.$i.'" size="10"/>'; echo '<input type="submit" class="submit" value="Submit"/>'; echo "<div class='clear'></div></div>"; $i=0; $handle = fopen ("file.csv","r"); echo '<div class="topicheader">Edit or delete</div>'; while ( ($data = fgetcsv ($handle, 1000, ",")) !== FALSE ) { $name = $data[0]; $name1 = $data[1]; echo "<div class='class'>"; echo '<input type="text" name="name'.$i.'" id="id" value="'.$name.'" size="80"/>'; echo '<input type="text" name="name1'.$i.'" id="id" value="'.$name1.'" size="2"/>'; echo '<input type="submit" class="edit" value="Edit"/>'; echo '<button class="delet" name="action" value="'.$i.'">Delete</button>'; echo "<div class='clear'></div></div>"; $i++; } fclose ($handle); echo '</form>'; ?> </body> </html> timer.php <?php $del = "blub"; $del = $_POST[action]; $timer = $_POST[timer]; $fh = fopen("file.csv", "w"); while($timer >= 0) { if($del != "" && $del == $timer){$timer--; continue;}; $name = $_POST[name.$timer]; $name1 = $_POST[name1.$timer]; $line = '"'.$name.'",'.$name1.''."\r\n"; if($name != "" && $name1) { fputs($fh, $line); }; $timer--; }; fclose($fh); echo ' <html> <head> <script language="JavaScript"> function next() { document.location.href="test.php"; } </script> </head> <body onload="next()"> </body> </html>'; ?> If i click submit then it generates new field with inserted values with edit and delete buttons but edit creates new field with default values instead editing it and delete deletes values but not field what im doing wrong it drives me crazy. Link to comment https://forums.phpfreaks.com/topic/176530-edit-delete-form/ Share on other sites More sharing options...
kickstart Posted October 5, 2009 Share Posted October 5, 2009 Hi Your form appears to call the timer script which doesn't then pass through any fields to the main script to be processed. You also appear to have multiple fields which will have the same id (eg, the name and name1 fields). All the best Keith Link to comment https://forums.phpfreaks.com/topic/176530-edit-delete-form/#findComment-930571 Share on other sites More sharing options...
dirkobrien56 Posted October 5, 2009 Author Share Posted October 5, 2009 Yea i know that ids are same its easy to change but i dont get why it wont let me edit or delete inserted data with field i have another script with same function and everything works fine. Link to comment https://forums.phpfreaks.com/topic/176530-edit-delete-form/#findComment-930584 Share on other sites More sharing options...
kickstart Posted October 5, 2009 Share Posted October 5, 2009 Hi Bit clearer what you are trying to do now. You save the fields to a csv file, but you do not save whether delete (or which delete) or submit has been pressed. You appear to try and ignore deleted records in the timer script which should work OK. However you do not have inverted commas around the field names:- $del = $_POST['action']; All the best Keith Link to comment https://forums.phpfreaks.com/topic/176530-edit-delete-form/#findComment-930606 Share on other sites More sharing options...
dirkobrien56 Posted October 5, 2009 Author Share Posted October 5, 2009 OK $del = $_POST['action']; fixed $timer = $_POST['timer']; fixed changed id to class still no luck By the way im net really good with php so its hard to find wheres mistake. And also im not native english speaker so difficult to explain what im trying to do. For now if i push edit it generates new field with default values (default values are empty it should change value to newly entere value) if i press delete id deletes values from fields and from csv (it should delete it with field) By the way thanks for helping trying to learn this stuff Link to comment https://forums.phpfreaks.com/topic/176530-edit-delete-form/#findComment-930612 Share on other sites More sharing options...
kickstart Posted October 5, 2009 Share Posted October 5, 2009 Hi There are also these 2:- $name = $_POST['name'.$timer]; $name1 = $_POST['name1'.$timer]; I suspect that what has happened is that with the ' missing from the above assignments it has put nothing into $name and $name1, and has then written those empty fields (separated with a ,) to the csv file. Your 2nd script has then read the CSV file and knows that each line represents a name / name1 pair, in order. So it has taken the blank values and output them into the form fields. Out of interest, why are you splitting up the processing into 2 separate scripts? All the best Keith Link to comment https://forums.phpfreaks.com/topic/176530-edit-delete-form/#findComment-930619 Share on other sites More sharing options...
dirkobrien56 Posted October 5, 2009 Author Share Posted October 5, 2009 Ok $name = $_POST['name'.$timer]; fixed $name1 = $_POST['name1'.$timer]; fixed Out of interest, why are you splitting up the processing into 2 separate scripts? I hate scrolling Now if i write data to textfield and push edit it generates new field with that data and writes data to csv. Delete still turns data to default values. Link to comment https://forums.phpfreaks.com/topic/176530-edit-delete-form/#findComment-930626 Share on other sites More sharing options...
kickstart Posted October 5, 2009 Share Posted October 5, 2009 Hi Just tried it on my machine and it appears to work. The delete button drops a row, but all other rows keep their values. All the best Keith Link to comment https://forums.phpfreaks.com/topic/176530-edit-delete-form/#findComment-930643 Share on other sites More sharing options...
dirkobrien56 Posted October 5, 2009 Author Share Posted October 5, 2009 Strange why it wont work for me? Link to comment https://forums.phpfreaks.com/topic/176530-edit-delete-form/#findComment-930646 Share on other sites More sharing options...
kickstart Posted October 5, 2009 Share Posted October 5, 2009 Hi Can you repost your code, just in case you have changed something else by mistake? All the best Keith Link to comment https://forums.phpfreaks.com/topic/176530-edit-delete-form/#findComment-930648 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.