
AibZilla
Members-
Posts
19 -
Joined
-
Last visited
Never
Profile Information
-
Gender
Not Telling
AibZilla's Achievements

Newbie (1/5)
0
Reputation
-
Deleting a list and telling user Delete was successful!
AibZilla replied to AibZilla's topic in PHP Coding Help
*When the delete button is pressed the list does delete but does not show the message delete successful, this is what i'm trying to do is recieve the message. Anyone know what i'm doing wrong? -
Deleting a list and telling user Delete was successful!
AibZilla replied to AibZilla's topic in PHP Coding Help
How can I grab the code I already have and make it echo in my index.php after a list is deleted successfully? -
Hi, I have created an application where a user can create, delete, and update lists. These functions are working fine except I want to echo a message that tells the user once hes deleted a a message that his delete was successful. I've already made some code but nothing seems to be echoing out.. here it is. delete-list.php <?php require('includes/list-brains.php'); if (isset($_GET["listid"])) { $listMonster = new Lists(); $deleteResult = $listMonster->DeleteList($_GET["listid"]); if ($deleteResult) { // return to list page with success message header("Location: /index.php?message=Deleted List"); } else { // return to list page with failure message header("Location: /index.php?message=Sorry No Dice"); } } else { header('Location: /'); } ?> Here is list-brains.php public function DeleteList($listId) { $sql2 ="DELETE FROM `toitdoit`.`lists` WHERE ListId = ".$listId; $result2 = mysql_query($sql2); $DeleteSuccessful = mysql_affected_rows(); if ($DeleteSuccessful) { $sql1 = "DELETE FROM `toitdoit`.`items` WHERE ListId = ".$listId; $result1 = mysql_query($sql1); } return $DeleteSuccessful; } how can i have the message be echoed to my index page when the list is deleted??
-
Bump, can anyone solve this?
-
I actually sort of figured it out but now I have a specific problem.. here is some code <?php require('includes/crumb-brains.php'); $crumbMonster = new Crumbs (); $breadcrumbs = '<a href="index.php">Home<a>'; switch ($_SERVER['PHP_SELF']) { case '/update-list.php': $newCrumbListLabel = $crumbMonster->GetCrumbUpListLabelByListID($_GET["listid"]); $breadcrumbs .= ' » '. $newCrumbListLabel; break; case '/view-list.php': $newCrumbListLabel = $crumbMonster->GetCrumbListLabelByListID($_GET["listid"]); $breadcrumbs .= ' » '. $newCrumbListLabel; break; case '/update-item.php': $newCrumbUpItemLabel = $crumbMonster->GetCrumbUpItemLabelByItemID($_GET["itemid"]); $breadcrumbs .= ' » <a href="view-list.php?listid=">Items<a> » '. $newCrumbUpItemLabel; break; } echo $breadcrumbs; ?> The last case ('/update-item.php') I want the <a href="view-list.php?listid="> to get my list label and post it for the breadcrumb before the $newCrumbUpItemLabel Here is my functions for better understanding. <?php class Crumbs { private $crumbs = 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 GetCrumbListLabelByListID($listId) { $sql = "SELECT `ListLabel` FROM `lists` WHERE `ListId` = ".$listId." LIMIT 0,30"; $result = mysql_query($sql); if (!$result) { die('Invalid query: ' . mysql_error()); } $labels = mysql_fetch_array($result, MYSQL_ASSOC); return $labels['ListLabel']; } public function GetCrumbUpListLabelByListID($listId) { $sql = "SELECT `ListLabel` FROM `lists` WHERE `ListId` = ".$listId." LIMIT 0,30"; $result = mysql_query($sql); if (!$result) { die('Invalid query: ' . mysql_error()); } $labels = mysql_fetch_array($result, MYSQL_ASSOC); return $labels['ListLabel']; } public function GetCrumbUpItemLabelByItemID($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']; } } ?> Thanks in advance if you can help.
-
Hi, was wondering if anyone has a decent breadcrumb link that is simple and possibly step by step? I've googled php breadcrumbs and most of them I don't understand or they don't work, If anyone has personal favorites or a particularly simple way to implement breadcrumbs into a website please help me out, thanks.
-
bump
-
Oops also forgot to add the GetAllItems function in itembrains include 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'],'iscomplete'=>$row['IsComplete'],'itemdesc'=>$row['ItemDesc']); array_push($this->items,$row); } return $this->items; } I hope this provided info is enough for people to help me, if more is needed please lmk.. thanks in advance.
-
I really didn't want to come here and ask for help on this but I'm really racking my brains trying to figure this out and would greatly appreciate some help. I have a form that retrieves item labels from my database, (which is working fine) and now I also wanted to add a description that the user has the option to add with the Item. I want both to appear dynamically with each other if the user chooses to add a description. (the item label already appears dynamically) I added a new text input to the form called ItemDesc and added a new column in my database also called ItemDesc, 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"],$_POST["new-item-desc"]); } $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>';} include('includes/crumbs.php'); ?> <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="text" name="new-item-desc" value="" maxlength="100" /><label>Enter Description</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) { if ($value['iscomplete']){ $checkbox ='<input type="checkbox" checked="true" disabled="true" />'; } else { $checkbox ='<input type="checkbox" disabled="true" />'; } echo "<li> ".$checkbox." ".$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>"; } ?> This is the list brains include.. Would I need to create a new function to handle the ItemDesc? rather than adding it to the create item function? 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, $newItemDesc, $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`,`ItemDesc`) VALUES ( NULL,'".$newItemListId."' , '".$newItemLabel."' , '".$newItemDesc."')"; $result = mysql_query($sql); if (!$result) { die('Invalid query: ' . mysql_error()); }
-
Bump.
-
Am I missing information needed to shorten this? please LMK, i'm using this forum as a learning tool.
-
Hi everyone, I just wanted to see if anyone can simplify this for me. I'm new to PHP but I can see that $itemMonster is being called multiple times. If someone can do this with the switch statement and possibly, briefly explain how and why, I would be very grateful. Thanks in advance if(!isset($_GET["itemid"]) && empty($_POST)) { header("Location: /"); } require('includes/item-brains.php'); $itemMonster = new Items(); if (!empty($_POST)) { $updateResult = $itemMonster->UpdateItem($_POST["new-item-label"],$_POST["item-id"]); if ($updateResult) { $currentlistid = $itemMonster->GetListIdByItemId($_POST["item-id"]); header("Location: /view-list.php?listid=$currentlistid&message=item updated"); } } $currentLabel = $itemMonster->GetItemLabelByItemId($_GET["itemid"]); $currentlistid = $itemMonster->GetListIdByItemId($_GET["itemid"]); ?> <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="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" name="item-updater"> <input type="text" name="new-item-label" value="<?php if ($currentLabel != NULL) { echo $currentLabel; } ?>" maxlength="100" /><label>Enter New Item Name</label> <input type="hidden" name="item-id" value="<?php echo $_GET["itemid"]; ?>" /> <br /> <input type="submit" value="Update Item!"> <a href="/view-list.php?listid=<?php echo $currentlistid;?>">Cancel</a> </form> </body> </html>
-
How to get checkboxes after entering information into a form?
AibZilla replied to AibZilla's topic in PHP Coding Help
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 } } ?> -
How to get checkboxes after entering information into a form?
AibZilla replied to AibZilla's topic in PHP Coding Help
bump -
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>