PHP - Recursive Delete Function
i have the below script but it doesn't work it just refreshes the page anyone know what is wrong
Code: [Select] <?php $path = "../../gallery/gallery_files/gallery/"; if(isset($_POST['file']) && is_array($_POST['file'])) { foreach($_POST['file'] as $file) { $dirname = $path; //Recursive Delete Function function DELETE_RECURSIVE_DIRS($dirname) { // recursive function to delete // all subdirectories and contents: if(is_dir($dirname))$dir_handle=opendir($dirname); while($file=readdir($dir_handle)) { if($file!="." && $file!="..") { if(!is_dir($dirname."/".$file))unlink ($dirname."/".$file); else DELETE_RECURSIVE_DIRS($dirname."/".$file); } } closedir($dir_handle); rmdir($dirname); return true; } } } ?> Similar TutorialsHello! Maybe I'm a bit ashamed to question some little kind of thing, but I tested 3 hours and couldn't let this function. It's like the most easiest possible recursiv function...: Code: [Select] function recursiv($s){ $s.="b"; if(strlen($s)>30){return $s;} //else return 0; else recursiv($s); } echo recursiv("h"); The result is a blank page... Thanks a lot for your help !! Hi all. Here is my scripts which allow user to check multiple rows of data and delete it , but it require select data and click for twice to delete the rows , what should be the error? Code: [Select] <form name="frmSearch" method="post" action="insert-add.php"> <table width="600" border="1"> <tr> <th width="50"> <div align="center">#</div></th> <th width="91"> <div align="center">ID </div></th> <th width="198"> <div align="center">First Name </div></th> <th width="198"> <div align="center">Last Name </div></th> <th width="250"> <div align="center">Mobile Company </div></th> <th width="100"> <div align="center">Cell </div></th> <th width="100"> <div align="center">Workphone </div></th> <th width="100"> <div align="center">Group </div></th> </tr> </form> <? echo "<form name='form1' method='post' action=''>"; while($objResult = mysql_fetch_array($objQuery)) { echo "<tr>"; echo "<td align='center'><input name=\"checkbox[]\" type=\"checkbox\" id=\"checkbox[]\" value=\"$objResult[addedrec_ID]\"></td>"; echo "<td>$objResult[addedrec_ID] </td>"; echo "<td>$objResult[FirstName]</td>"; echo "<td>$objResult[LastName] </td>"; echo "<td>$objResult[MobileCompany] </td>"; echo "<td>$objResult[Cell] </td>"; echo "<td>$objResult[WorkPhone] </td>"; echo "<td>$objResult[Custgroup] </td>"; echo "</tr>"; } echo "<td colspan='7' align='center'><input name=\"delete\" type=\"submit\" id=\"delete\" value=\"Delete\">"; if (isset($_POST['delete']) && isset($_POST['checkbox'])) // from button name="delete" { $checkbox = ($_POST['checkbox']); //from name="checkbox[]" $countCheck = count($_POST['checkbox']); for($d=0;$d<$countCheck;$d++) { $del_id = $checkbox[$d]; $sql = "DELETE from UserAddedRecord where addedrec_ID = $del_id"; $result2=mysql_query($sql) or trigger_error(mysql_error());;; } if($result2) { $fgmembersite->GetSelfScript(); } else { echo "Error: ".mysql_error(); } } echo "</form>"; Thanks for every reply. I have a function that searches first for a line in a file and then for a string in that line. If the string is not found, it concatenates the line with the next line and so on until it finds the string. The following script works but it is time consuming. I want to put a "break" somewhere so that if the line is found, the foreach will break. Can someone please help and tell me how to do this? If I put the break before the recursive call, it wont do the call. If I put it after, it wont get to the break. Thanks! function findEndTag($file, $line, $consolidatedLine) { $endTagFound = strstr($consolidatedLine,"/>"); if (!$endTagFound) { $fileContent = file($file); foreach ($fileContent as $i => $lineArray) { if ($lineArray == $line) { $consolidatedLine = $consolidatedLine." ".$fileContent[$i+1]; return (findEndTag($file, $fileContent[$i+1], $consolidatedLine)); } } } else { return $consolidatedLine; } } Hi there, I have written a recursive function that basically generates a tree structure for my site pages (kind of like a sitemap). It all worked fine until yesterday, I started getting error messages telling me that I have exhausted the amount of memory available. There are only about 30 pages in the site (parent, child, sub-child etc), so I dont think that I should be using up that much memory. This was my first attempt at a recursive function so I am pretty sure that it may not have been optimised properly. If anyone could take a look and offer any feed back that would be great. (written in codeigniter framework) function getAllPages() { $this->tmp_arr = array(); $this->buildPageStructure(0, 0); return $this->tmp_arr; } function buildPageStructure($parent_id, $counter) { $CI = & get_instance(); $query = $CI->db->query("SELECT page_id, title, page_url, status FROM pages WHERE parent_page='$parent_id' ORDER BY sort_order ASC"); $counter++; if($query->num_rows() > 0) { foreach($query->result() as $row) { $new_arr = new Page(); $new_arr->page_id = $row->page_id; $new_arr->title = $row->title; $new_arr->level = $counter; $new_arr->page_url = $row->page_url; $new_arr->status = $row->status; $this->tmp_arr[] = $new_arr; $this->buildPageStructure($row->page_id, $counter); } } } Cheers Jon Hi, I am using a separate class for all the functions. And using using the following function "objectToArray" to convert the JSON decoded object to Array. Class file: class xyz { . . . . . function objectToArray($d) { if (is_object($d)) { $d = get_object_vars($d); } if (is_array($d)) { return array_map(__FUNCTION__, $d); } else { return $d; } } . . . } Main page: $obj = new xyz(); $arr = $obj->objectToArray($json_obj); Because the function "objectToArray" is recursive, array_map(__FUNCTION__, $d) is not able to applies the callback. And throws the warning "array_map() expects parameter 1 to be a valid callback". Need help! Girish Hey guys, I've got a problem. I need a function, that gives me a menue like that: parent_page1 page1 page2 page3 parent_page2 page1 page2 page3 So.. here is my database structu All what I need, is a function, that gives me a menu like that on top. Do you need some more information? Let me know.. Hey all! I'm writing a simple script to scan a local directory named 'files' and all sub directories of 'files', adding each file to a database in the same table. To do this, I'm using scandir on the current working directory/files to start, and iterating over each file in a loop, but if the file is a directory, I append the directory name to the cwd/files and call scandir on that, creating a list of files in the subfolder, and then I call my addFiles() function recursively, with this as the argument. As of now, it just stops at the second call to addFiles. It adds all the top level files fine, stops there. That's where all my print_r() lines have gotten me. Here's my code... <!-- To change this template, choose Tools | Templates and open the template in the editor. --> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body> <?php include 'DBConnect.php'; $db = new DBConnect() or die("Can't connect to DB"); $conn = $db->getConn(); mysql_select_db('download', $conn) or die("Can't select DB"); $dir = getcwd(); $dir = $dir . '\files' . "\\"; $fid = 1; $dir = addslashes($dir); $files = scandir($dir); echo $fid . " "; echo $dir; function addFiles($files) { global $dir; global $conn; global $fid; unset($files[0]); unset($files[1]); print_r($files); foreach ($files as $aFile) { if (is_file($dir.$aFile)) { echo "<li> $aFile </li>"; $query = "INSERT INTO files (file_id, file_path, file_name) values ($fid, '$dir', '$aFile')"; mysql_query($query, $conn) or die("Something wrong with query"); $fid = $fid + 1; } else if (is_dir($dir.$aFile)) { $fid = $fid + 1; $aDir = $dir . $aFile . "\\"; echo $dir; addFiles(scandir($dir.$aFile)); } } } addFiles($files); ?> </body> </html> Thanks in advance for any ideas. Also, if I'm approaching this problem completely wrong, let me know! I just came up with this and I feel like it should work... Hi all, Ok, simple question... just imagine a multidimensional array, array(array(1,2,3,array(4,5,6, array(7,8,9)))); how to build a recursive function that will unpack all the arrays into 1 array. Somehow, none of my tries has worked out properly Cheers I need to create a function that lists subfolders of a given folder, that contain at least one .txt file. I found the following function, which displays a list of file that match a pattern in a directory tree: function find($dir, $pattern){ $dir = escapeshellcmd($dir); $files = glob("$dir/$pattern"); foreach (glob("$dir/{.[^.]*,*}", GLOB_BRACE|GLOB_ONLYDIR) as $sub_dir) //look in subdirectories { $arr = find($sub_dir, $pattern); //recursive call $files = array_merge($files, $arr); // merge array with files from subdirectory } return $files; } $txtFiles=find("project/sys","*.txt"); foreach ($txtFiles as $txtFile) { echo '<h2>'.$txtFile.'</h2>'; //display all text files } My question is, how do I change the function to return only folders that contain at least one text file. But, the functions should look inside child folders of "project/sys" and list a child folder only once if that folder or any of its child folders contain at least one text file. I'll give an example of the output I'm looking for: Folder list project/sys/diagram project/sys/bin project/sys/scripts project/sys/styles project/sys/meta The above folders may not contain a text file directly, but their children folders do. However, I'm not interested in their children folder and I want to list the above level folder only once for each folder. Thanks in advance Hey there I just started out with PHP so it might be a trivial problem. I want to populate an array with values by a recursive function but i don't get it the way i want it to have. Target array (written in python syntax): myArray = { key : [ [a1, a2, a3, a4], [b1, b2, b3 ,b4] ], key2 : [ [c1, c2, c3, c4], [d1, d2, d3, d4] ] } So far i created a recursive function to collect all data i need for the array but i don't get the right syntax to achieve my target array. What i have so far is following code (snippet): function get_data($main_dir, $items=[], $myArray=[], $depth=0) { global $items; if ($myArray == NULL && depth == 0) { $myArray = array(); } $depth++; $dirHandle = opendir($main_dir); while ($file = readdir($dirHandle)){ if(is_dir($main_dir.$file) && $file != "." && $file != "..") { $new_dir = $main_dir.$file."/"; $items = get_data($new_dir, $items, $myArray, $depth); $myArray = $items[1] $items = $items[0] } else { splitted_dir = preg_split("/\//", $main_dir); key = splitted_dir[2]; file_information = read_out_file($main_dir.$file); information_1 = file_information[0]; information_2 = file_information[1]; myArray = array_merge($myArray, array($key, array($key, $information_1, $information_2, $main_dir, $file)) } } } The array contains all informations i need but the structure of it is not useable. Current output: Array ( [0] => key1 [1] => Array ( [0] => key1 [1] => information_1 [2] => information_2 [3] => ./path/ [4] => filename ) [2] => key1 [3] => Array ( [0] => key1 [1] => information_1 [2] => information_2 [3] => ./path/ [4] => filename ) [4] => key1 [5] => Array ( [0] => key1 [1] => information_1 [2] => information_2 [3] => ./path/ [4] => filename ) [6] => key2 [7] => Array ( [0] => key2 [1] => information_1 [2] => information_2 [3] => ./path/ [4] => filename ) [8] => key2 [9] => Array ( [0] => key2 [1] => information_1 [2] => information_2 [3] => ./path/ [4] => filename ) ) 1 ## IDK why this "1" at the end gets printed out... But what i want to get is this: Array ( [key1] => Array ( Array ( [0] => key1 [1] => information_1 [2] => information_2 [3] => ./path/ [4] => filename ) ) Array ( [0] => key1 [1] => information_1 [2] => information_2 [3] => ./path/ [4] => filename ) ) ) [key2] => Array ( Array ( [0] => key2 [1] => information_1 [2] => information_2 [3] => ./path/ [4] => filename ) ) Array ( [0] => key2 [1] => information_1 [2] => information_2 [3] => ./path/ [4] => filename ) ) ) )
At the end i want to sort the output by alphabetic order of the keys which i should achieve with sort() i guess?
Greetings Edited August 10, 2019 by Sandy_85Hi, I am trying to recursively build another array based on the one I get back from our CRM api. The array I get back looks like this: Code: [Select] [1] => stdClass Object ( [description] => Description Text [label] => Product [name] => Product [sobject] => KnowledgeArticleVersion [topCategories] => stdClass Object ( [childCategories] => Array ( [0] => stdClass Object ( [childCategories] => Array ( [0] => stdClass Object ( [childCategories] => Array ( [0] => stdClass Object ( [label] => Apple [name] => Apple ) [1] => stdClass Object ( [label] => Orange [name] => Orange ) [2] => stdClass Object ( [label] => lemon [name] => lemon ) ) [label] => Templates [name] => Templates ) [1] => stdClass Object ( [label] => Connector [name] => Connector ) [2] => stdClass Object ( [label] => AeroView [name] => AeroView ) ) [label] => AeroWare [name] => AeroWare ) [1] => stdClass Object ( [label] => BackOffice [name] => BackOffice ) [2] => stdClass Object ( [label] => OutWare [name] => OutWare ) [3] => stdClass Object ( [childCategories] => Array ( [0] => stdClass Object ( [label] => ERA [name] => ERA ) [1] => stdClass Object ( [label] => Kairos [name] => Kairos ) ) [label] => InWare [name] => InWare ) ) [label] => All [name] => All ) ) The child categories could be any level deep. I would like put it in an array something like this: Code: [Select] Array ( [label] => Cat 1 [level] => 0 [children] => Array ( [label] => Sub Cat 1 [level] => 1 [children] => Array ( [label] => Sub Sub Cat 1 [level] => 2 ) ) ) I have tried so many things but I just can't get it right. Any assistance would be greatly appreciated. Thanks Peter I'm trying to return to array of letters that bruteForce finally decides upon. However, I can't seem to pass the array to librarySolve. I'm feeling dumb, any help? Code: [Select] function librarySolve($string){ $temp = $this->bruteForce($string, FALSE, 0); return $temp; } function bruteForce($string, $state, $trys){ $base = $string; $state = $state; $new_letters = array(); if($trys <= 6000){ $this->new_letters = $this->generateRandomCipher(); $string = preg_replace('/[^a-zA-Z0-9-\s]/', '', $string); for($a=0;$a<=strlen($string);$a++){ $letter = substr($string, $a, 1); $pattern = "/[A-Z]/"; if(preg_match($pattern, $letter)!=0){ $new_letter = $this->new_letters[$letter]; } else if(preg_match($pattern, $letter)==0) { $new_letter = $letter; } $decipher .= $new_letter; } $word_array = explode(" ", $decipher); $count = 0; for($a=0;$a<count($word_array);$a++){ $do = $this->checkWord($word_array[$a]); if(!empty($do)){ $count++; } } if($count>=2){ $state = TRUE; } else { $state = FALSE; } if($state==TRUE){ return $this->new_letters; } else { $trys++; $this->bruteForce($base, $state, $trys); } } } Hi there, hope one of you can help me with a problem im just having. Ok, lets start with the explanation what i want to to: I'd like to collect headlines from a html site, and get the test results in an array, so that the array structure represents the dom-levels of the site. Small Example: <h1>test1.1<h1/> <h2>test2.1</h2> <h2>test2.2</h2> <h3>test3</h3> <h1>test1.2<h1/> Shoul end in a array structure like: Code: [Select] array('level 1' => array ( 'sibble1' => array ( 'headline' => 'test1.1', 'level2' => array( 'sibble1' => array ( 'headline' => 'test2.1', 'level3' => array(), // empty data, needs to be processed anyway to find gaps, to maybe a h4 headline would be existing ), 'sibble2' => array ( 'headline' => 'test2.2', 'level3' => array ( 'sibble1' => array ( 'headline' => 'test3.1', 'level4' => array(), // empty data, needs to be processed anyway to find gaps, to maybe a h4 headline would be existing ), ), ), ), ), 'sibble2' => array ( 'headline' => 'test1.1', 'level2' => array(), ), ), ); So i hope out of this example you can see what i want to do. level represents the healdine level 1-9, sibblin is as name for the childs on the headline level. Ok, so to extract the herefore needed data out of the html, i build a class with a recursive function, that filters the html by a regex from one headline to the next, first iteratin all childs, if there are no more childs i go tho ne nextsibbling element. as an running example code look he Code: [Select] <?php class Application_Model_DomParser { const PREG_MATCH_ONE_ELEMENT_TO_MUCH_LENGTH = 4; private $slicedFields = array(); public function __construct() { } public function sliceFirstSectionToDataFields($level = 1, $haystack) { preg_match_all("#(.*?)<h$level>(.*?)</h$level>(.*?)(<h$level>|$)#s", $haystack, $data); // prepare the chunkData $pageText = ''; if (isset($data[1][0])) { $pageText = $data[1][0]; } $headline = ''; if (isset($data[2][0])) { $headline = $data[2][0]; } $dataToProcessNextLevel =''; if (isset($data[3][0])) { $dataToProcessNextLevel = $data[3][0]; } // @todo dirty warnings compression, search why warning occures @$posOfNextChild = strlen($data[0][0]) - self::PREG_MATCH_ONE_ELEMENT_TO_MUCH_LENGTH; // from here goes the debug... echo $headline ."::" .strlen($dataToProcessNextLevel). "<br>"; if (strlen($dataToProcessNextLevel) <= self::PREG_MATCH_ONE_ELEMENT_TO_MUCH_LENGTH) { if ($level < 9) { $dataToProcessNextLevel = $haystack; } else { return; } } //recursive check for next level in $dataToProcessNextLevel $nextLevel = $level + 1; $this->sliceFirstSectionToDataFields($nextLevel, $dataToProcessNextLevel); $haystack = substr($haystack, $posOfNextChild); // slized To The End if (self::PREG_MATCH_ONE_ELEMENT_TO_MUCH_LENGTH == strlen($haystack)) { // die("slized To The End"); return; } // recursive check for other childs in actuall level... $this->sliceFirstSectionToDataFields($level, $haystack); } } $htmlString = 'test<h1>headkline1.1</h1> <p>test test</p> <h2>headline 2.1</h2>test test <h2>headline 2.2</h2> <p>tes test test</p> <h3>headline 3.1</h3>test <h3>headline 3.2</h3>test <h2>headline 2.3</h2> <p> </p> <p>test</p> <h1>headline 1.2</h1> <h2>headline 2.4</h2> <p>11111111111112222222222222222222222</p> <p> ewfwrefg upowmdg w3q09umq09wrt n3q089ty 3q0898943ty -98 41</p> <h3>headline 3.3</h3> <p>test</p> <p>test</p> <p>test</p> <h1>1.3 testtest</h1> <p>test</p> <h3>head 3.4</h3> <p>sadfsadfsadf asdfsda f sdaas saf saddas</p> <h3>head 3.4</h3> <h3>test 1.3</h3> <p>test;</p> '; $model = new Application_Model_DomParser(); $result = $model->sliceFirstSectionToDataFields(1, $this->htmlString); So letting this piece of code run, you can se via the debug echo, every headline is found, even in the right order of its occurence. My problem now is dont get it how to return the extracted values, and collect them to get a result as my above shown structure shows. So i spent ours to solve this problem but didnt come to a result. I know its a hard problem, and to help me takes time, cause its a complex situation. Allthough i hope someone knows a anser. I need this problem solved, to get my mind rested! Thanks, and greetings Selma I made a private messaging system. There is a select all checkbox, but how do I create a function that says delete all of the selected messages? I'm just looking for some logic on this. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=328704.0 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>"); } ?> Hello Everyone, I am writing a simple CMS system for someone. I am having trouble getting the delete function to work. I pick the user that I want to remove from the system. I verify that this is the right person to remove. Then the record is deleted from the database. The part that picks the person and verifies that it is the right person to remove from the database work fine. It is the part that actually deletes the record. It takes me back to the pick_user.php. If someone could help me with this I would appreciate it This is the code from the show_user_del.php <?php if (!$_POST[id]) { header ("LOCATION: pick_user.php"); exit; } if ($_COOKIE[auth] != "ok") { header("Location: ../login.php"); } require('../includes/auth_user.php'); //build and issue query $sql = "SELECT * FROM $table WHERE id = '$_POST[id]'"; $result = mysql_query($sql, $connection) or die(mysql_error()); while ($row = mysql_fetch_array($result)) { $f_name = $row['f_name']; $l_name = $row['l_name']; $username = $row['username']; $password = $row['password']; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Add Classified Ad</title> </head> <body> <h2><em>Delete user from Database</em></h2> <h3>User being deleted <?php echo "$f_name $l_name"; ?></h3> <form method="POST" action="do_delete_user.php"> <input type="hidden" name="id" value="<?php echo "$_POST[id]"; ?>" /> <input type="hidden" name="f_name" value="<?php echo "$f_name"; ?>" /> <input type="hidden" name="l_name" value="<?php echo "$l_name"; ?>" /> <p> <strong>Name:</strong> <?php echo "$f_name $l_name"; ?> </p> <p> <strong>Username:</strong> <?php echo "$username"; ?> </p> <p> <strong>Password:</strong> <?php echo "$password"; ?> </p> <p> <input type="submit" name="submit" id="name" value="Delete User" /> </p> </form> <p><a href="../admin_menu.php">Return to Administration Menu</a></p> </body> </html> When the submit button is clicked in the above code. It is supposed to bring you to the page below saying that the record was deleted. When the submit button is clicked it sends you back to the pick user page. <?php if ((!$_POST[f_name]) || (!$_POST[l_name])) { header ("LOCATION: show_user_del.php"); exit; } if ($_COOKIE[auth] != "ok") { header("Location: ../login.php"); } require('../includes/auth_user.php'); $sql = "DELETE FROM $table WHERE id = '$_POST[id]'"; $result = mysql_query($sql, $connection) or die(mysql_error()); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <h1>User has been removed</h1> <h2><em>User <?php echo "$_POST[f_name] $_POST[l_name]"; ?> has been deleted from the <?php echo "$table"; ?> table</em></h2> <p><a href="pick_user.php">Delete another person</a></p> <p><a href="../admin_menu.php">Administration Menu</a></p> </body> </html> hello there.. im planning to create a simple Online Users that is integrated to Facebook sdk. So far, i have the ff codes: index.php (this is where the online users listed) Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Online Users</title> <link type="text/css" rel="stylesheet" href="style.css" /> <script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript" src="js/ouser.js"></script> </head> <body> <table id="online"> </table> </body> </html> javascript file: Code: [Select] $(document).ready( function() { setInterval (loadLog, 2500); }); function loadLog(){ $.ajax({ url: "onlineusers.html", cache: false, success: function(html){ $("#online").html(html); }, }); } test.php (This is my temporary file to test the Login authentication for FB.. THIS IS WORKING) Code: [Select] <?php session_start(); require_once("src/facebook.php"); $config = array( 'appId' => '285873338131549', 'secret' => '56b9f71b9fd307a033aeeb725893fc89', ); $facebook = new Facebook($config); $user_id = $facebook->getUser(); ?> <?php if($user_id) { try { $user_profile = $facebook->api('/me','GET'); $profile = $user_profile['name']; $_SESSION['user'] = $profile; //PUT USER TO SESSION $_SESSION['user_id'] = $user_id; $line = file_get_contents("onlineusers.html"); $line = trim($line); // removes leading/trailing blank lines $line = explode("\n", $line); $line[] = '<tr><td><img src="https://graph.facebook.com/' . $_SESSION['user_id'] . '/picture"width="25"height="25"/></td><td>' . $_SESSION['user'] . '</td><td><a href="http://www.fb.com/' . $_SESSION['user_id'] . '" target="_blank">View Profile</a></td></tr>'; $line = array_unique($line); $line = implode("\n", $line); file_put_contents("onlineusers.html", $line); echo 'OK'; } catch(FacebookApiException $e) { $login_url = $facebook->getLoginUrl(); echo '<a href="' . $login_url . '">LOGIN</a>'; error_log($e->getType()); error_log($e->getMessage()); } } else { $login_url = $facebook->getLoginUrl(); echo '<a href="' . $login_url . '">LOGIN</a>'; } echo "<a href='logout.php'>Logout</a>"; ?> What it does is, it simple insert the picture and name of the user in a flat html file.. http://www.barkadafm.org/onlineusers/index.php Now, my problem is,. I dont know how to delete the pic and name if a user logs out or disconnect.. Example, my name is Name5 and i will connect / login using http://www.barkadafm.org/onlineusers/test.php for the first connect, my name and picture will be inserted to my flat html file.. Let's assume that there'are already 4 users online.. and the 5th data will be mine. Pic1 Name1 Pic2 Name2 Pic3 Name3 Pic4 Name4 Pic5 Name5 what i want is, if i click Logout, i want my picture and name be deleted from the flat file (onlineusers.html) and destroy my 2 variables set at test.php Please help me.. Thank you! Hi, ppl, my problem is that whenever the DELETE link is clicked, a javascript confirm box pops up and it should only delete the record with the ID from the $_GET global array if the user clicks the OK button, otherwise it should just redirect to the table of entries WITHOUT DELETION, but somehow it IS DELETING even when CANCEL button of javascript confirm box clicked. Here's my code below: <html> <head><title> </title> </head> <body> <?php require "bellConnect.inc.php"; $ID=$_GET['ID']; $result=mysql_query("SELECT * FROM bellProducts WHERE ID=$ID"); $row=mysql_fetch_assoc($result); $name=$row['Name']; $manufacturer=$row['Manufacturer']; print "Value of ID is $ID"; ?> <script type='text/javascript'> var confirmDelete=confirm("Are you sure you want to delete <?php echo "$name $manufacturer"?> ?"); if(confirmDelete) { <?php $deletedResult=mysql_query("DELETE FROM bellProducts WHERE ID=$ID"); ?> alert("<?php echo "$name $manufacturer" ?> has been deleted successfully."); window.location="http://localhost/index.php"; } else if(!confirmDelete) { window.location="http://localhost/index.php"; } </script> </body> </html> **please help me someone!!! thanks I am attempting to build an online shopping cart, however I have a problem with the Delete /Remove Item function. Add New and Update Item work perfectly fine, just the Remove Item doesn't. It seems to be mirroring the same functionality as Update Item. http://www.tottonc.co.nz to see my problem in action. Any help or solutions would be much appreciated... |