The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
View As User
#21
I just can't get my head gripped around the differences, like for example, I would use:
Code:
$query = "SELECT * FROM
orders
Code:
WHERE
user_id
Code:
='$uid'
Code:
$result = mysqli($connect,$query)
Code:
$connect
is grabbed from the
Code:
db.php
file

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.
  Reply
#22
$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
  Reply
#23
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!
  Reply
#24
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();
Then to get the item back, you do

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)Wink

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 } ?>
  Reply
#25
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 Wink I appreciate you guys taking your time to help me with this.
  Reply
#26
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).





  Reply
#27
Beautiful, I'm going to play with this a bit and I'll be back for more Wink LOL.
  Reply
#28
Mudmin,

I'm trying to use the
Code:
$theUserQ
and
Code:
$theUser->
function we discussed in here, but because it is used in the navigation already, I can't use it for another purpose further down in another script. How can I make a second function called
Code:
$secondUserQ
.

Thanks!
  Reply
#29
Neveremind! I was missing my result line! Sorry!
  Reply
#30
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 Smile
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)