AibZilla Posted May 25, 2012 Share Posted May 25, 2012 Hi I have a PHP script that enables a user to be able to add items onto the page and after pressing submit the user can get the items back to view what he/she has entered. I want to know if there is a way the user can retrieve the items entered with a checkbox next to them to mark the items as 'complete' when he is done with his task. This is a basic Todo list that I am creating, the user can already create items to do and receive them, I just want the items received to have a checkbox next to them. If anyone can help me I would greatly appreciate it, mind you I am fairly new to PHP so a good explanation would be valuable to me. Here is some code <?php // ERROR HANDLING if (isset($_GET['message'])) { $message = $_GET['message']; } else { $message = false; } // LIST MANANGEMENT require('includes/item-brains.php'); $itemMonster = new Items(); if (!empty($_POST)) { $itemMonster->CreateItem($_POST["new-item-label"],$_POST["new-item-list-id"]); } $existingItems = $itemMonster->GetAllItems($_GET["listid"]); ?> <html lang="en"> <head> <meta charset="utf-8"/> <title>ToitDoit</title> </head> <body> <?php if ($message) { echo '<p style="color: red;">'.$message.'</p>';} ?> <form action="/view-list.php?listid=<?php echo $_GET["listid"]; ?>" method="POST" name="item-creator"> <input type="text" name="new-item-label" value="" maxlength="100" /><label>Enter Item Name</label> <input type="hidden" name="new-item-list-id" value="<?php echo $_GET["listid"]; ?>"/> <br /> <input type="submit" value="Add New Item!"> </form> <ul class="existing-items"> <?php if (count($existingItems)) { foreach ($existingItems as $key => $value) { echo "<li>".$value['label'].' <a href="delete-item.php?itemid='.$value['id'].'">Delete</a> <a href="update-item.php?itemid='.$value['id'].'">Update</a></li>'; } } else { echo "<li>there are no items in DB</li>"; } ?> </ul> </body> </html> Link to comment https://forums.phpfreaks.com/topic/263131-how-to-get-checkboxes-after-entering-information-into-a-form/ Share on other sites More sharing options...
AibZilla Posted May 25, 2012 Author Share Posted May 25, 2012 bump Link to comment https://forums.phpfreaks.com/topic/263131-how-to-get-checkboxes-after-entering-information-into-a-form/#findComment-1348632 Share on other sites More sharing options...
Kays Posted May 25, 2012 Share Posted May 25, 2012 Please address all of the following: 1. Post the Items class. Redact all sensitive information. If it is really long, post it on pastie.org and provide the link. 2. What's in require('includes/item-brains.php');? Redact all sensitive information. If it is really long, post it on pastie.org and provide the link. 3. What is the value of $_GET['listid']? Link to comment https://forums.phpfreaks.com/topic/263131-how-to-get-checkboxes-after-entering-information-into-a-form/#findComment-1348642 Share on other sites More sharing options...
AibZilla Posted May 30, 2012 Author Share Posted May 30, 2012 item-brains.php <?php class Items { private $items = array(); private $mysql; private $database; function __construct(){ $this->mysql = mysql_connect('localhost','root',''); if (!$this->mysql) { echo 'no connection'; } $this->database = mysql_select_db('toitdoit',$this->mysql); } public function CreateItem($newItemLabel, $newItemListId) { if (!isset($newItemLabel) || $newItemLabel == '') { header('Location: /?message=Please provide a label fool'); exit; } if (!isset($newItemListId) || $newItemListId == '') { header('Location: /?message=Please provide a list Id FOOL!!!!'); exit; } $sql = "INSERT INTO `toitdoit`.`items` (`ItemId` ,`ListId`,`ItemLabel`) VALUES ( NULL,'".$newItemListId."' , '".$newItemLabel."')"; $result = mysql_query($sql); if (!$result) { die('Invalid query: ' . mysql_error()); } } public function UpdateItem($existingnewItemLabel,$newItemListId) { if (!isset($existingnewItemLabel) || $existingnewItemLabel == '') { header('Location: /update-item.php?itemid='.$newItemListId.'&message=Please provide a Item Id fool!!!!'); exit; } $sql = "UPDATE items SET `ItemLabel`='".$existingnewItemLabel."' WHERE `ItemId` = '".$newItemListId."'"; $result = mysql_query($sql); if (!$result) { die('Invalid query: ' . mysql_error()); } return mysql_affected_rows(); } public function DeleteItem($itemId) { $sql ="DELETE FROM `toitdoit`.`items` WHERE ItemId = ".$itemId; $result = mysql_query($sql); return mysql_affected_rows(); } public function GetAllItems($newListId) { $sql = "SELECT * FROM `items` WHERE `ListId`= ".$newListId." LIMIT 0,30"; $result = mysql_query($sql); if (!$result) { die('Invalid query: ' . mysql_error()); } while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $row = array('label'=>$row['ItemLabel'],'id'=>$row['ItemId']); array_push($this->items,$row); } return $this->items; } public function GetItemLabelByItemID($itemId) { $sql = "SELECT `ItemLabel` FROM `items` WHERE `ItemId` = ".$itemId." LIMIT 0,30"; $result = mysql_query($sql); if (!$result) { die('Invalid query: ' . mysql_error()); } $labels = mysql_fetch_array($result, MYSQL_ASSOC); return $labels['ItemLabel']; } public function GetListIdByItemID($itemId) { $sql = "SELECT `ListId` FROM `items` WHERE `ItemId` = ".$itemId." LIMIT 0,30"; $result = mysql_query($sql); if (!$result) { die('Invalid query: ' . mysql_error()); } $labels = mysql_fetch_array($result, MYSQL_ASSOC); return $labels['ListId']; } public function CompleteItem ($isComplete, $itemId) { $sql = "SELECT `IsComplete` FROM `items` WHERE `ItemId` = ".$itemId." LIMIT 0,30"; if ($isComplete == $itemId); echo Is complete } } ?> Link to comment https://forums.phpfreaks.com/topic/263131-how-to-get-checkboxes-after-entering-information-into-a-form/#findComment-1349806 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.