PHP - Update Multiple Rows With Checkboxes / Export Selected To .txt
Hello all,
i have a table that displays data from mysql, now i want to update multiple rows from that table with checkboxes, the value will basically just switch from 'new' to 'done' so far i have this: Code: [Select] <tbody> <tr class="first"> </tr> <?php $ticketde=0; while ($ticketde < $numpscde) { $f1pscde=mysql_result($ticketresultde,$ticketde,"id"); $f2pscde=mysql_result($ticketresultde,$ticketde,"ticket"); $f4pscde=mysql_result($ticketresultde,$ticketde,"date"); $f5pscde=mysql_result($ticketresultde,$ticketde,"ip"); $f6pscde=mysql_result($ticketresultde,$ticketde,"done"); $setdone = ($f6pscde["done"] == 'n') ? "<a href=\"donepsc.php?id=".$f1pscde."\"><img src=\"ico_new.gif\" alt=\"new\" /></a>" : $f6pscde["done"]; if(isset($_POST['setdone'])){$checkbox = $_POST['checkbox']; $id = "('" . implode( "','", $checkbox ) . "');" ; $sql = "UPDATE ticket SET done='done' WHERE id='$f1pscde'"; $result = mysql_query($sql) or die(mysql_error()); } ?> <tr class="first"> <td class="tc"><font face="Arial, Helvetica, sans-serif"><?php echo $f1pscde; ?></font></td> <td class="tc"><font face="Arial, Helvetica, sans-serif"><?php echo $f2pscde; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f4pscde; ?></font></td> <td class="tc"><font face="Arial, Helvetica, sans-serif"><?php echo $f5pscde; ?></font></td> <td class="tc"><font face="Arial, Helvetica, sans-serif"><?php echo $setdone; ?></font></td> <td class="tc"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $f1pscde['id']; ?>"></td> </tr> <?php $ticketde++; } ?> </tbody> </table> <center><input type="submit" name="setdone" id="setdone" value="Set selected to done" class="button"/> - <input type="submit" name="exporttxt" id="exporttxt" value="Export selected to .txt" class="button"/> </center> </fieldset> </form> I found that checkbox code sample on some other site and tried to implement it, i don't really know where to go from here, as it's a total mess to me now, any help would be greatly appreciated. Similar TutorialsHey All, I tried seraching, but I'm not sure what exactly to search for. Here's what I need to do, and any push in the right direction would be great: I have a PHP form, with the Following: Text Box: Student ID Checkboxes for Activities What I need to do is somehow loop through and make a new row for each activity. Example, if I entered Student ID 105 and Activities are Basketball, Baseball, and Chess Team, I need three different rows in the database each listing the individual activity and the student ID. Any suggestions? I know how to do this if it was one entry (radio buttons) but want to be able to enter multiple rows at a time. Thanks! Hi, I am having difficulty deleting rows in my table using check boxes. I have all the check boxes displaying for each row and a delete button below the table. However when i click on the delete button it isnt deleting the checked rows, i have displayed the code below that i am using; Code: [Select] <?php $result = mysql_query("SELECT * FROM contact ORDER BY msg_id ASC"); echo "<table border='1'> <tr> <th>Delete</th> <th>Message ID</th> <th>Name</th> <th>Email</th> <th>Message</th> </tr>"; while($row = mysql_fetch_array($result)) { ?> <td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo $row['del_id']; ?>"></td> <?php echo "<td>" . $row['msg_id'] . "</td>"; echo "<td>" . $row['name'] . "</td>"; echo "<td>" . $row['email'] . "</td>"; echo "<td>" . $row['msg'] . "</td>"; echo "</tr>"; } echo "</table>"; ?> <td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td> </tr> <?php // Check if delete button active, start this if(isset($_GET['delete'])) { for($i=0;$i<$count;$i++){ $del_id = $checkbox[$i]; $sql = "DELETE FROM contact WHERE id=".$_GET['del_id']; $result = mysql_query($sql); } // if successful redirect to delete_multiple.php if($result){ } } mysql_close(); ?> Please help Thank you Hi, I am new to php and need help. I am building a library system for an assignment. I want to provide a functionality that registers (adds) all transactions to defferent databases. I am stuck on how to add a selected row (selected by a checkbox) to the database and make sure that 2 users cannot update the same record at the same time. Thanks for your help. bellow is my code: Code: [Select] <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=windows-1250"> <meta name="generator" content="PSPad editor, www.pspad.com"> <title>Web Works DD - Web Development & Software Solutions</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="css/style.css" /> </head> <body> <!--<div class="utilities"> <!-- UTILITIES MENU -- <a href="index.php" style=text-decoration:none;><img src="images/home.png" border="0" alt="Home Page"/> Home Page</a> <a href="sitemap.php" style=text-decoration:none;><img src="images/sitemap.png" border="0" alt="Sitemap"/> Sitemap</a> </div><!-- END UTILITIES --> <div id="right_bar"> <!-- right bar starts here --> </div> <!-- end of right bar --> <div id="top_bar"> <!-- top bar starts here --> <a href="index.php" style=text-ecoration:none; title="Web Works DD - Web Development & Software Solutions"><img src="images/mainLib.jpg" border=0 style=height:180;/> </a> <img src="images/topText.jpg" border=0 style=height:180;/> </div> <!-- end of top bar --> <div id="container"> <div id="top-logo"> <!--<a href="index.php" style=text-ecoration:none; title="Web Works DD - Web Development & Software Solutions"><img src="images/Main_logo.jpg" border=0 /> </a> --> </div> <ul class="dropdown dav"> <li><a href="index1.php">HOME</a></li> <li><a href="#" class="dir">VIEW RWSOURCES</a> <ul> <li><a href="books.php">BOOKS</a></li> <li><a href="dvds.php">DVDS</a></li> <li><a href="journals.php">JOURNALS</a></li> </ul> </li> <li><a href="staffLogin.php">STAFF ZONE</a></li> <li><a href="studentsLogin.php">STUDENT ZONE</a></li> </ul> <table> <!--This defines a new form --> <form action="" method="post"> <!--This creates the dropdown in html--> <select name="fields"> <option value="1">Please select...</option> <option value="isbnno">isbnno</option> <option value="title">title</option> <option value="description">description</option> <option value="author">author</option> </select> </td> </tr> <tr> <td> <input type="text" name="value" size="40"> </td> </tr> <tr> <td> <!-- Create a button --> <input type="submit" value="Select" name="select"> </td> </tr> </form> </table> <?php session_start(); include("secure/db_open.php"); /* $myusername=$_SESSION['myusername']; echo $myusername; $insert = $checkbox[$i]; $cops = $_POST['copies']; $userid ="SELECT id FROM students WHERE username = '$myusername'"; $uido = mysql_query($userid); $row = mysql_fetch_array($uido); echo $row['id']; */ // get variable after selecting something from the dropdown with name 'fields' $select = $_POST['select']; $valu = $_POST['value']; // if something has been chosen if (!empty($select)) { $fields = $_POST['fields']; //get the chosen value $allbooks="SELECT * FROM books WHERE {$fields} = '$valu'"; //select books that are available - driven by the user's input $copas="SELECT * FROM books WHERE {$fields} = '$valu' AND available_copies > 0"; $copy = mysql_query($copas); //count the number of rows resulting from the query $count=mysql_num_rows($copy); //$copse = mysql_fetch_array($copy); //select books that are not available $notavailable="SELECT * FROM books WHERE {$fields} = '$valu' AND available_copies = 0"; $shownotavailable=mysql_query($notavailable); $count1=mysql_num_rows($shownotavailable); //display a form echo "<table width='1100' border='0' cellspacing='1' cellpadding='0'>"; echo "<tr>"; echo "<td>" ; echo "<form name='form1' method='post' action=''>"; echo "<table width='1100' border='0' cellpadding='3' cellspacing='1' bgcolor='#CCCCCC'>"; echo "<tr>"; echo "<td align='center' colspan='9' bgcolor='#FFFFFF'>"; echo "<strong>Available to Loan </strong>" ; echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td align='center' bgcolor='#FFFFFF'>Loan</td>"; echo "<td align='center' bgcolor='#FFFFFF'><strong>ISBN No.</strong></td>"; echo "<td align='center' bgcolor='#FFFFFF'><strong>Title</strong></td>"; echo "<td align='center' bgcolor='#FFFFFF'><strong>Description</strong></td>"; echo "<td align='center' bgcolor='#FFFFFF'><strong>Author</strong></td>"; echo "<td align='center' bgcolor='#FFFFFF'><strong>Loan Type</strong></td>"; echo "<td align='center' bgcolor='#FFFFFF'><strong>Location</strong></td>"; echo "<td align='center' bgcolor='#FFFFFF'><strong>Available Copies</strong></td>"; echo "<td align='center' bgcolor='#FFFFFF'><strong>Desired Num of Copies</strong></td>"; echo "</tr>"; while(($row = mysql_fetch_assoc($copy))) { echo "<tr>"; echo "<td align='center' bgcolor='#FFFFFF'><input name='checkbox[]' type='checkbox' id='checkbox[]' value=".$row['bookid']."></td>"; echo "<td>" .$row['isbnno']. "</td>"; echo "<td>" .$row['title']. "</td>"; echo "<td>" .$row['description']. "</td>"; echo "<td>" .$row['author']. "</td>"; echo "<td>" .$row['loan_type']. "</td>"; echo "<td>" .$row['location']. "</td>"; echo "<td>" .$row['available_copies']. "</td>"; echo "<td align='center' bgcolor='#FFFFFF'><input name='copies' type='text' id='copies' size='2'></td>"; echo "</tr>"; } echo "<tr>"; echo "<td colspan='9' align='center' bgcolor='#FFFFFF'><input name='loan' type='submit' id='loan' value='Loan Book'></td>"; echo "</tr>"; echo "</table>"; if (isset($_POST)) { session_start(); $myusername=$_SESSION['myusername']; $cops = $_POST['copies']; $userid ="SELECT id FROM students WHERE username = $myusername"; $uido = mysql_query($userid); $row1 = mysql_fetch_array($uido); $sid = $row1['id']; for ($i=0;$i<$count;$i++) { $insert = $checkbox[$i]; //echo "Welcome, ".$row['id']; $insertloaned="INSERT INTO studentloanedbooks(studentid, bookid, noofcopies) VALUES ($sid, $insert, $cops)"; $loaned = mysql_query($insertloaned); } } if($count1>0) { //display the books details //display a form echo "<br>"; echo "<br>"; echo "<table width='1100' border='0' cellspacing='1' cellpadding='0'>"; echo "<tr>"; echo "<td>" ; echo "<form name='form1' method='post' action=''>"; echo "<table width='1100' border='0' cellpadding='3' cellspacing='1' bgcolor='#CCCCCC'>"; echo "<tr>"; echo "<td align='center' colspan='9' bgcolor='#FFFFFF'>"; echo "<strong>Available to Loan </strong>" ; echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td align='center' bgcolor='#FFFFFF'>Loan</td>"; echo "<td align='center' bgcolor='#FFFFFF'><strong>ISBN No.</strong></td>"; echo "<td align='center' bgcolor='#FFFFFF'><strong>Title</strong></td>"; echo "<td align='center' bgcolor='#FFFFFF'><strong>Description</strong></td>"; echo "<td align='center' bgcolor='#FFFFFF'><strong>Author</strong></td>"; echo "<td align='center' bgcolor='#FFFFFF'><strong>Loan Type</strong></td>"; echo "<td align='center' bgcolor='#FFFFFF'><strong>Location</strong></td>"; echo "<td align='center' bgcolor='#FFFFFF'><strong>Available Copies</strong></td>"; echo "<td align='center' bgcolor='#FFFFFF'><strong>Desired Num of Copies</strong></td>"; echo "</tr>"; while(($row = mysql_fetch_assoc($shownotavailable))) { echo "<tr>"; echo "<td align='center' bgcolor='#FFFFFF'><input name='checkbox[]' type='checkbox' id='checkbox[]' value='.$row[bookid]'></td>"; echo "<td>" .$row['isbnno']. "</td>"; echo "<td>" .$row['title']. "</td>"; echo "<td>" .$row['description']. "</td>"; echo "<td>" .$row['author']. "</td>"; echo "<td>" .$row['loan_type']. "</td>"; echo "<td>" .$row['location']. "</td>"; echo "<td>" .$row['available_copies']. "</td>"; echo "<td align='center' bgcolor='#FFFFFF'><input name='copies' type='text' id='copies' size='2'></td>"; echo "</tr>"; } echo "<tr>"; echo "<td colspan='9' align='center' bgcolor='#FFFFFF'><input name='reserve' type='submit' id='reserve' value='Reserve Book'></td>"; echo "</tr>"; echo "</table>"; } } // include("secure/db_close.php"); //include("secure/db_close.php"); ?> <!--if($cop>0){ --> <!-- this is my footer div --> <div id="footer"> Copyright © 2010 | <a href="privacy.php">Privacy Policy</a> | <a href="terms.php">Terms of Service</a> <img src="images/mini_logo1.png" align="right" style="margin-right:5" /> </div> <!-- End footer div --> </div> </div> </body> </html> MOD EDIT: [code] . . . [/code] BBCode tags added. what Im basically trying to do is just like a phpmyadmin function... you select rows you want to update with a checkbox and then it takes you to a page where the rows that are clicked are shown in forms so that you can view and edit info in them... and then have 1 submit button to update them all at once. As the title says I need help with multiple update system.. Can't really get it to work at all >.< Here's some code: $selectt = mysql_query("SELECT * FROM exercises WHERE user='" . $_SESSION["user"] . "' AND exname='" . $_GET["edit"] . "'"); echo '<form method="POST" action="exercises.php?edited">'; echo '<div id="newexx">'; while($raw = mysql_fetch_array($selectt)) { echo '<input type="text" name="up[' . $raw["id"] . ']" value="' . $raw["swe"] . '">'; echo '<input type="text" name="up1[' . $raw["id"] . ']" value="' . $raw["eng"] . '"><br>'; echo '<input type="hidden" name="id[' . $raw["id"] . ']">'; } echo '</div>'; echo '<input type="submit" value="Update Exercise">'; echo '</form>'; if(isset($_GET["edited"])) { $swe = $_POST["up"]; $eng = $_POST["up1"]; $id = $_POST["id"]; foreach($id as $value => $index) { $update = "UPDATE exercises SET swe='".$swe."', eng='".$eng."' WHERE id='".$index."'"; mysql_query($update); } Would be thankful for reply! I have ran this code before and it worked but not it won't update. Can anyone see what I am doing wrong? Code: [Select] <? if(isset($_POST[sort_invest])) { // if form was submitted $id = $_POST['sel_record']; $sort = $_POST['sort']; for($i=0;$i<$count;$i++){ $sql = "UPDATE invest SET id='$id[$i]', sort='$sort[$i]' WHERE id='$id[$i]'"; $sql_result = mysql_query($sql,$con) or die (mysql_error()); } } // if form was submitted or if it came from another page if (isset($_POST['order_invest']) || isset($_POST['sort_invest'])) { ?> <p><strong>Order Invest</strong></p> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <? $sql = "SELECT id, sort, title FROM invest ORDER BY sort ASC"; $sql_result = mysql_query($sql,$con) or die(mysql_error()); while ($row = mysql_fetch_array($sql_result)) { $id = $row["id"]; $title = $row["title"]; $sort = $row["sort"]; ?> <input type="hidden" name="sel_record[]" value="<? echo "$row[id]"; ?>"> <table width="545" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="69"><input type="text" name="sort[]" value="<? echo "$row[sort]"; ?>" size="3"></td> <td width="476"><? echo "$row[title]"; ?></td> </tr> </table> <br> <? } } ?> <input name="sort_invest" type="submit" value="Sort"> </form> hey can someone advice me on how to make my update script update multiple rows. here's what i've got so far: update.php <?php require('connect.php'); $update = mysql_query("SELECT DISTINCT rideName FROM ride ORDER BY rideName DESC" ); $numrows = mysql_num_rows($update); echo "<form action='mysql_update.php' method='POST'> <select name='updateRide' >"; while ($row=mysql_fetch_assoc($update)) { #$rideID = $row ['rideID']; $rideName = $row ['rideName']; #$seatNumber = $row ['seatNumber']; #$time = $row ['time']; #$price = $row ['price']; echo "<option value='$id'> $rideName </option>"; } echo "</select> <input type='text' name='tochange'> <input type='submit' name='submit' value='change'> </form>"; ?> and now the handler script: mysql_update.php <?php require ('connect.php'); $updateRide=$_POST['updateRide']; $tochange=$_POST['tochange']; if ($updateRide&&$tochange) { $change = mysql_query("UPDATE ride SET rideName='$tochange' WHERE $id='updateRide'"); } ?> When I try this I get nothing, no changes. In the table there is 3 distinct rideNames each have more than 20 rows. Is there a way using the drop down box and ext field like i Have to update all of the distinct rideNames in the table? Thanks. Only the last row will update when I submit. I have this form (and one nerve left): <form action="" method="post" > echo" <input style=\"text-align:center\" type=\"text\" name=\"linkorder\" value=\"".$row['order']."\" /> <input type=\"hidden\" name=\"id\" value=\"".$row['id']."\"/> "; <input type="submit" name="updateorder" value="Save Order" /> </form> On Submit: if (isset($_POST['updateorder'])){ connect(); $changeorder = mysql_unbuffered_query("update links set `order` = '".$_POST['linkorder']."' where id = '".$_POST['id']."'") or die(mysql_error()); } I was going put my fist through the monitor but then I remembered I could get help here. Thank you! can anyone see anything wrong here?? it wont update the Ships table.. i should of gone bed hours ago but its bugging me: <?php $sql="SELECT * FROM ships ORDER BY auction='Yes' DESC"; $result=mysql_query($sql); // Count table rows $count=mysql_num_rows($result); ?> <table width="100%" border="0" cellspacing="1" cellpadding="0"> <form name="form1" method="post" action=""> <tr> <td> <table width="100%" border="0" cellspacing="1" cellpadding="0"> <tr> <td align="center"><strong>Active?</strong></td> <td align="left"><strong>typeID</strong></td> <td align="left"><strong>Item Name</strong></td> <td align="left"><strong>Base Price</strong></td> <td align="left"><strong>Market Price</strong></td> <td align="center"><strong>Auction</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <?php if ($rows['auction'] != "Yes") { ?> <td align="center"><img src="../images/site/delete.png" /></td> <?php } else { ?> <td align="center"><img src="../images/site/accept.png" /></td> <? } ?> <td align="left"><span class="isk"> <? $typeID[]=$rows[typeID]; ?> <? echo $rows['typeID']; ?></span></td> <td align="left"><span class="eveyellow"><? echo $rows['typeName']; ?></span></td> <td align="left"><span class="normal"><?php echo number_format($rows['basePrice'])?> isk</span></td> <td align="left"><input name="marketPrice[]" type="text" size="10" id="marketPrice" value="<? echo $rows['marketPrice']; ?>"> <span class="credits">(<?php echo number_format($rows['marketPrice']/1000000, 2)?> m)</span></td> <td align="center"><input name="auction[]" type="text" size="6" id="auction" value="<? echo $rows['auction']; ?>"></td> </tr> <?php } ?> <tr> <td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td> </tr> </table> </td> </tr> </form> </table> <?php // Check if button name "Submit" is active, do this if($Submit){ for($i=0;$i<$count;$i++){ $sql1="UPDATE ships SET marketPrice='$marketPrice[$i]', auction='$auction[$i]' WHERE typeID='$typeID[$i]'"; $result1=mysql_query($sql1); } } if($result1){ header("location:ship.php"); } mysql_close(); ?> typeID is my primary key in the table and i only want to update "marketPrice" and "auction" upon submit. its a update multiple rows form by the way. thank you so much for helping me... again.. would be lost without phpfreaks. Hello all, im new to this forum, im a noobie, just started coding about 3 weeks ago, don't be too hard on me.
My question is I wan't to check for challenges a user's team posted that have not been excepted after 1 day, then auto refund the user's team back there credits, and then also delete all the challenges. So far here is my code.
//Delete all matches not accepted after 1 day $arrayin = array(); $autorefund = mysql_query("SELECT * FROM `challenges` WHERE `a` = " . $team['id'] . " " . "AND `accepted` = 0 AND `completed` = 0 AND `chtype` = 1 AND (`expires` < " . ((int) time()) . ")"); if (mysql_num_rows($autorefund) > 0) { while ($autorefund = mysql_fetch_assoc($autorefund)) { $arrayin[] = $autorefund['id']; mysql_query("UPDATE `teams` SET `balance` = `balance` + " . $autorefund['credits'] . " " . "WHERE `id` IN (" . mysql_real_escape_string(implode(',', $arrayin)) . ")"); mysql_query("DELETE FROM `challenges` WHERE `a` IN " . "(" . mysql_real_escape_string(implode(',', $arrayin)) . ") " . "AND `accepted` = 0 AND `completed` = 0 AND `chtype` = 1 " . "AND (`expires` < " . ((int) time()) . ")"); } }FYI here is the code i had, it works fine, however it will only delete 1 challenge per team, not all of there challenges. $autorefund = mysql_query("SELECT * FROM `challenges` WHERE `a` = " . $team['id'] . " AND `accepted` = 0 AND `completed` = 0 AND `chtype` = 1 AND (`expires` < ".((int)time()).")"); if (mysql_num_rows($autorefund) > 0) { while ($autorefund = mysql_fetch_assoc($autorefund)) { if ($autorefund['accepted'] == 0 and $autorefund['expires'] < time()) { mysql_query("UPDATE `teams` SET `balance` = `balance` + " . $autorefund['credits'] . " WHERE `id` = " . $team['id'] . ""); mysql_query("DELETE FROM `challenges` WHERE `a` = " . $team['id'] . " AND `accepted` = 0 AND `completed` = 0 AND `chtype` = 1 AND (`expires` < ".((int)time()).")); } } }I inherited this script, its using deprecated statements, i know im not skilled to rewrite the entire site to use prepared statements. This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=325508.0 Hi, after banging my head against the wall for a while thinking this would be a simple task, I'm discovering that this is more complicated than I thought. Basically what I have is a link table linking together source_id and subject_id. For each subject there are multiple sources associated with each. I had created a basic listing of sources by subject... no problem. I now need a way of having a form to create an ordered list in a user-specified way. In other words, I can currently order by id or alphabetically (subject name lives on a different table), but I need the option of choosing the order in which they display. I added another row to this table called order_by. No problem again, and I can manage all of this in the database, however I want to create a basic form where I can view sources by subject and then enter a number that I can use for sorting. I started off looping through each of the entries and the database (with a where), and creating a foreach like so (with the subject_id being grabbed via GET from the URL on a previous script) Code: [Select] while($row = mysqli_fetch_array($rs)) { //update row order if (isset($_POST['submit'])) { //get variables, and assign order $subject_id = $_GET['subject_id']; $order_by = $_POST['order_by']; $source_id = $row['source_id']; //echo 'Order by entered as ' . $order_by . '<br />'; foreach ($_POST['order_by'] as $order_by) { $qorder = "UPDATE source_subject set order_by = '$order_by' WHERE source_id = '$source_id' AND subject_id = '$subject_id'"; mysqli_query($dbc, $qorder) or die ('could not insert order'); // echo $subject_id . ', ' . $order_by . ', ' . $source_id; // echo '<br />'; } } else { $subject_id = $_GET['subject_id']; $order_by = $row['order_by']; $source_id = $row['source_id']; } And have the line in the form like so: Code: [Select] echo '<input type="text" id="order_by" name="order_by[]" size="1" value="'. $order_by .'"/> (yes I know I didn't escape the input field... it's all stored in an htaccess protected directory; I will clean it up later once I get it to work) This, of course, results in every source_id getting the same "order_by" no matter what I put into each field. I'm thinking that I need to do some sort of foreach where I go through foreach source_id and have it update the "order_by" field for each one, but I must admit I'm not sure how to go about this (the flaws of being self-taught I suppose; I don't have anyone to go to on this). I'm hoping someone here can help? Thanks a ton in advance Hi, my PHP code currently outputs the results from a users search by querying a backend postgresql database. As result/row is retuned to the user i would like to be able to detect whether or not they have checked a checkbox at the end of each rown in which case multiple rows can then be deleted from the database upon the user clicking a 'delete multiple records' button. I have no problem in being able to display the checkboxes on the webpage but i am a little unsure as to how to refernce them and detect which ones the user has checked. Given my database stores hostnames/IP addresses would it be best to name each checkbox to reflect the hostname or name the value it returns when checked to reflect the hostname. Given the above and that I also store the results of a users search in a $_SESSION['hosts'][][] array how can I then tie the two together? Thanks for reading. Have a look at this image Here is the part of the form code that makes them into arrays $sql="select * from products"; $res=mysql_query($sql); WHILE($fetch=mysql_fetch_assoc($res)){ echo "<td><input type=hidden name='desBox[]' id='desBox[]' value='".$fetch['prod_id']."'>".$fetch['prod_name']."</td> <td><input type=text id=quantBox[] maxlength=6 name=quantBox[]></td> <td><input type=text maxlength=6 id=teethBox[] name=teethBox[]></td>"; echo "</tr>";} Hey everyone i having some trouble updating records in my databse using checkbox from a form. I can update the records, but i can't figure out how to remove records at the same time. I've posted the code that i'm using to update below foreach($_POST['tag'] as $k=>$l){ $tag = mysql_real_escape_string($_POST['tag'][$k]); $check_tags = mysql_query("SELECT * FROM file_cats WHERE category='$tag'") or die(mysql_error()); $num_tags = mysql_num_rows($check_tags); if($num_tags==0){ $add_tag = mysql_query("INSERT into file_cats (fileID, category) VALUES('$fileID', '$tag')") or die(mysql_error()); } } This code inserts new records based on what the user checked. If it exist it won't add a new row, if it doesn't exist then it will add a new row. but like i said how can remove a row if the box is no longer checked? I've tried using foreach(empty($_POST['tag'] as $k => $l){ $tag = empty($_POST['tag']['$k']; } But that didn't work basically nothing was deleted. Has anyone done something like this before? if so i would appreciate any help you could give Ok so i want to grab an id from the checkbox then grab the option drop down associated with that check box and update a mysql row here is my code so far any help is awesome help taaaanks guys <?php mysql_connect("localhost", "root", "root") or die(mysql_error()); mysql_select_db("db1") or die(mysql_error()); $query = "SELECT * FROM tickets ORDER BY id DESC"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { print "<input name='delete[]' value='{$row['id']}' type='checkbox'>"; mysql_connect("localhost", "root", "root") or die(mysql_error()); mysql_select_db("db1") or die(mysql_error()); $query2 = "SELECT * FROM admin"; $result2 = mysql_query($query2) or die(mysql_error()); print "<form name='namestoupdate' method='post' action='update.php'>\n"; print '<select>'; while($row2 = mysql_fetch_array($result2)) { if ($row2['priv']==prov){print '<option value="'.$row2['user'].'" name="prov['.$i++.']">'.$row2['user'].'</option>';} } print '</select>'; print "<input type='submit' value='submit' />"; print "</form>"; } ?> Visual aid Hi I wanted to know how once I have selected and echoed the rows from mysql table how can I get it to number those rows that echo? etc 1. echo $variable 2. echo $variable 3. echo $variable 4. echo $variable 5. echo $variable Any help is appreciated okay, what i have is a page part of my ACP, and what i am trying to do is list all images from database, the list of images will have a "Checkbox" beside it. the checkbox is for setting where the image will be displayed. reason for the checkbox is cuz the images are only being displayed on 2 separate pages. basicly the whole list of images are in 1 form so when submit is activated its suppose to update the image list where checkboxs have been changed. hope i explained this clearly since im sick haha. but heres what i got for code Code: [Select] <form method="post"> <input type="submit" name="submit" value="Submit" /><br /> <?php $result = mysql_query("SELECT * FROM items") or die("Query Failed: ".mysql_error()); while($row = mysql_fetch_array($result)){ list($id, $item_info, $item_img, $price, $sale, $location) = $row; if($location == 'home'){ $set_checked = 'checked="checked"'; }else{ $set_checked = ''; } if(isset($_POST['location'])){ foreach($_POST['location'] as $value){ $id = $_POST['id']; $insert = mysql_query("UPDATE items SET location='$value' WHERE id='$id'") or die('Insert Error: '.mysql_error()); } } echo '<img src="../images/items/'.$item_img.'" width="100" /> Home Page Slide Show: <input type="checkbox" id='.$id.' value="home" name="location[]" '.$set_checked.' /><br />'; } ?> <input type="hidden" name="hdnLine" value="<? echo $count ?>" /> <input type="submit" name="submit" value="Submit" /> </form> i also added a pic of how it looks like lol |