kelliethile Posted May 6, 2010 Share Posted May 6, 2010 I have been following tutorials from learningnerd.com, to do this to do list management program. I'm struck with delete function. Can someone proof-read my codes and see if I'm doing something wrong? Everything works okay, like adding elements to list, but to delete it off list is my problem. Also, here's the tut url: http://www.learningnerd.com/phpmysql-day-4 <html> <head> <title>Add to list</title> </head> <body> <form method="post" action="try.php"> <label for="item">Add item to list: </label> <input type="text" name="item" id="item" size="30"> <br /> <label for="tag">Tag it: </label> <input type="text" name="tag" id="tag" size="15"> <br /> <input type="submit" value="Add to list" /> </form> <?php // Connecting, selecting database $link = mysql_connect('localhost', 'root', 'whatever') or die('Could not connect: ' . mysql_error()); echo 'Connected successfully'; mysql_select_db('try_db') or die('Could not select database'); // Inserting data if (isset($_POST['item'])) { $item = mysql_real_escape_string($_POST['item']); $tag = mysql_real_escape_string($_POST['tag']); // Performing SQL query $query = "INSERT INTO try_table (item, tag) VALUES ('$item', '$tag')"; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); } ?> <?php if(isset($_POST['done'])) { $done = implode(', ', $_POST['done']); $deletequery = "DELETE FROM try_table WHERE id IN ($done)"; $resultdelete = mysql_query($deletequery) or die(mysql_error()); } ?> <h2>Things To Do</h2> <?php // Selecting the data $resultselect = mysql_query('SELECT * FROM try_table'); // Fetching and displaying data while($row = mysql_fetch_array($resultselect)) { ?> <input type="checkbox" name="done[]" id="<?php echo $row['id'] ?>" value ="<?php echo $row['id'] ?>" /> <label for="<?php echo $row['id'] ?>"> <?php echo $row['item'] . ' - tagged ' . $row['tag'];?> </label> <br /> <?php } ?> <input type="Submit" value = "Mark Items Complete" /> </form> </body> </html> please help Quote Link to comment https://forums.phpfreaks.com/topic/200883-to-do-list-delete-function/ Share on other sites More sharing options...
phpchamps Posted May 6, 2010 Share Posted May 6, 2010 You have missed the form tag for deleting the item... put the following line just below "<h2>Things To Do</h2>" line... <form method="post" action="try.php"> Quote Link to comment https://forums.phpfreaks.com/topic/200883-to-do-list-delete-function/#findComment-1054069 Share on other sites More sharing options...
kelliethile Posted May 6, 2010 Author Share Posted May 6, 2010 thanks phpchamps! Quote Link to comment https://forums.phpfreaks.com/topic/200883-to-do-list-delete-function/#findComment-1054071 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.