The following warnings occurred: | ||||||||||||||||||||||||
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
|
problem with update function - Printable Version +- UserSpice (https://userspice.com/forums) +-- Forum: Miscellaneous (https://userspice.com/forums/forumdisplay.php?fid=28) +--- Forum: Off-topic Discussions (https://userspice.com/forums/forumdisplay.php?fid=10) +--- Thread: problem with update function (/showthread.php?tid=137) |
problem with update function - lefox - 05-22-2016 Hey I was wondering if anyone could tell me why... <pre> Code: $db = DB::getInstance(); ..doesn't work. The field 'leagueCustom' exist and I know the values are being passed because Code: $query = $db->query("UPDATE Code: SET Code: = ? WHERE Code: . Code: = ?", array($customMessage,$leagueID)); works perfectly fine. Thank you! problem with update function - mudmin - 05-22-2016 I don't have a whole lot of context to go on, but from what I can tell. Code: $db->update('leagues',1,$userfields); Will always try to update the table leagues id field of 1. The 1 you are hard coding in there is the id on the table of leagues. When you are writing your query out, you are passing in the leagueID properly. My gut says that the update query should be... Code: $db->update('leagues',$leagueID),$userfields); Does that work? problem with update function - lefox - 05-22-2016 Sorry I originally had $leagueID in that value. I was trying to manipulate every value to see if I could get the query to pass. Is there any information I could give to better context? I've created a leagueAdmin.php which passes variables from a form. Echoing these variables shows they are being passed. problem with update function - mudmin - 05-22-2016 Can you paste all of your php over on hastebin.com and share the link here so I can replicate it? problem with update function - lefox - 05-22-2016 of course! league.php is where you would manipulate league http://hastebin.com/iyidayokej.xml if you were the owner of the league it would show you a form where you can manipulate the values of the leagues table . The values are passed to this page: http://hastebin.com/izuqegezit.xml if i missed anything please let me know! problem with update function - mudmin - 05-22-2016 As to why the update isn't being processed properly, it's pretty much one of those things you have to step through. It's almost always related to the id not getting passed from your form as just a single number. I would almost always do something like Code: $leagueID = Input::get('id'); Code: dnd($leagueID) //Dump and Die to make sure you're really getting the id properly from your form. Same thing with your custom message. Sorry to keep asking you questions, but when you say the update fails...what's failing. Are you getting a blank field in the db? Are you getting no change to the current field? Is it throwing an error? Your code looks fine off the top of my head other than the 1 for the id. Also, are you just wondering why the update method isn't working when the manual query works? I will say that for some reason the update method feels "pickier" to me sometimes. I use the full query every once in a while when I don't want to diagnose that. I'll keep giving input though once I hear back from you. @Brian might have some ideas also. problem with update function - lefox - 05-22-2016 You are the man, I'm totally fine with using the query now that I understand mysql queries a little better. I have read you shouldn't pass values straight to queries, is there a benefit from using the update function over the query other than time saved? When I say it fails I mean that there are no change to the current field! No errors though. On the dump and die topic, I've noticed that if I create a new variable like: Code: $league = $db->get('leagues',array('leagueID', '=',$leagueKey)); and then immediately another Code: $player = $db->get('player',array('id', '=',$playKey)); I can't access the $league unless I repeat the $db->get. Would dnd allow me to retain the information from my get? I have managed to get all my scripts to work with query command, however I'm using alpha 3 (because I can't get alpha 4 to work) and I just realized the registration system isn't working so that's my next step. You guys have created a great system and if I can figure out these minor problems(other than the join.php, thats really putting me through a loop. Should have tested it before I started doing everything else...) I'm confident I can use this script for my website. Once my websites done, I plan to write some tutorials for people who are less familar with php but want to use your system! So thank you again! problem with update function - lefox - 05-22-2016 And sorry if my code is messy! problem with update function - mudmin - 05-22-2016 The update function automatically does the same thing as the ? in your prepared (bound) sql statement, so you're pretty much good to go. I use the update method a lot in foreach loops and things like that. It's quick when you're doing something simple, but what you're doing works just as well and is more readable. dnd kills the page so it's more for tracking down errors. Basically it is a very simple helper that does a preformatted(one instance per line) var_dump and then kills the page so you get exactly what was put in the variable before anything else mucks with it. You can also do dump($variable); to do a preformatted var_dump without killing the page. I use those two helper functions constantly when trying to diagnose issues. That's funny that you noticed $db->get. I never documented that method in the db class. I really don't use it enough to figure out why you're losing the info. I'll play with it. That doesn't seem right. I'll check back with you on that. I'm also confused as to why Alpha 4 isn't working for you. I'm about to release 4.1 final, so I'm really interested in helping you track that down. problem with update function - lefox - 05-22-2016 So query over get? That should be perfectly fine, I just like the format of the get over writing out query every time. Not worth the head ache though! I'm running some errands to get ready for Game of Thrones but then I will jump into alpha 4 to see if I can't get a little more information on whats getting mucked up. Thanks again! |