The following warnings occurred: | ||||||||||||||||||||||||
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
|
View As User - Printable Version +- UserSpice (https://userspice.com/forums) +-- Forum: Support Center (https://userspice.com/forums/forumdisplay.php?fid=23) +--- Forum: UserSpice 4.3 and Below (https://userspice.com/forums/forumdisplay.php?fid=26) +--- Thread: View As User (/showthread.php?tid=344) |
View As User - Brandin - 11-24-2016 I just can't get my head gripped around the differences, like for example, I would use: Code: $query = "SELECT * FROM Code: WHERE Code: ='$uid' Code: $result = mysqli($connect,$query) Code: $connect Code: db.php How do I translate something like that to PDO? And like how do you do inserts and deletions. I just don't get it lol. View As User - dan - 11-24-2016 $query=$db->query("Select * from users where id = ?", array($uid)); Then since you are only expecting one result you do $results = $query->first(); The deal with the question marks in the queries is a security feature that forces it to only look in that one column for the information and stops people from doing some hackery type things. If your query was expecting multiple results then you would switch out the word first for results. If you are searching for multiple things you just put a? After each one and then put a comma between every variable in the array View As User - Brandin - 11-24-2016 Now how do you handle deletions and stuff? If I'm using a table of values, how do I produce certain columns? Like with mySQLi and PHP, I have this table: http://hastebin.com/itelevuvoj.xml How would I format this code for PDO? I appreciate your help! View As User - mudmin - 11-24-2016 So this is where the whole results vs first comes in. If you're only going to get 1 user or 1 item because you are searching by id or something that is unique, you use Code: $result=$query->first(); Code: $result->columname. BUT, say you are looking for all of your orders (like in your example), it's this... Code: $query = $db->query("SELECT * FROM ORDERS"); Code: $results = $query->results(); That gives you an object (You can see that if you do dump($results) So you most likely want to do a foreach loop to generate your table of orders. Do your table headings... Code: <thead> Code: <tr> Code: <th>Delete</th><th>ID</th><th>Date</th><th>Order Number</th><th>Functions</th> Code: </tr> Code: </thead> THEN you foreach your rows Code: <?php Code: foreach ($results as $result) { Code: ?> Code: <tr> Code: <td><?=$result->id?></td> Code: <td><?=$result->date?></td> Code: <td><?=$result->ordernumber?></td> Code: <td><?=$result->system?></td> Code: <tr> Code: <?php } ?> View As User - Brandin - 11-25-2016 OHHHHHHHHHHH. Hmmmmmm. I like. This is simpler than I thought! NOW! Lets pretend orders are removable from this table. Pretend I have added a Function column, and there is a button that performs runs through JS, blah blah. Okay, it is now at the Delete function. This is what I currently have: http://hastebin.com/efebabinip.xml How do I move this to PDO? You're getting me somewhere I appreciate you guys taking your time to help me with this. View As User - mudmin - 11-25-2016 So, in that situation, you are already getting the id on every row (even if you don't want to show it). I tend to like to redirect people to a different page if they're deleting so you can put as many confirmations and checks as you want in there, so you would add a row like this to the table... <td>Delete this Item</td> Then the delete_item.php page would pull in the id... Code: $itemID = Input::get('id'); Then you do whatever confirmations you want to do to make sure they're sure and delete the item.... $db->delete('items',array('id','=',$itemID)); The format is ('tablename', and then an array with the 'columname', 'your operator, usually equals, but could be anything', $variable). View As User - Brandin - 11-25-2016 Beautiful, I'm going to play with this a bit and I'll be back for more LOL. View As User - Brandin - 01-12-2017 Mudmin, I'm trying to use the Code: $theUserQ Code: $theUser-> Code: $secondUserQ Thanks! View As User - Brandin - 01-12-2017 Neveremind! I was missing my result line! Sorry! View As User - Brandin - 03-19-2017 Alright, So I built this, and scrapped it. It worked well, but was hard to maintain when making new pages. It was even harder to take out of my system lol, gave me a reason to fully convert to PDO tho, which is good! I have a new idea though. Have a space in the admin panel to generate a "master password", valid for only 60 minutes, in which after the 60 minutes, an auto-cron (which I can make myself) will just make a new one. My thought is this: -The auto cron will change it every 60 minutes so nobody can ever know what it is -When the Admin wants to obtain the master password, they enter the admin panel, and just generate a new one, in which case when you press the button, the system will provide you a plain text master password -They can use this master password to enter any account (this feature will only be open to System Admins, so I don't need to worry about them breaking stuff or giving themself extra access, etc) -They will use it by going to the login page, entering the username and using the Master Password I need to know the following: During the login process, how can I have the DB first check for the users password and determine: 1) if valid - continue 2) if invalid - move to next Check the Master Password 1) if valid - continue 2) if invalid - return the "password invalid blah blah" error I would obviously want to hash the password the same as users password, as I would want it hashed in the DB so it can't be retrieved, what do I need to do to accomplish this? Your help is GREATLY appreciated |