Home Community Mys-Script Creative Off-Topic |
|
|
Thread Tools | Display Modes |
#1
|
||||
|
||||
Delete query deletes from all usesrs
Why does this
Code:
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; } |
#2
|
||||
|
||||
bump. Ideas, friends?
|
#3
|
||||
|
||||
The problem is in this code not the above code:
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.'; } |
#4
|
||||
|
||||
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().
__________________
Mysidia Adoptables, a free and ever-improving script for aspiring adoptables/pets site. |
#5
|
||||
|
||||
So what would that look like?
|
#6
|
||||
|
||||
This should suffice:
PHP Code:
__________________
Mysidia Adoptables, a free and ever-improving script for aspiring adoptables/pets site. |
#7
|
||||
|
||||
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.
|
#8
|
||||
|
||||
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().
__________________
Mysidia Adoptables, a free and ever-improving script for aspiring adoptables/pets site. |
#9
|
||||
|
||||
I do.... must not have come across those O.o
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Database Query: COUNT(*) | Kyttias | Questions and Supports | 5 | 01-19-2015 03:57 AM |
CSS Query .-. | ChibiMaestro | Templates and Themes | 2 | 12-08-2012 05:51 AM |
Having a problem running a query | !Alive | Questions and Supports | 8 | 03-11-2012 02:39 PM |
MySQL Query Empty on default install? (i.e. No edits.) | Flametail | Questions and Supports | 3 | 10-18-2011 12:30 PM |
Join query for optimization? | Arianna | Questions and Supports | 2 | 04-09-2010 12:32 PM |
What's New? |
What's Hot? |
What's Popular? |