Jump to content

To-do list delete function


kelliethile

Recommended Posts

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  :shy:

Link to comment
https://forums.phpfreaks.com/topic/200883-to-do-list-delete-function/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.