View Full Version : Delete query deletes from all usesrs
SilverDragonTears
05-07-2012, 03:45 AM
Why does this
function getdeltabs() {
$formcontent = "";
$result = $GLOBALS['adopts']->select("tabs", array("username", "name"), "username = '".$GLOBALS['username']."'");
while ($row = $result->fetchObject()) {
$tabname=$row->name;
$formcontent = $formcontent."<option value='".$tabname."'>".$tabname."</option>";
$i++;
}
return $formcontent;
}
delete all the users tabs when one person deletes a single tab?
SilverDragonTears
05-11-2012, 11:56 PM
bump. Ideas, friends? :catfish:
SilverDragonTears
05-14-2012, 06:36 PM
The problem is in this code not the above code:
elseif (isset($_POST['deltab'])) {
$name = $_POST['name'];
$query = "SELECT * FROM ".constant("PREFIX")."tabs WHERE username='".$loggedinname."' AND name='".$name."'";
$stmt = $adopts->query($query);
$num = $stmt->fetch(PDO::FETCH_ASSOC);
if($num == 0){
$article_content='This cage does not exist.';
}else{
$adopts->update("owned_adoptables", array("tab" => ''), "owner='{$loggedinname}' and tab='{$name}'");
$adopts->delete("tabs", array(), "username='{$loggedinname}' and name='{$name}'");
$article_content='You successfully deleted the tab. Your hamster was automatically moved to your default cage at the <a href="myadopts.php">My Hamsters</a> page.';
}
Hall of Famer
05-14-2012, 07:32 PM
First of all your script has a problem with the usage of $num. It is an array fetched using a PDO method, and you are checking if its value equals to 0? An array cannot equal to 0 unless it contains only one element(which is considered a string instead), the statement will always evaluate to be false...
On the other hand, you are using the delete() method incorrectly. It does not accept an empty array as its second argument, so get rid of it. I am surprised that you do not receive an error message for the way you use delete().
SilverDragonTears
05-14-2012, 07:33 PM
So what would that look like?
Hall of Famer
05-14-2012, 07:34 PM
This should suffice:
$adopts->delete("tabs", "username='{$loggedinname}' and name='{$name}'");
SilverDragonTears
05-14-2012, 07:40 PM
Ahhh works like a dream. Thought it would look like that but I didn't realize you didn't have to have the array() there.
Hall of Famer
05-14-2012, 07:47 PM
Well you can always browse through the existing script files, including those in admincp, classes and functions directories. There should be plenty of examples that tell you how to use a database method such as update() and delete().
SilverDragonTears
05-14-2012, 07:49 PM
I do.... must not have come across those O.o
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.