AibZilla Posted June 5, 2012 Share Posted June 5, 2012 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()); } Quote Link to comment https://forums.phpfreaks.com/topic/263721-retrieving-form-info-from-database/ Share on other sites More sharing options...
AibZilla Posted June 5, 2012 Author Share Posted June 5, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/263721-retrieving-form-info-from-database/#findComment-1351449 Share on other sites More sharing options...
AibZilla Posted June 5, 2012 Author Share Posted June 5, 2012 bump Quote Link to comment https://forums.phpfreaks.com/topic/263721-retrieving-form-info-from-database/#findComment-1351479 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.