PHP - Deleting Selected Things With Checkboxs
Hi all, I've just finished sorting my Inbox code for my website which all works apart from deleting more than one message at a time.
if (isset($_POST['Deleteselected'])){ foreach($_POST['radio'] as $value) { $numm++; mysql_query("DELETE FROM inbox WHERE id='$value'"); } echo "<table class='table' width='30%' align='center' cellpadding='0' border='1' cellspacing='0'> <tr> <td class='header' align='center'>Success</td> </tr> <tr> <td align='center'>$numm messages deleted!</td> </tr> </table><br /> "; } $row = mysql_fetch_array($get_messages2); if($row['read'] == 0) { echo '<tr><td><input class="input" type="checkbox" name="radio[]" value="' . $row['id'] . '"></td><td width="40%" align="center"><a href="rmessage.php?messageid=' . $row['id'] . '">' . $row['title'] . '</a> <font color="red"><strong>**</font> Unread <font color="red">**</strong></font></td><td width="40%" align="center"><a href="profile.php?viewuser=' . $row['from'] . '">' . $row['from'] . '</a></td><td align="center"><a href="?delete='.$row['id'].'"><strong>Delete</strong></td></tr>'; }else{ echo '<tr><td><input class="input" type="checkbox" name="radio[]" value="' . $row['id'] . '"></td><td width="40%" align="center"><a href="rmessage.php?messageid=' . $row['id'] . '">' . $row['title'] . '</a></td><td width="40%" align="center"><a href="profile.php?viewuser=' . $row['from'] . '">' . $row['from'] . '</a></td><td align="center"><a href="?delete='.$row['id'].'"><strong>Delete</strong></td>'; } This is the form which has the button: <form action='' method='POST' name='thishere'> <table width="25%" cellpadding="0" align="center" cellspacing="0" border="1" class="table"> <tr> <td class="header" align="center" colspan="2">Control Panel</td> </tr> <tr> <td align='left' width='50%'> <input name='Deleteselected' class='button' type='submit' id='Deleteselected' value='Delete Selected'></td> </tr> When I select the check box and the press "Delete Selected" It says that the message is deleted but it accually still there and hasnt been deleted. Anyone see why its doing that? Thanks for any help provided Similar TutorialsI have a bad way with words, so if the title doesnt make much sense nor my post, I apolagize! But I am using a while loop and mysql_fetch_array to echo all information in a table in mysql. With each entry, I have included a button that executes a delete query for that entry. Code: [Select] $delquery="DELETE FROM requests WHERE user = '".$row['user']."'"; mysql_query($delquery,$link2); echo "<font size='19px' color='#009933'>User deleted from request database.When I click the button, the message is echod in every entry listed on the page, and nothing happens. I figured Id use delete from the username, so that way mysql will know which one to delete... but Idk when I think about it thats dumb and makes no sense. Im stuck. This side of the application im trying to make is the admin side where I can process requests. After I process the request I delete it from the database so I know I processed it. I have no idea what query to use for this. Anybody know how I could do this? Thanks
Hello I need a great help for my problem, I tried to insert multiple checkboxs for "$_POST active" in my CRUD and the values must be saved in the database but will be saved as "Array" everytime. foreach($_POST['active'] as $act){//query? } Here the PHP code <?php require_once "../lakota/config.php"; if ($_SERVER["REQUEST_METHOD"] == "POST") { if (isset($_POST['faction'], $_POST['stations'], $_POST["active"], $_POST['pending'], $_POST['influence'], $_POST['id_fact'])) { if(isset($_POST["submit"])){ $activearr=$_POST["active"]; $newvalues= implode(",", $activearr); include_once "../lakota/checkboxClass.php"; $checkBoxClass=new checkboxClass(); echo $checkBoxClass->addtoDatabase($newvalues); } $sql = "INSERT INTO lakotabgs (faction, stations, active, pending, influence, id_fact) VALUES (?,?,?,?,?,?)"; if ($stmt = $link->prepare($sql)) { $stmt->bind_param("ssssss", $_POST['faction'], $_POST['stations'], $_POST["active"], $_POST['pending'], $_POST['influence'], $_POST['id_fact']); if ($stmt->execute()) { header("location: ../lakota/index.php"); exit(); } else { echo "Error! Try again later."; } $stmt->close(); } } $link->close(); } ?> HTML code <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Add new info</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"> </head> <body> <form action="<?php echo $_SERVER["PHP_SELF"] ?>" method="post"> <label><b>Active States</b></label> <input name="active[]" class="form-control" id="example1" type="checkbox" value="None" /> <label for="example1">None</label> <input name="active[]" class="form-control" id="example2" type="checkbox" value="Everybody" /> <label for="example2">Everybody</label> <input name="active[]" class="form-control" id="example3" type="checkbox" value="Unknown" /> <label for="example3">Unknown</label> <input type="submit" id="submit" name="submit" class="btn btn-primary" value="Add new info"> <a href="../lakota/index.php" class="btn btn-default">Back</a> </form> </body> </html> Edited November 14, 2020 by AccuCORE I have this loop on a shorturl website i own that selects domains from my website and lists them in a dropdown list where users can select one domain to use as url shortener. The problem is that when a users selects and entry from the dropdown list this created only the [[[main_url]]] entry from the database table bellow can be used. When someone selectes "coolartistname.site.com the submit button cannot be pressed. in other words it's not adding the SELECTED attribute other than the [[[main_url]]] domain. Can anyone see on the code bellow why this would happen?
**Index.php** // get base urls $shortUrlDomains = getShortUrlDomains(); <?php foreach ($shortUrlDomains AS $k => $shortUrlDomain) { // active domains only if (($shortUrlDomain['premium_only'] !== '1') && ($shortUrlDomain['premium_only'] !== $Auth->id)) { continue; } echo '<option value="' . (int)$k . '"'; if (isset($_REQUEST['shortUrlDomain'])) { if ($k == (int)$_REQUEST['shortUrlDomain']) { echo 'SELECTED'; } } echo '>'; echo $shortUrlDomain['domain']; if ($disabled == true) { echo ' (' . safeOutputToScreen(t('unavailable', 'unavailable')) . ')'; } '</option>'; } echo '</optgroup>'; ?> FUNCTIONS.PHP function getShortUrlDomains() { // if we already have it cached if(defined('_SETTINGS_SHORT_URL_DOMAINS')) { return unserialize(_SETTINGS_SHORT_URL_DOMAINS); } // get connection $db = Database::getDatabase(true); // load from database $domains = $db->getRows("SELECT id, domain, premium_only, status FROM url_domain ORDER BY premium_only ASC, id ASC"); // organise and replace site url $rs = array(); foreach($domains AS $domain) { if($domain['domain'] == '[[[main_url]]]') { $domain['domain'] = _CONFIG_SITE_FULL_URL; } $rs[$domain{'id'}] = $domain; } **MYSQL DATABASE** url_domain (id, domain, premium_only, status, date_created, owner) VALUES (1, '[[[main_url]]]', 0, 'enabled', '2019-03-02 08:13:00', 1) (14, 'coolartistname.site.com', 6, 'enabled', '2020-04-18 19:21:59', 6);
Could anyone tell me why this is not deleting the userip and post id from the database at all. Thanks Code: [Select] <?php include('dbcon.php'); if($_REQUEST['postId']) { $userip = $_SERVER['REMOTE_ADDR']; mysql_query("update collapsed_likes set likes=likes-1 where post_id= ".$_REQUEST['postId']); mysql_query("delete from collapsed_ip where userip=".$userip." AND post_id = ".$_REQUEST['postId']); $total_likes = mysql_query("SELECT * FROM collapsed_likes where post_id = ".$_REQUEST['postId']." "); $likes = mysql_fetch_array($total_likes); $likes = $likes['likes']; } echo $likes; ?> Hi. What am I doing wrong he Code: [Select] mysql_query("DELETE FROM availability WHERE id = '$_POST['id']'"); I am able to echo the id but I must be entering the post item incorrectly into the delete string. Can anyone show me my mistake? Thanks I am sorry even i didn't say hello to forum but i need this snippet very urgently. i have Zero knowledge of PHP but unfortunately i need a small code as follow. I'm just trying to get suggestions on what people think would be the best way to go with this. With the bottom part of this card where it s tarts working with the foreach loop its taking what was a UL and for each of each LI's and updating a table with its new data however this way isn't going to work as this is editing a user. Because there could be 5 in the database but the new edit user has only 4 lis so I'm sure you could all see the issue here. What I'm thinking would be best is to have it DELETE the existing characterIDs that have WHERE handler_ID = $handlerID and then just do a new INSERT statement. Anyone else think this would be the best way to go about this? Code: [Select] if (mysqli_num_rows($Qresult) == 0) { $query = "UPDATE `handlers` SET `userName` = '".$userName."', `password`='".$password."', `firstName`='".$firstName."', `lastName`='".$lastName."', `statusID`='".$statusID."', `isAdmin`='".$admin."', `defaultCharID`='".$defaultCharID."', `email`='".$email."' WHERE `ID` = '".$handlerID."'"; mysqli_query($dbc, $query); foreach ($characterIDs as $cID) { $query2 = "UPDATE `handler_characters` SET `handler_id` = '".$handlerID."', `characterID` = '".$cID."'"; mysqli_query($dbc, $query2); } $result = "good"; } Hi, I gave the following php script: #!/usr/bin/php -f <?php require_once(dirname(dirname(__FILE__))."/modules/common/common.config.inc.php"); $path = $conf["root"]."/media/images/tricouri/tmp/"; $command = "rm -Rf".$path."*"; if(exec($command)) { echo "Folder cleared\n"; } else { echo "Folder clear failed\n"; } ?> I want to delete some .png files from the ./tmp folder and I receive a rm error: Quote rm: invalid option -- / Try `rm --help' for more information. Folder clear failed The rm -rf command sintax is ok on the linux bash, but from php i receive the error. Php safe mode is off. Can someone help, please ? Hi, When i launch my code i get the following php error: Warning: unlink(../files/"yCUuH0223e3d6d046acb58678fbb54042e0fe.pdf") [function.unlink]: Invalid argument in C:\xampp\htdocs\intra\VVS\admin\fakture-edit.php on line 74 But in the dir: C:\xampp\htdocs\intra\VVS\files\ The file exists.. here's my php code: Code: [Select] $id = mysql_real_escape_string($_GET['id']); $fil = mysql_real_escape_string($_GET['fil']); $result2 = mysql_query("SELECT * FROM fakture WHERE id=('$id') LIMIT 1"); $row2 = mysql_fetch_array($result2); if ($_GET["op"] == "process") { if (!unlink('../files/"'.$fil.'"')) Hi, this is the first time I've asked for some help from a forum. I guess this code has sort of got me stumped. So, I have a system where a user can enter a number. The number goes into a mysql database. A random number is also generated and it is added into another column. So, I want users to be able to delete the number using the random number. I've shown it to them, and I need help working my delete script. Code: [Select] <?php $con = mysql_connect("localhost","",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("a8784hos_adopts", $con); $adopt = $_POST['adoptid']; $uniquecode = $_POST['uniquecode']; $result = mysql_query("SELECT uniquecode, id FROM id WHERE id='$adopt'"); mysql_fetch_array($result); if (($adopt == $row['id']) || ($uniquecode == $row['uniquecode'])){ mysql_query("DELETE FROM id WHERE id='$adopt'"); echo 'Done! <br/><br/><a href="tester.php">Go back....</a>'; } else { echo 'Bad unique code. <br/><br/><a href="tester.php">Go back....</a>'; } ?> So, the random number is uniquecode in the database, and the number is id. However, when I try this code, it always tell me I have a bad unique code. What am I doing wrong? Thanks. Does anyone have a code that will automatically delete stuff out of the database after 30 days of being in there...? I'm trying to delete the <identifier> node of some XML, using the following code; unsuccessfully.
Can someone help me identify where I'm going wrong? TIA
$newXML = ""; $xmlString = Fedora_API::callGetDatastreamContents($this->pid, 'MODS', true); $doc = DOMDocument::loadXML($xmlString); $xpath = new DOMXPath($doc); $fieldNodeList = $xpath->query("/identifier"); foreach ($fieldNodeList as $node) { $fieldNodeList->removeChild($node); } $newXML = $doc->SaveXML(); Ok If anyone read my recent topics they will know I am making a forum system This system for users is currently about 1/3 complete and I now have a couple of issues. Firstly: When a user logs in I am using $_SESSION['RAYTH_MEMBER_ID'] to save their member ID for when they return. However every time the browser/page is closed it doesn't save and then they are logged out. How would I set it so it keeps them logged in until they personally logout? Secondly: Since It's a forum you expect there to be new lines and stuff when you Read posts in threads (like we do here). How would I set it when a user posts it replaces every return character from the input (enter/newline etc) and replace it with <br> in the mysql database? Thanks for your help By not using the order by function in SQL. Like I have $match_1 and $segment_1. They are two seperate tables so how would I order them like the ORDER BY in sql. Is there a way to do that? This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=328221.0 ok , here is my mysql code to get all posts from the posts table . Code: [Select] $query = mysql_query("SELECT id,to_id,from_id,post,type,state,date FROM posts WHERE state='0' ORDER BY id DESC LIMIT 50"); and here is the code to display the users friends... Code: [Select] $sqlArray = mysql_query("SELECT friend_array FROM myMembers WHERE id='" . $logOptions_id ."' LIMIT 1"); while($row=mysql_fetch_array($sqlArray)) { $iFriend_array = $row["friend_array"]; } $iFriend_array = explode(",", $iFriend_array); if (in_array($id, $iFriend_array))see now i got as far as , if(in_array($id, $iFriend_array)) How would i put these togeather to where it would get the posts from the posts table that there friends posted? ok so i have my login page all set up and working good , but i want to add a special thing to where after 3 login attempts it locks the account for like 30 mins , and notifies the use by email that someone is trying to login and failed... what would be the best way to do this? How can i make code which can do something when time is 00:00 ? Is that possible in php, and if not any suggestions? I've seen two post now about not deleting within a loop and I think I may need to ask a question about this. I have a photograph db that gives the addresses of the thumbs and photos in files for a product, it also is keyed to the products db. There can be more than one photo per product. If someone selects yes from a radio button and clicks submit the process should delete the record of the product in the product db, delete the photos in the photo images/files(this is the loop) and then delete the product id and row in the photo db Is this a decent way of doing this? if ($_POST['sure'] == 'Yes') { // If Yes delete the item and its pictures in image folders $q = "DELETE FROM product WHERE id = $item LIMIT 1"; // Delete the product record $r = @mysqli_query ($dbc, $q); $q = "SELECT id, thumb, photo FROM photos WHERE id = '$item'"; $r = @mysqli_query ($dbc, $q); if ($r){ while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)){ unlink('images/members/'.$row['thumb'].''); // Remove-delete photos from folders for each row in photo db unlink('images/members/'.$row['photo'].''); } } $q = "DELETE FROM photos WHERE id_prod = $item"; // Delete the photo record $r = @mysqli_query ($dbc, $q); // When through redirect header("Location: $home/member/index.php?user=$mem_id"); exit(); } |