The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (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
how to prepare?
#1
I have this

https://pastebin.com/j06N2nf6

I can replace the $conn with

require_once 'users/init.php';
$conn = DB::getInstance();

That works just fine.

But how do I get the user_id inthere?

I get that this should do the trick.

$user_id = (isset($user) && $user->isLoggedIn())? $user->data()->id : 0;

But if I add these requires to the file things stop working.

require_once $abs_us_root.$us_url_root.'users/includes/header.php';
require_once $abs_us_root.$us_url_root.'users/includes/navigation.php';
  Reply
#2
It sounds like you are getting an error from your query, and since it is printing out the error text before your HTML it is throwing off your page. Your current query is binding the parameters before you set the variables, so if you move your variables up before the binding it should work.

https://pastebin.com/rDt9MQ8C

I also included an example of using the Input class to grab your variable out of $_POST. It sanitizes it so it's safe to display, insert into database, etc.

Test this out and let me know how it goes!
  Reply
#3
Thanks!

I just went with query() eventually which worked.

The abovePasted code worked just fine until I tried to use the usespice db instance. Doing it the way you showed is probably a good idea. I was using bindParam hoping to conveniently change vars and write multiple rows to my database. Something like.


$fff = 1;
$query->execute();
$fff = 2;
$query->execute();
$fff = 3;
$query->execute();
etc

From what I understand (which isn't much) you get to bind a value only one time then are stuck with it.

Going to give your suggestion a try when I have time.
  Reply
#4
You don't really prepare the same way in PDO.

I think spending 35 minutes would be really useful to you if you watched this video. I know it's a lot, but it will show you nearly everything you need to know in order to interact with the database. It will save you lots of time in the future.

https://www.youtube.com/watch?v=rb0kD5tC...tion=share
  Reply
#5
I strongly recommend watching this video! I know very very little about PDO and how to interact with the database, and after watching this video, I honestly feel like I'm a pro at it lol
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)