PHP - Not Deleting
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; ?> 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 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, 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. 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 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. 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(); 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"; } Does anyone have a code that will automatically delete stuff out of the database after 30 days of being in there...? 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. Hi fellas, i am wondering if someone can point me in the right direction? I have a simple upload script where users can upload thier profile picture, but if they want to change that picture i would like to delete the old one, to save space and time cleaning up the left overs. So, without further ado, i gather the info from the existing database: $existingimage = "/profileimage/". $userid2['image']; Then further on in the script when it comes time to add or update the image i have: if (!empty($existingimage)) {unlink($existingimage);} $insert= ("UPDATE userdatabase SET image='$finalname' WHERE user='$userid'"); mysql_query($insert); Only problem is, the unlink part dont work, the original image is still there! Any clues? i trying to delete messages out of my message database but im not sure if i'm using this code right or there stuff missing to it :S delete.php <?php require_once('settings.php'); checkLogin('1 2'); $id=$_GET["msgs"]; mysql_query("DELETE messages FROM messages WHERE message_id='$id'"); ?> link usages to delete <a href="delete.php?msgs=<? echo $row['message_id'] ?>">[X]</a> please just deleting this post I think i figured it out This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=318433.0 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(); } Ok I am trying to delete some rows from a database. I have done this before with success so I thought I could use the same method just modify it a little and it would work. Man was I wrong. Any help on this is much appreciated below is my code. Code for the Query to get the data from the database and for displaying the results in a table: Code: [Select] //GET DATA $sql = "SELECT * FROM `".$tblname."` ORDER BY $orderby $sort LIMIT $startrow,$limit"; $result = mysql_query($sql) or die(mysql_error()); $result2 = mysql_query($sql); //START TABLE AND TABLE HEADER echo "<form name='form1' method='post' action=''><table style='font-size:9.5px;'>\n<tr><th>Delete</th>"; $array = mysql_fetch_assoc($result); foreach ($array as $key=>$value) { if($config['nicefields']){ $field = str_replace("_"," ",$key); $field = ucwords($field); } $field = columnSortArrows($key,$field,$orderby,$sort); echo "<th>" . $field . "</th>\n"; } echo "</tr>\n"; //reset result pointer mysql_data_seek($result,0); //start first row style $tr_class = "class='odd'"; //LOOP TABLE ROWS while($row = mysql_fetch_assoc($result)){ echo "<tr ".$tr_class.">\n<td><a href='remove_rec.php?id=". $rows['ID'] . "'><p>Delete</p></a>"; echo "</td>"; foreach ($row as $field=>$value) { echo "<td>" . $value . "</td>\n"; } echo "</tr>\n"; //switch row style if($tr_class == "class='odd'"){ $tr_class = "class='even'"; }else{ $tr_class = "class='odd'"; } } //END TABLE echo "</table>\n</form>"; Here is the code that should delete the row: Code: [Select] $tblname = 'tablename'; // get value of id that sent from address bar $id=$_GET['ID']; // Delete data in mysql from row that has this id $sql="DELETE FROM $tblname WHERE ID='$id'"; $result=mysql_query($sql); // if successfully deleted if($result){ echo "Deleted Successfully"; echo "<BR>"; echo "<a href='leads3.php'>Back to Results</a>"; } else { echo "ERROR"; } When I click on the link to delete a record it redirects me to the appropriate page with the "Deleted Successfully" message but when I go to view the results the row was not deleted. Any help on this would, again, be greatly appreciated. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=355218.0 I'm trying to write a PHP program that a user will use to register to my site. I have a temporary table temp for which the user's information will be stored until they verify their account using an email that is sent to them. Once they verify their account through email, the information stored in the temporary table will be moved to a table called 'users'. I then want to delete the temporary data that they had stored. Unfortunately I'm having trouble doing this. This snippet of code isn't exactly the entire code, but just a test I've been using since I realized that my real code wasn't working as far as deletion goes. Here is my test code. Code: [Select] <?php include('connect.php'); $sql2="SELECT username FROM temp WHERE username = 'justin'"; $result2=mysql_query($sql2); if($result2) echo ("Record found"."<BR>"); else echo ("Record not found"); $sql3="DELETE FROM temp WHERE username='justin'"; $result3=mysql_query($sql3); if($result3) echo ("SUCESSFUL DELETION"); else echo ("failed"); ?> In this code, I check the temp table to see if 'justin' can be found. This has consistently returned "Record found". On the other hand, my deletion command has not worked yet and will constantly fail. connect.php is correct as far as I know and has worked flawlessly for the other parts of this small project. Is something wrong here? What could be the problem? I use this this same exact delete for users to delete their own account with no problem for some reason this code below is deleting all my rows in each table Code: [Select] <?php if(isset($_POST['delete'])) { // this is a check box you need to check in order to confirm if(empty($_POST['confirm'])){ echo "You need to check confirm"; }else{ mysql_query("DELETE FROM `users` WHERE `goauld`= ".(int)($_POST['delete_goauld'])); mysql_query("DELETE FROM `game` WHERE `goauld`= ".(int)($_POST['delete_goauld'])); echo "$delete_goauld was deleted<br />\n"; } } ?> Hi, i have delete link for records and it goes to other page to delete all related records in tables. is there away to get confirmation before the delete process starts? <?Php include('session.php'); include('dbcon.php'); if(isset($_GET['Del'])) { $userid = $_GET['Del']; $query = "delete from staff where OracleID='".$userid."'"; $result = mysqli_query($con,$query); if($result) { echo "staff deleted"; } else { echo 'check the errors!'; } $query2 = "delete from attendance_records where OracleID='".$userid."'"; $result2 = mysqli_query($con,$query2); if($result2) { echo "records deleted"; } else { echo 'check the errors!'; } header("location:viewstaff.php"); } else { header("location:viewstaff.php"); } ?> how to add confirm message with php before deletion is processed? How would I make a script that would delete any row in a MySQL table that was more than 7 days old? |