This forum is archived. Posts are preserved for historical reference. For current help, join us on Discord.

Running Update Query

In Off-topic Discussions · Started by Brandin on 2016-12-03 9:31 pm · 70225 views · 32 replies

Hey!

I am using the UserSpice pages in many ways, and one of them is a migration tool. Basically, I have a list of categories, and if I migrate the category number to be another number, I also want to update all of the templates with that category number, to the new one. Currently, I am using the default function from the
admin_user.php
page that I just modified to my good, and I have this:

<pre>
    //Update catnum

    if ($number != $_POST['number']){
       $number = Input::get("number");

      $fields=array('number'=>$number);
      $validation->check($_POST,array(
        'number' => array(
          'display' => 'Number',
          'required' => true,
          'min' => 1,
          'max' => 3
        )
      ));
    if($validation->passed()){
      $db->update('categories',$id,$fields);
      $successes[] = "Sort Updated";
</pre>


But what I need to do is also update the
templates
table
WHERE category=
the new
$number
I have set.

If you could help with the
$db->
function for this, I would be VERY appreciative :)

Thanks again!
I posted this on HasteBin since it went crazy on here:
http://hastebin.com/ehefapokas.php
I missed this one. I was on vacation. Did you get it figured out?
I did - I'll pull the code to let you know what I did later today. Hope you enjoyed your vacation!
Now when I am running the update query this happens:

Warning: Invalid argument supplied for foreach() in /home/aircentralized/public_html/boss/users/classes/DB.php on line 50

Warning: Invalid argument supplied for foreach() in /home/aircentralized/public_html/boss/users/classes/DB.php on line 50

Line 50 is:
foreach ($params as $param) {
What does parms have to do with anything when I'm not calling for parms?

Thanks.
PHP didn't give you the most helpful error there. That error is part of the db->query method, so there is a problem with one of your queries. Go through any time you did any db queries on that page and see if there are any errors...

If you're kind of lost on where you messed up, just put

die();

after a query (starting from the top of the page) and reload the page. If you don't get that error, remove that die and put it after the next one.

Once you get the error, the query before the die is the one that is causing you a problem.
Hey mudmin,

I've tried doing this but it ends up stopping the page from loading because I'm using die(); in queries that load the page. This only happens when I actually perform an update, so it seems as if is something to do with the update query, but this is the same query from the default UserSpice pages, just modified for this purpose (only change the update values and table and stuff). It occurs on every page after I perform an update function.

Thoughts?
Can you pastebin the latest version of this code and I can figure it out for you?
templatesreqedit.php
https://hastebin.com/owoxawuyab.xml

This performs an update, and then gives me the error above, which is linked to the DB.php file which is here:
https://hastebin.com/ikoyugutiz.xml

Excuse this mixed use of mysqli queries and PDO lmao - I'm still trying to convert all of my stuff to PDO.
So just double checking...did you modify the db class?
No I have not made any changes to the db class.
Ok. I'm seeing now. I don't think there is anything in those changes to the DB class that really NEEDS to be in the class. Those functions would work just as well in the usersc/custom_functions file and then you would be able to receive updates without breaking things. I'll look at the rest of the code.
OHHHHH, like my migrateCat and migrateTemplate functions? Move those to custom_functions? Do I have to do any additional loading?
Do you know which queries are triggering your errors? My guess is that it's somewhere in the
$status='1';
$db->approveRequest('templatesrequest',$id,$status);
$modifieduid = $uid;
$db->approveRequest2('templatesrequest',$id,$modifieduid);
mudmin, I'm really not sure. If I remove any of those queries I will never know what caused it, and if I 'die()' the page doesn't load so I can't tell what is doing it.
Ahh. Ok. Well, if you could help me figure out which query is the problem, I can help.

If you move those functions to custom functions you will have to make a few little changes like put the DB:Get instance thing at the top of the function (you can look in us_helpers for an example) and then get rid of the $this and change it to $db. Again, looking in us_helpers will show you a difference between writing it as a method (in a class) and function (not in a class). But even before that, let's figure out where the problem is...


You don't just have to put die. You can give a description, so I would start at the top and change
if($validation->passed()){
$db->update('templates',$requestid,$fields);
$successes[] = "Long Name Updated";
to
if($validation->passed()){
$db->update('templates',$requestid,$fields);
die('made it to the long name update');
$successes[] = "Long Name Updated";

If you make it that far and you see the die message but no error on line 50 error then you know there is no problem with that query so go to the next one...
if($validation->passed()){
$db->update('templates',$requestid,$fields);
die('made it to the text update');
$successes[] = "Text Updated";

Do that for each query (one at a time) and once you see the error pop up, you will know which one is causing you the problem and we can fix it.
mudmin,

You're a genius man! It looks like my problem lies with these lines on my
templatesreqedit.php
https://hastebin.com/vagosanoqi.php

Lines 112-115 on my original haste. Any thoughts on why? Could it have something to do with the fact I am posting numerical values instead of text values? Or what? Hmmm...

Thanks!
I would get those two functions out of the db class and put them in usersc/includes/custom_functions.php. I redid them for you...

https://hastebin.com/wokaqataji.xml
Okay, so I moved them, as well as the migrateTemplate and migrateCat stuff I added, but now it is producing this error:
Fatal error: Call to undefined method DB::approveRequest() in /home/aircentralized/public_html/boss/usersc/includes/external/templatesreqedit.php on line 113

Seems like it can't find the function. Thoughts? Am I doing something wrong?
My custom_functions.php:
https://hastebin.com/ujehokuqad.xml
You need to put the functions in users/includes/custom_functions.php or it could be in some kind of script folder but there is already a file called custom functions it is automatically included in every single page.

Then you need to remove the $db-> from in front of approved equestrian when you call your functions on your pages
12Next ›