PHP - Categorizing Items In A List With Edit And Delete Buttons
Hello!
We our creating an admin page to display a list of all the items within a mysql database, these items are within a table called "item". Each item is categorized, these categories are in a table called "category" each category has an ID. There is then a table called "links" which links the items to their category using ID's. We want to display each item by their category with an edit and delete button. We have it so all the items display with the two buttons in no specific order however we are not too sure how to make it so they all display via their category. Here is the code we are currently using: Code: [Select] <?php $itemlist = mysql_query("SELECT item.item_name, item.item_description, item.item_image, item.item_price, item.item_id FROM item ORDER BY item.item_id ASC"); $item_count = 0; ?> <?php while( $row = mysql_fetch_array($itemlist) ){?> <?php if(($row['item.item_name'] == 1) && (isset($item_count) && $item_count < 1)) { ?> <?php $item_count ++; } ?> <li class="title"> <h3><?php echo $row['item_name'];?></h3><br /> <form action="ourworkadmin.php" method="get"> <input type="hidden" name="item_id" value="<?php echo $row['item_id'];?>" /> <input name="edit" value="Edit" type="submit" /> <input name="remove" value="Remove" type="submit" /> </form> </li> <?php } ?> </ul> <!--Close-items_list--> </div> Any help would be appreciated! Thank you!!! Similar TutorialsI have a webpage where all the database items are displyes in a table format.The table also has a check box.Upon clicking the delete button i need to delete all the items whish has the checkbox checked. How will i do that Hey guys So my question is related to the delete and edit functions in a table When I am able to delete entries, I can't edit When I am able to edit entries, I can't delete Let me explain... Started with the table script first (excerpt): Code: [Select] echo "<form method = \"post\" action=\"{$_SERVER['PHP_SELF']}\"> <table> <tr> <td width=\"55\" class=\"formLabelsS2\"><input type=\"submit\" name=\"delete_mail\" value=\"Delete\" id=\"delete_mail\"></td> </tr> </table>"; echo "<table class=\"sortable\" id=\"query_quick2\" width=\"100%\" >\r\n"; echo "\t<tr><th class=\"sorttable_nosort\" ></th><th class=\"sorttable_nosort\" ></th> <th class=\"sorttable_alpha\" >Promoter Locus</th>\r\n"; if($result->num_rows){ while ($row = $result->fetch_array()){ $RowCount ++; $row_color = ($RowCount % 2) ? $color1 : $color2; echo "\t<tr id=\"{$row['id']}\" class=\"$row_color\" > <!--<form method = \"post\" action=\"{$_SERVER['PHP_SELF']}\">--> <td><input type =\"hidden\" name = \"id\" value=\"{$row['id']}\"/></td> <td><input name=\"checkbox[]\" type=\"checkbox\" id=\"checkbox[]\" value=\"{$row['id']} \"></td> <td>{$row['pro']}</td> <td><input type=\"submit\" name=\"edit_mail\" value = \"Edit\"/></td> <!--</form>--> </tr>"; } } echo "</table>"; echo "</form>"; Script for deleting entries (excerpt): Code: [Select] } elseif(isset($_SESSION['user_id']) AND isset($_POST['delete_mail'])){ //user is deleting existing queries $connect=db_connect_2(); if($_POST['checkbox']){ { foreach($_POST['checkbox'] as $check) { $delete = mysqli_query($connect, "DELETE FROM mailing_list WHERE id = '$check'"); } $msgs[] = "Entry deletion was successful!"; $body = "account.php"; } When "edit_mail" button is pressed: Code: [Select] } elseif(isset($_SESSION['user_id']) AND isset($_POST['edit_mail'])){ //user is editing existing queries $body = "mailingList_edit.php"; } A editing form is displayed based on the value of $id: Code: [Select] <?php //retrieve user information $conn=db_connect_2(); $id = mysqli_real_escape_string($conn, $_POST['id']); $result = $conn->query("SELECT * FROM mailing_list WHERE id = '$id';"); $mail = $result->fetch_array(); ?> <div class="viewTitles" >Edit Your Queries:</div> <form method = "post" action = "<? echo $_SERVER['PHP_SELF'] ?>"> <table> <tr><td width="88" class="formLabelsS2" align="left">Promoter Locus:</td></tr> <tr><td><input class = "basicTextField" type="text" name="pro_edit" value="<? echo $mail['pro']; ?>"></td></tr> </table> OK so what happens is: I can delete entries with no problems by checking off the entries I want to delete then click delete button But when I try to click "edit" button near a specific entry (individually), it DOES refer to a specific entry, but right after i SORT the table using sorttable.js, it would always refer to the LAST entry. So I am suspecting there's problem with positioning of the <form></form> inside the while loop (see the table script, as I put lot of space in between these lines for emphasis) Note that I put these <form> and </form> lines as comment so I could do what I mention above, otherwise I couldn't even delete any entries if I leave these 2 lines to be part of the while loop BUT !! I could edit specific entry even after I sort the table I know this is long thread, so please let me know if you need more clarification Thanks. Old issue of mine that I'm coming back to. My question is I'm trying to figure out how to work with the select box of options and apply button so that if delete is chosen and the user clicks on apply it performs the deletedivision inside the process page I know it deals with jquery's ajax however this part of it does not that I'm trying to get fixed because as of right now I have if (isset($_POST['deletedivision'])) and I know that's not right and I know I can't apply a name to the option tag because name isn't one of option's allowable attributes. mods/divisions.php Code: [Select] <form action="" method="post"> <label for="actionSelect">With selected items: </label> <select class="select" name="actionSelect" id="actionSelect"> <option id="1">Edit</option> <option id="2">Delete</option> </select> <button class="button small-button"><strong>Apply</strong></button> </form> <?php while ( $row = mysqli_fetch_array ( $result, MYSQL_ASSOC ) ) { echo ' <tr> <td><input type=checkbox class=checkbox name=checkbox[] id=checkbox[] value="' . $row['id'] . '" /></td> <td>' . $row['divisionname'] . '</td> <td>' . $row['name'] . '</td> <td class=last>' . $row['datecreated'] . '</td> </tr>'; } ?> processes/divisions.php if (isset($_POST['deletedivision'])) { $checkbox = $_POST['checkbox']; $countCheck = count($_POST['checkbox']); for($i=0;$i<$countCheck;$i++) { $del_id = $checkbox[$i]; $query = "DELETE from `divisions` where id = $del_id"; mysqli_query($dbc,$query); } } Hey i created a page to add/edit/remove job's i've posted. I got everything running smoothly except for the edit function? any help would be really appreciated <?php $action = $_GET["action"]; if ($action == "delete"){ $delid = $_GET['delid']; $query = "DELETE FROM jobs WHERE id=".$delid." LIMIT 1"; $sql = mysql_query($query); echo("Job succesfully deleted! [ <a href='add_jobs.php'>Back</a> ]"); } if ($action == "edit"){ print("<strong>Editing a Job:</strong>"); $editid = $_GET['editid']; $sql = mysql_query("SELECT * FROM jobs WHERE id = ".$editid." ") or die ('Error: '.mysql_error ()); while ($row = mysql_fetch_array($sql)) { $id = $row['id']; $job_title = $row['job_title']; $job_description = $row['job_description']; $job_type = $row['job_type']; $job_area = $row['job_area']; $query2 = "UPDATE jobs SET (job_title, job_description, job_type, job_area, hot_job) VALUES ('$job_title', '$job_description', '$job_type', '$job_area', '$hot') WHERE id=$id"; echo("<form name='add' method='post' action='?action=edit'>"); echo("<input type='hidden' name='?action=edit'>"); echo("<table class=main cellspacing=0 cellpadding=5 width=50%>"); echo("<tr><td>Job Title: </td><td align='right'><input type='text' size=50 name='job_title' value='$job_title'></td></tr>"); echo("<tr><td>Job Description: </td><td align='right'><textarea size=50 name='job_description'>$job_description</textarea></td></tr>"); echo("<tr><td>Job Type: </td><td align='center'><select name='job_type'><option>Permanent</option><option>Locum or Contract</option></SELECT></td></tr>"); echo("<tr><td>Hot Job? </td><td align='center'>Yes <input type='radio' name='hot' value='Yes'> No <input type='radio' name='hot' value='no'></td></tr>"); echo("<tr><td>Job Area: </td><td align='center'><select name='job_area'><option>East Anglia</option><option>London / South East</option><option>Midlands</option><option>North West</option><option>Northern Ireland</option><option>Scotland</option><option>South</option><option>South West</option><option>Southern Ireland</option><option>Wales</option><option>Yorkshire / North East</option></SELECT></td></tr>"); echo("<tr><td></td><td><div align='right'><input type='Submit'></div></td></tr>"); echo("</table>"); } } if ($action == "add"){ $add = $_POST['add']; $job_title = $_POST['job_title']; $job_description = $_POST['job_description']; $job_type = $_POST['job_type']; $job_area = $_POST['job_area']; $hot = $_POST['hot']; $id = mysql_insert_id(); $query = "INSERT INTO jobs (id, job_title, job_description, job_type, job_area, hot_job) VALUES ('$id', '$job_title', '$job_description', '$job_type', '$job_area', '$hot')"; $sql = mysql_query($query) or die (mysql_error()); } print("<strong>Add A New Job!</strong>"); print("<br />"); print("<br />"); echo("<form name='add' method='post' action='?action=add'>"); echo("<input type='hidden' name='?action=add'>"); echo("<table class=main cellspacing=0 cellpadding=5 width=50%>"); echo("<tr><td>Job Title: </td><td align='right'><input type='text' size=50 name='job_title'></td></tr>"); echo("<tr><td>Job Description: </td><td align='right'><textarea size=50 name='job_description'></textarea></td></tr>"); echo("<tr><td>Job Type: </td><td align='center'><select name='job_type'><option>Permanent</option><option>Locum or Contract</option></SELECT></td></tr>"); echo("<tr><td>Hot Job? </td><td align='center'>Yes <input type='radio' name='hot' value='Yes'> No <input type='radio' name='hot' value='no' checked></td></tr>"); echo("<tr><td>Job Area: </td><td align='center'><select name='job_area'><option>East Anglia</option><option>London / South East</option><option>Midlands</option><option>North West</option><option>Northern Ireland</option><option>Scotland</option><option>South</option><option>South West</option><option>Southern Ireland</option><option>Wales</option><option>Yorkshire / North East</option></SELECT></td></tr>"); echo("<tr><td></td><td><div align='right'><input type='Submit'></div></td></tr>"); echo("</table>"); if($success == TRUE) { print("<strong>Success!</strong>"); } echo("<br>"); echo("</form>"); print("<strong>Existing Jobs:</strong>"); print("<br />"); print("<br />"); echo("<table class=main cellspacing=0 cellpadding=5>"); echo("<td>ID:</td><td>Title:</td><td>Description:</td><td>Type:</td><td>Area:</td><td>Edit (DO NOT USE YET):</td><td>Delete:</td>"); $query = "SELECT * FROM jobs WHERE 1=1"; $sql = mysql_query($query); while ($row = mysql_fetch_array($sql)) { $id = $row['id']; $job_title = $row['job_title']; $job_description = $row['job_description']; $job_type = $row['job_type']; $job_area = $row['job_area']; $position=18; $job_description2 = substr($job_description, 0, $position); echo("<tr><td><strong>$id</strong></td><td><strong>$job_title</strong></td><td><strong>$job_description2...</strong></td><td><strong>$job_type</strong></td><td><strong>$job_area</strong></td><td><a href='add_jobs.php?action=edit&editid=$id'>Edit</a></td><td><a href='add_jobs.php?action=delete&delid=$id'>Delete</a></td></tr>"); } ?> Hi guys, I have a PHP site where logged user can book appointments. I would like the system to be able to monitor which users edited and deleted an appointment or appointments (e.g 'appointment edited/last edited by...'). I already understand how to edit and delete appointments from the MySQL, but the problem is how do I display who deleted/edited the appointment/s. Please your ideas and suggestions a more than welcome. Thanks Hello, Hi all. I built an online finance tracking thingy for myself and I got it to work using the following database table and PHP code. I didn't write the PHP code, rather, I edited it to suit my needs. It works great for my needs. I have a way to enter records and view the last 180 records in a table. The thing is, while viewing the table, I would lke to be able to edit and delete records. I don't know enough to be able to do this. Can it be done? I realize my PHP code would probably, for the most part, be totally different. Thanks for any help with this. Here is my DB table structu Code: [Select] DROP TABLE IF EXISTS `money`; CREATE TABLE IF NOT EXISTS `money` ( `id` int(5) NOT NULL AUTO_INCREMENT, `date` date NOT NULL, `type` varchar(18) NOT NULL, `checking` decimal(5,2) NOT NULL DEFAULT '0.00', `cash` decimal(5,2) NOT NULL DEFAULT '0.00', `description` varchar(25) NOT NULL, `who` varchar(25) NOT NULL, `note` varchar(50) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; And here is the PHP: Code: [Select] <?php $result = mysql_query ('SELECT date, type, checking, cash, who, description, note' . ' FROM money' . ' ORDER BY date DESC LIMIT 0,180') or die(mysql_error()); echo "<table border='1' cellpadding='5'>"; echo "<tr><th>Date</th><th>Type</th><th>Checking</th><th>Cash</th><th>Who?</th><th>Description</th><th>Note</th></tr>"; while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['date']; echo "</td><td>"; echo $row['type']; echo "</td><td>"; echo $row['checking']; echo "</td><td>"; echo $row['cash']; echo "</td><td>"; echo $row['who']; echo "</td><td>"; echo $row['description']; echo "</td><td>"; echo $row['note']; echo "</td></tr>"; } echo "</table>"; ?> I want to add text to a file, getting it printed out in index.php and later want to edit/delete per row. I give codes page wise. first the form to take data: add.php: Code: [Select] <?php ?> <form method="post" action="add_data.php"> <fieldset> <legend>Student List</legend> Name : <input type="text" name="uname" /><br> Content : <input type="text" name="age" /> <br> <input type="submit" name="submit" value="send" /> </fieldset> </form> Next adding text to a file: add_data.php: Code: [Select] <?php $id = 1; if (file_exists("data.txt")) { $fp = fopen("data.txt", 'r'); $str = fread($fp, filesize("data.txt")); $str_arr = explode("|", $str); foreach ($str_arr as $rec) { if ($rec) { $id++; } } } $mode = (file_exists("data.txt"))? "a" : "w"; $fp = fopen("data.txt", $mode); $line = $id . "--" . $_POST['uname'] . "--" . $_POST['age'] . "|"; $res = fwrite($fp, $line); fclose($fp); header("location:index.php"); ?>In the index.php, I'd like to fetch data and edit them per row: Code: [Select] <?php $fp = fopen("data.txt", 'r'); $str = fread($fp, filesize("data.txt")); $str_arr = explode("|", $str); echo "<table border='1'>"; echo "<tr><td>ID</td><td>Name</td><td>Age</td><td>Option</td></tr>"; foreach ($str_arr as $rec) { if ($rec) { $rec_arr = explode("--", $rec); echo "<tr>"; foreach ($rec_arr as $col) { echo "<td>$col</td>"; } print "<td><a href=\"edit.php?id=$id\">Edit</a>/<a href=\"delete.php?id=$id\">Delete</a></td></tr>"; } } echo "</table>"; echo "<a href=\"add.php\">Add Data</a>"; ?> Next I want to Edit per row: edit.php: Code: [Select] <?php $fp = fopen("data.txt", 'r'); $str = fread($fp, filesize("data.txt")); $str_arr = explode("|", $str); foreach ($str_arr as $rec) { if ($rec) { $rec_arr = explode("--", $rec); $id = $rec_arr[0]; $name = $rec_arr[1]; $age = $rec_arr[2]; if ($id == $_REQUEST["id"]) { echo "<form action='edit_data.php' method='post'>"; echo "Name :<input type='text' name='uname' value='$name' /><br>"; echo "Age: <input type='text' name='age' value=$age /><br>"; echo "<input type='hidden' name='uid' value=$id />"; echo "<input type='submit' value='Edit'>"; echo "</form>"; } } } ?> From edit.php to edit_data.php where I practically try to edit per row: Code: [Select] <?php $fp = fopen("data.txt", 'r'); $str = fread($fp, filesize("data.txt")); $str_arr = explode("|", $str); foreach ($str_arr as $rec) { if ($rec) { $rec_arr = explode("--", $rec); $id = $rec_arr[0]; $name = $rec_arr[1]; $age = $rec_arr[2]; if ($id == $_POST['uid']) { $new_str = $id . "--" . $_POST['uname'] . "--" . $_POST['age'] . "|"; } else { $new_str = $id . "--" . $name . "--" . $age . "|"; } } } fclose($fp); $fp = fopen("data.txt", 'w'); fwrite($fp, $new_str); fclose($fp); ?> The mechanism is simple. Taking datas from a form, explode them to an array and get them into col/row pattern to edit and delete them. But my problem is when I want to edit in index.php page, specially in this part: Code: [Select] print "<td><a href=\"edit.php?id=$id\">Edit</a> It says, undefined index. But I try to catch this $id in the edit.php page, in this manner, as you see in my code: Code: [Select] foreach ($str_arr as $rec) { if ($rec) { $rec_arr = explode("--", $rec); $id = $rec_arr[0]; $name = $rec_arr[1]; $age = $rec_arr[2]; if ($id == $_REQUEST["id"]) { echo "<form action='edit_data.php' method='post'>"; echo "Name :<input type='text' name='uname' value='$name' /><br>"; echo "Age: <input type='text' name='age' value=$age /><br>"; echo "<input type='hidden' name='uid' value=$id />"; echo "<input type='submit' value='Edit'>"; echo "</form>"; } } } Have I done any mistake here? If anyone points out, I'll be obliged. Not sure how to go about making it so that I can delete and edit a post.. So I am stumped on how to make it to delete and edit post. The key factor for getting the information is the id field. And I am able to get it and display it, but how can I get it to work between all my functions? This is what I have so far. <?php include 'test.php'; function connection() { $connection = @mysql_connect('localhost','root','') or die('could not connect to mysql'); $select_db = @mysql_select_db('tutorials') or die('could not connect to database'); } function delete_post($id) { connection(); $query = "DELETE FROM `posts` WHERE `id` = '$id'"; $result = mysql_query($query); } function find_posts() { connection(); $query = 'SELECT `posts`.`title`, `posts`.`body`, `posts`.`id`, `users`.`username` FROM `posts`, `users` WHERE `posts`.`user_id` = `users`.`id`'; $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { $id = $row['id']; echo '<b>' . $row['title'] . '</b>' .'<a href=/practice/model/posts.php?action=delete>[delete]</a> <a href=/practice/model/posts.php?action=edit>[edit]</a>' . '<br/>'; echo $row['body'] . '<br/>'; echo $row['username'] . '<p>'; } } function find_post($id) { connection(); $query = "SELECT `posts`.`title`, `posts`.`body`, `posts`.`id`, `users`.`username` FROM `posts`, `users` WHERE `posts`.`user_id` = `users`.`id` AND `posts`.`id` = '$id'"; $result = mysql_query($query); $row = mysql_fetch_array($result); echo '<b>' . $row['title'] . '</b>' . '<br/>'; echo $row['body'] . '<br/>'; echo $row['username'] . '<p>'; } function create_post() { connection(); $title = $_POST['title']; $body = $_POST['body']; $query = "INSERT INTO `posts` SET `title` = '$title', `body` = '$body', `created_at` = NOW(), `user_id` = 53"; $result = mysql_query($query); if(!$result) { echo mysql_error(); } } delete_post(7); find_posts(); ?> <?php $action = $_GET['action']; switch ($action) { case 'create': echo 'created' . '<br/>'; create_post(); break; case 'delete': echo 'deleted' . '<br/>'; delete_post($id); break; } ?> <form action="/practice/model/posts.php?action=create" method="POST"> <input type="text" col="40" name="title" /><br/> <textarea cols="30" rows="5" name="body"> </textarea><br/> <input type="submit" name="submit" /> </form> So yea, I am not sure how to get the 'id' parameters linked between everything that needs it. Sorry for the vague description, but its kind of hard to put it into words. If you need a more detailed description please let me know and I will try to. Pretty much want to be able to delete and edit my posts. Thank you! How hard would something like this be? I have a database with all my users. I need an empty list and when a user clicks a button "Add me to the list" they are added to the first position in the list Slots 1. Tom 2. 3. 4. 5. Later, Jerry wants to be added to the list. So this happens Slots 1. Jerry 2. Tom 3. 4. 5. More people join the list 1. Bob 2. John 3. Jerry 4. Tom 5. Tom gets upset clicks the same button to join the list again, and he's bumped back up to first place. Slots 1. Tom 2. Bob 3. John 4. Jerry 5. Is this possible? And is so, how would I go about getting started on such a thing? I've been using PHP for about a year and a half. I have the following session variables for each item in a cart, which gets updated each time an item is added from the catalog // Register the session variables $_SESSION['ses_basket_items']=$ses_basket_items; $_SESSION['ses_basket_name']=$ses_basket_name; $_SESSION['ses_basket_amount']=$ses_basket_amount; $_SESSION['ses_basket_price']=$ses_basket_price; $_SESSION['ses_basket_stockcode']=$ses_basket_stockcode; $_SESSION['ses_basket_image']=$ses_basket_image; $_SESSION['ses_basket_size']=$ses_basket_size; $_SESSION['ses_basket_sizechoice']=$ses_basket_sizechoice; $_SESSION['ses_basket_id']=$ses_basket_id; I have a current cart page which loops through the sessions and displays them in a form. I have a check box for each item with the name="remove[]" and the value is the itemID which is the $ses_basket_id of item in the session. I have a select box with name="size[]" and the value is the users selected size for each item in the session which is $ses_basket_size Finnally I have a quantity text box with name="quantity[]" and the value is the users quantity value selected which is $ses_basket_amount. After all the looping through the products displaying each item in a row I have an update cart submit button name="change" outside the loop. What I want to know is how do I setup to perform each of these actions for each item in the session, how do I create the foreach loops for each array to delete or modify the correct items in the session if they are modified. I have the code to perform each task but dont know how to loop it through for each item in the session affecting only the correct session items. so if I have 3 items in the session for example, and I want to change the size of item 1, remove item 2 and change item 3 for quantity 1 to quantity 3 with only the 1 form and change button for all items and actions? Hope that makes sense any help with this would be appreciated. Hi all I am having troubles integrating a shopping cart. $action = (isset($_GET['action']) && $_GET['action'] != '') ? $_GET['action'] : 'view'; switch ($action) { case 'add' : addToCart(); break; case 'update' : updateCart(); break; case 'delete' : deleteFromCart(); break; case 'view' : } Allows me to Delete and Update but not Add an item. [php]$action = (isset($_POST['action']) && $_POST['action'] != '') ? $_POST['action'] : 'view'; Allows me to ADD an item to the cart(add action passed from previous page via form) but not Delete or UPDATE Im not sure if I should have attached the pages or just pasted them but heres the code cart.php <?php require_once 'config.php'; require_once 'cart-functions2.php'; require_once 'functions.php'; require_once 'database.php'; $ID = $_POST["ID"]; $pSize = $_POST["size"]; $pcolour = $_POST["colour"]; ?> <?php $action = (isset($_GET['action']) && $_GET['action'] != '') ? $_GET['action'] : 'view'; switch ($action) { case 'add' : addToCart(); break; case 'update' : updateCart(); break; case 'delete' : deleteFromCart(); break; case 'view' : } $ID = $_POST["ID"]; $cartContent = getCartContent(); $numItem = count($cartContent); $pageTitle = 'Shopping Cart'; // show the error message ( if we have any ) displayError(); if ($numItem > 0 ) { ?> <form action="<?php echo $_SERVER['PHP_SELF'] . "?action=update"; ?>" method="post" name="frmCart" id="frmCart"> <table width="780" border="0" align="center" cellpadding="5" cellspacing="1" class="entryTable"> <tr class="entryTableHeader"> <td colspan="2" align="center">Item</td> <td align="center">Unit Price</td> <td width="75" align="center">Quantity</td> <td align="center">Total</td> <td width="75" align="center"> </td> </tr> <?php $subTotal = 0; for ($i = 0; $i < $numItem; $i++) { extract($cartContent[$i]); $productUrl = "index.php"; $subTotal += $price * $ct_qty; ?> <tr class="content"> <td width="80" align="center"></td> <td><?php echo $pDesc; ?></td> <td align="right"><?php echo displayAmount($price); ?></td> <td width="75"><input name="txtQty[]" type="text" id="txtQty[]" size="5" value="<?php echo $ct_qty; ?>" class="box" onKeyUp="checkNumber(this);"> <input name="hidCartId[]" type="hidden" value="<?php echo $ct_id; ?>"> <input name="hidProductId[]" type="hidden" value="<?php echo $ID; ?>"> </td> <td align="right"><?php echo displayAmount($price * $ct_qty); ?></td> <td width="75" align="center"> <input name="btnDelete" type="button" id="btnDelete" value="Delete" onClick="window.location.href='<?php echo $_SERVER['PHP_SELF'] . "?action=delete&cid=$ct_id"; ?>';" class="box"> </td> </tr> <?php } ?> cart-functions <?php require_once 'config.php'; /********************************************************* * SHOPPING CART FUNCTIONS *********************************************************/ function addToCart() { $sid = session_id(); $ID = $_GET["ID"]; $pSize = $_GET["size"]; $pcolour = $_GET["colour"]; // current session id // check if the product is already // in cart table for this session $sql = "SELECT ID FROM cart WHERE ID = '$ID' AND ct_session_id = '$sid'"; $result = dbQuery($sql); if (dbNumRows($result) == 0) { // put the product in cart table $sql = "INSERT INTO cart (ID, ct_qty, ct_session_id, ct_date) VALUES ('$ID', 1, '$sid', NOW())"; $result = dbQuery($sql); } else { // update product quantity in cart table $sql = "UPDATE cart SET ct_qty = ct_qty + 1 WHERE ct_session_id = '$sid' AND ID = '$ID'"; $result = dbQuery($sql); } header('Location: cart2.php'); } /* Get all item in current session from shopping cart table */ function getCartContent() { $cartContent = array(); $sid = session_id(); $sql = "SELECT ct.ct_id, ct.ID, ct.ct_size, ct.ct_colour, ct.ct_qty, pd.pDesc, pd.price, pd.ID FROM cart ct, products pd WHERE ct_session_id = '$sid' AND ct.ID = pd.ID"; $result = dbQuery($sql); while ($row = dbFetchAssoc($result)) { $cartContent[] = $row; } return $cartContent; } /* Remove an item from the cart */ function deleteFromCart($cartId = 0) { if (!$cartId && isset($_GET['cid']) && (int)$_GET['cid'] > 0) { $cartId = (int)$_GET['cid']; } if ($cartId) { $sql = "DELETE FROM cart WHERE ct_id = $cartId"; $result = dbQuery($sql); } header('Location: cart2.php'); } /* Update item quantity in shopping cart */ function updateCart() { $cartId = $_POST['hidCartId']; $productId = $_POST['hidProductId']; $itemQty = $_POST['txtQty']; $numItem = count($itemQty); $numDeleted = 0; $notice = ''; for ($i = 0; $i < $numItem; $i++) { $newQty = (int)$itemQty[$i]; if ($newQty < 1) { // remove this item from shopping cart deleteFromCart($cartId[$i]); $numDeleted += 1; } // update product quantity $sql = "UPDATE cart SET ct_qty = $newQty WHERE ct_id = {$cartId[$i]}"; dbQuery($sql); } exit; } function isCartEmpty() { $isEmpty = false; $sid = session_id(); $sql = "SELECT ct_id FROM cart ct WHERE ct_session_id = '$sid'"; $result = dbQuery($sql); if (dbNumRows($result) == 0) { $isEmpty = true; } return $isEmpty; } /* Delete all cart entries older than one day */ function deleteAbandonedCart() { $yesterday = date('Y-m-d H:i:s', mktime(0,0,0, date('m'), date('d') - 1, date('Y'))); $sql = "DELETE FROM cart WHERE ct_date < '$yesterday'"; dbQuery($sql); } ?> Thanks in advance Hi, I'm pretty sure that I am complicating thing for something I'm trying to do. In my database, I have some posts, each with a category field. what I'm trying to do is have a list of categories with each post that falls in that category listed underneath each category. ie: Code: [Select] <h3>Category 1</h3> <ul class="nav1"> <li><a href="#">Title of post with category 1</a></li> <li><a href="#">Title of another post with category 1</a></li> <li><a href="#">Title of 3rd post with category 1</a></li> </ul> <h3>Category 2</h3> <ul class="nav1"> <li><a href="#">Title of post with category 2</a></li> <li><a href="#">Title of another post with category 2</a></li> <li><a href="#">Title of 3rd post with category 2</a></li> </ul> Can someone please tell me what the easiest way to do this is? I've tried different tutorials and methods i could think of, but they overcomplicated things. any help would be appreciated, thank you : ) Hi first tyvm for reading my help request me and my friend ar trying to build a order form (see png file ^^) so the main idea is some on go to order form.php
in that order form they fil in thear info like name, adress you know ^^
thean here is the treaky part at the and of the form they kan add products to there order by selecting it or search it from the drop down list the items in the dropdown list come from msql
the client can add more or delete items by clicking - or + whean the clint click send the client need to get a mail whit there a list of what theay have orderd and there unic order number wel so far we can do that but we wont to send another list to the company of order where the added products in the order ar sorted out based on the product id number
this is what we have so far http://clientconstru...sion.nl/valeri/
tyvm again voor anyone who read this ^^
Attached Files
bestel-form.png 37.78KB
0 downloads I have a simple form that edits student information. I have several fields that I have a drop down list pulled as an array from a separate table. I would like the information that is already entered on the student to be the default but still have the drop down list available if the item was entered in error. For example: Drop down list of all the states of America, OH was entered for the student, when the edit form comes up for State in Address I would like OH to be the default but still have the list to choose if OH was entered in error. I have tried selected = $selected but then the entire drop down changed to OH. I am very, very much a beginner in this <?php // list of possible modules comes from database $state_array=get_states(); //display as a drop down list for end user to choose if (!is_array($state_array)) { echo "<p>No States are currently available<p>"; return; } foreach ($state_array as $row) { echo "<option value=\"".($row['stateid'])."\""; // if existing state, put in current catgory echo "<strong> ".($row['stateid'])."</strong><br />"; echo "<option select=\"selected\">OH"; } ?> I coded the following but some parts are not working (the "curveball" mentioned at the end). How would YOU do this? I have a page (A) displaying a form with a textarea field using a WYSIWYG interface. The user will enter a list of unordered items and upon submit the string will look something like this: This is my list of food items: <ul> <li> Lettuce </li> <li> Tomatoes </li> <li> Eggs </li> <ul> Upon submit, I need to give each list item an unique id and store this id along with the text next to it in a separate table: List_item_id List_item_text List_item_state food_1 Lettuce food_2 Tomatoes food_3 Eggs The user will then land in another page with a form displaying the list. The text is now in the page itself and not in a textarea. Instead of the bullets a dropdown list appears, and the user can select "buy" or "sell" for each list item. This page (B) looks something like this: <form> This is my list of food items: <br><select name="food_1"> <option value="buy">Buy</option> <option value="sell">Sell</option> </select> Lettuce <br><select name="food_2"> <option value="buy">Buy</option> <option value="sell">Sell</option> </select> Tomatoes <br><select name="food_2"> <option value="buy">Buy</option> <option value="sell">Sell</option> </select> Eggs <input type=submit value="submit"> </form> When the user hits "submit" the table with the list items will be updated with the values selected in the dropdown list: List_item_id List_item_text List_item_state food_1 Lettuce Buy food_2 Tomatoes Buy food_3 Eggs Sell The next time the user goes to Page B the list will remember the states. Here's the curveball: At any point the user may click on "EDIT LIST" on Page B so they may add more items (at the begining, middle or end of the string). On edit mode the list items should appear as bullets again inside the WYSIWYG interface. Keep in mind that some of the text in the string may not be a list item (ie, "this is my list of food...") Hi. I will try and explain simply.
I have a list of item codes eg.
size1 Acolor1
size1 Bcolor3
size1 Bcolor1
size1 Acolor3
size1 Acolor4
size2 Acolor1
size3 Bcolor1
size3 Bcolor2
size3 Bcolor2
size3 Acolor1
I want to take these and split them into parts:
size1 Acolor2
size1 Bcolor3
etc.
Then I want to create a form with 2 dropdowns. The first option would just have all unique sizes so:
size1
size2
size3
Then when one is selected, option 2 would show the colours available in that size.
Is there a standard way of doing this? Can I use PHP to create the array and then jquery to display and hide the options?
I'm totally stuck and i'm not just looking for somebody to code it all for me. any help would be greatly appreciated
thanks
Sam
Hello all, I have used the phpfreaks custom order list script to create, well, a custom order list, but for some reason the Delete section of the code is not reassigning the numbers correctly after an item is deleted. It deletes the record okay, but if I have: 1 2 3 4 and delete 3, then 4 should become 3 but 4 stays as 4 until it moves two places and then it becomes 3. I am sure its related to part of this code, but please let me know if you have any ideas. Cheers Pockitz // delete row from table $sql = "DELETE FROM images WHERE imgsequenceid = '$seqid'"; $result = mysql_query($sql) or die(mysql_error()); if($result){ echo "Image $seqid successfully deleted from $id"; }else{ echo "ERROR"; } // select the info, ordering by sequenceid $sql = "SELECT imgsequenceid, imgid FROM images ORDER BY imgsequenceid"; $result = mysql_query($sql) or die(mysql_error()); // initialize a counter for rewriting sequenceid $seqid = 1; // while there is info to be fetched... while ($r = mysql_fetch_assoc($result)) { $imgid = $r['imgid']; // update the sequenceid number to the one in the next number $sql = "UPDATE images SET imgsequenceid = '$seqid' WHERE imgid = '$imgid'"; $update = mysql_query($sql) or die(mysql_error()); // inc to next avail number $seqid++; } // end while } // end if del i do think is a small mistake i making can u please have a look if u can ok here's the problem i am trying to delete an album within the album should also delete the photos related to that album this what i tried gives this error Delete image failed. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3 my tables are table albums fields album_id, album_name, album_owner, sub_album table photos fields, photo_id, photo_name, photo_extension, photo_proper photo_owner, photo_date, photo_comments, photo_size, album_id photo_proper is the name image stored in folder <?php define('ROOT_DIR', './'); define('PROPER', TRUE); /** * include common files */ include_once(ROOT_DIR. 'includes/common.inc.php'); // No album id has been selected if (isset($_GET['albums'])) // get the album name since we need to display // a message that album 'foo' is deleted $result = mysql_query("SELECT album_id, album_name, album_owner, sub_album FROM albums WHERE album_id = $album_id") or die('Delete image failed. ' . mysql_error()); if (mysql_num_rows($result) == 1) { $row = mysql_fetch_assoc($result); $album_id = $row['album_id']; $album_name = $row['album_name']; // get the image filenames first so we can delete them // from the server $result = mysql_query("SELECT photo_id, photo_id FROM photos WHERE album_id = $album_id") or die(mysql_error()); while ($row = mysql_fetch_assoc($result)) { define("GALLERY_IMG_DIR", "./photos/"); unlink(GALLERY_IMG_DIR . $row['photo_proper']); unlink(GALLERY_IMG_DIR . 'thumbs/' . $row['photo_proper']); } $result = mysql_query("DELETE FROM photos WHERE album_id = $album_id") or die('Delete image failed. ' . mysql_error()); $result = mysql_query("DELETE FROM album WHERE album_id = $album_id") or die('Delete album failed. ' . mysql_error()); // album deleted successfully, let the user know about it echo "<p align=center>Album '$album_name' deleted.</p>"; } else { echo "<p align=center>Cannot delete a non-existent album.</p>"; } ?> try 2 error line 5 <?php define('ROOT_DIR', './'); define('PROPER', TRUE); /** * include common files */ include_once(ROOT_DIR. 'includes/common.inc.php'); // No album id has been selected if (isset($_GET['albums'])) { // get the image file name so we // can delete it from the server $sql = "SELECT album_id, album_name, album_owner, sub_album FROM albums WHERE album_id = {$_GET['albums']}"; $result = mysql_query($sql) or die('Delete photo failed. ' . mysql_error()); if (mysql_num_rows($result) == 1) { $row = mysql_fetch_assoc($result); // get the image filenames first so we can delete them // from the server $sql = "SELECT photo_id, photo_proper FROM photos WHERE photo_id = {$_GET['photos']}"; $result = mysql_query($sql) or die('Delete photo failed. ' . mysql_error()); if (mysql_num_rows($result) == 1) { $row = mysql_fetch_assoc($result); define("GALLERY_IMG_DIR", "./photos/"); // remove the image and the thumbnail from the server unlink(GALLERY_IMG_DIR . $row['photo_proper']); unlink(GALLERY_IMG_DIR . 'thumbs/' . $row['photo_proper']); // and then remove the database entry $sql = "DELETE FROM photos WHERE photo_id = {$_GET['photos']}"; $result = mysql_query("DELETE FROM album WHERE album_id = $album_id") or die('Delete album failed. ' . mysql_error()); // album deleted successfully, let the user know about it echo "<p align=center>Album '$album_name' deleted.</p>"; } else { echo "<p align=center>Cannot delete a non-existent album.</p>"; } } } ?> |