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
/printthread.php 16 require_once



UserSpice
how to prepare? - 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: how to prepare? (/showthread.php?tid=512)



how to prepare? - gaby de wilde - 04-01-2017

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';



how to prepare? - karsen - 04-04-2017

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!


how to prepare? - gaby de wilde - 04-06-2017

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.


how to prepare? - mudmin - 04-07-2017

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=rb0kD5tCENM#action=share



how to prepare? - Brandin - 04-08-2017

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