I will look at that more closely when I get home, but if you think something could be interfering then put the "deleting" code on a separate page, by itself, and see if it works then. If it does, than something is interfering within the main script.
I will look at that more closely when I get home, but if you think something could be interfering then put the "deleting" code on a separate page, by itself, and see if it works then. If it does, than something is interfering within the main script.
I am Abby (05-04-2010)
After getting rid of the other php code, I still had the same problem.
keep troubleshooting...
PHP Code:// Deleting an Announcement)
if ( $_POST['deletechecker'] == 1 )
{
// check that the code is being triggered
echo $_POST['deletechecker'];
// $dcount = array();
// the above line IS COMMENTED OUT in your script, correct?
$dcount = $_POST["dcount"];
// Check that we're getting the correct $dcount value
echo $dcount;
$file = '../sidebar.xml';
$xml = simplexml_load_file($file);
$i = 0;
foreach($xml as $kid){
// see what we're comparing $dcount to each time
echo $kid->id;
if($kid->id == $dcount){
// see if script finds a match
echo $kid->id.' is equal to '.$dcount;
// make sure it's the right entry
echo $xml->myquotes[$i];
unset($xml->myquotes[$i]); break;
}
$i ++;
}
$xml = $xml->asXML($file);
}
I think I found the problem but do not understand.
when I echo $dcount, the reply is "Array" and becuase of this it is never equal to $kid->id.
The question is why is $dcount = Array instead of being an array?
I saw this before which lead me to comment out "$dcount = array();"
Last edited by I am Abby; 05-04-2010 at 04:28 PM. Reason: add more inforamtion
It IS an array. That's what you want. "echo" can only work with strings.
When you use "echo"+[non-string] the result will be a warning of sorts, like "array" or "resource" (for something like a mysql query).
(array(1)==array(1)) is true.
(array(1)==array(2)) is false.
There's no reason you can't match arrays.
But if you want to "echo" an array, you need to use another function. The common one is print_r($array);.
Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
I am Abby (05-04-2010)
worked fine.Code:print_r($dcount)
So the problem seems to be on the linewhen I do an echoCode:if($kid->id == $dcount);I get nothing back.Code:$kid->id;
Or is the problem with the foreach lineI get no response fromCode:foreach($xml as $kid){Code:echo $kid;
The problem has to be in the if statements. I just changed it to a not equal statement and echoed "hello" which was triggered for every record in my .xml file.
To echo on an array you had to do the print_r($array)...do we also need a trick for using them in if statements?
something like
Code:if(in_array($kid->id, $dcount))
I love you guys. It works!
I thought that might be the problem - we added that a while back because you might have had multiple entries to delete. But then, I saw that the$dcount = array();line was commented out, so I figured it was something else. But it's still an array because your html inputs are named "dcount[]". Duh.
I'm glad you got it figured out!
Bookmarks