-
Posts
6,906 -
Joined
-
Last visited
-
Days Won
99
Everything posted by ginerjm
-
You also do not need to do 2 queries to find out if there is a user record. Just run your second query and check the row count returned for your 0 or 1.PDO uses a great little item called rowCount() $q = "SELECT User FROM LIBusersX WHERE UserKey = '$Pwd1' AND UserN = '$Name'"; $qUser = $pdo->query($q); if ($qUser->rowCount()) == 1) return $qUser->fetchcolumn(); else return false; You will need to check the calling code result for the false value to proceed.
-
I would be very surprised if you can do a file_get_contents on a url. The url suggests that a script has to run and the file_get_contents expects a set of data at the ready, which it will not be. And just what do you mean by "import"? Are you meaning "download"?
-
In your connectdb function you create the db connection and save it in the variable $conn. But then you return something called $pdf (??) which doesn't exist. After that you call the connectdb function without capturing the returned connection so you can't do anything there. IMHO I would alter that connect function to return the NEW PDO connection with "return $conn". In any later call of this function I would assign this returned value to $pdo and use that for all future db references. That means you need to change the latter item I mentioned above to be "$pdo = connectDb()". Of course (as also already mentioned) you should begin any script that is going to be using a db with the call to your connectdb function and get that $pdo value as the result and only reference $pdo when doing db work. You should not need to call connectdb any longer unless you are doing something with a different database later on, which would imply you should use $pdo2 perhaps for that work. PS - you should add the database name to the connectdb function header so that you can provide it with the call to connectDB($dbname) instead of defining it inside the function. After all of this you should be passing the $pdo variable in the call to any db-related function so that function has the connection. Many people would call this variable ($pdo) the 'handle' to your database which removes your concerns about it from that script. PS - Any reference to something with "mysql_" in it is invalid in the latest versions of PHP. If you are using those functions you have a lot of changes to make which definitely makes using PDO the better improvement to your code. It really is easier to use with just a little reading and testing out. Here is an example of what you new code could look like: (if the comments were removed this would be a much smaller chunk of code) $pdo = PDOConnect('database_1'); // a call to my std. connection logic that sets the db name // it also contains my credentials and options which I hardly // ever touch. ... ... (doing work) ... // need to do a query // All you need to do is: // write the query and save it as a var for use later // prepare the query // define the prepared query values // run the query being sure to check the results // (All this needs is 2 functions which is different than mysqli uses) $q ="select fld1, fld2, fld3 from my_table_name where keyfld = :keyvalue"; $qst = $pdo->prepare($q); // prepare the the query to create a "query statement" variable $parms = array('keyvalue'=>12); // perform the query using the parms that get substituted // into the query if($qrslts = $qst->execute($parms)) { // query ran successfully so process the results echo "The query has found these results:<br>"; $cnt = 0; while ($row = $qrslts->fetch()) { echo "fld1 is {$row['fld1']}, fld2 is {$row['fld2']}, fld3 is {$row['fld3']}<br>"; $cnt++; } echo "There were $cnt rows returned<br>"; } else { // query failed so you decide what you want to do here. echo "Query failed to run. Query is<br>$q and key value was {$parms['keyvalue']}<br>"; (handle this failure or exit) } // All done with querying but you don't need to close the connection since // PHP will do that at the end of this script. I keep the query itself outside of a function call so that my code can output it if doing some debugging during development. I use the parms array for the same reason although you could define the array as an argument to the call to execute(). I use the simple fetch() function since I mostly use the associative array for my results which is set during the connection logic.
-
How do i make a page of user like:
ginerjm replied to CaraDoPastelDaSuaRua's topic in PHP Coding Help
Something like: website.com/user?id=xyz ? Although you may have to include the script name before the ? As in website.com/user/index.php?id=xyz -
Don't know about css recs to you since I didn't recommend any to you. I think the other contributor to this post brought that up while trying to tell you that <table> tags our out-dated. That is true and we are supposed to use CSS to design our html tables. Guess what - I haven't seen the need to do that and perhaps someday I will have to change a whole lot of code. In the meantime I will continue to use html tables whenever I need to display data in a tabular format. And That's That.
-
Too few arguments to function Wpsec\captcha\handlers\WPLoginEventHandler::handle_login_hook(), 1 passed in /var/www/wp-includes/class-wp-hook.php on line 308 and exactly 2 expected in /var/www/wp-content/mu-plugins/vendor/wpsec/wp-captcha-plugin/src/handlers/WPLoginEventHandler.php:24 The beginning says you are passing one arg in line 308. Find that. You do understand how functions work I hope. When you define/create a function the header of it will have a number of parameters in the parentheses following the function name. However many of them are hard, required parms will need to be included in any line of code that later calls this function. If that line of code does not use enough values in the call to the function you get your error message. So take those first couple of lines of the error message and track down the items mentioned there in your code and see what you are passing.
-
Definitely go with PDO.
-
So have you created new code yet?
-
One does not need to make 2 connections. Simply add the dbname to the tablename in your one query. "select a.fld1, b.fld1,a.host, a.child, a...., b..., b... from db1.tablea a, db2.tableb b where a.key = b.key
-
You are storing calculated items in your array elements. That is not necessary when you have the details of the calc already present. How about these lines: 'order_lines'=> [ [ 'name'=>$product_name, 'quantity'=>1, 'unit_price'=>$api_amount, 'tax_rate'=>0, 'total_amount'=>$api_amount, 'total_tax_amount'=>0 ] ], You have an element with no key And - why an array and not a db?
-
Update to 1st row when try to update other rows
ginerjm replied to Ooilchen's topic in PHP Coding Help
Totally agree with Strider. To create this topic that seems to reference a problem with doing a db update and post ALL THAT CODE that has nothing to do with (mostly) is a waste of the poster's time as well as ours - if we even try to read thru it all. 1 - can you identify the part of the code that is giving you the problem? 2 - Are you getting any errors? If you are - You Should Be Showing Us the complete message as well as the line(s) of code it refers to. 3 - Try and make it easy for us to help you as well as make it easy on yourself to zero in on that part of your effort as well as when we give you suggested changes to it. -
get new value of type='date' field in its onchange event
ginerjm replied to ginerjm's topic in Javascript Help
That was a mistake (error). At first I thought my code had an error (it did) but then I corrected it and meant to post my corrected code as the solution and forgot to edit the text. I had already begun. -
Update to 1st row when try to update other rows
ginerjm replied to Ooilchen's topic in PHP Coding Help
Way too much posted code that doesn't pertain to the topic's point IMHO. Let me ask this though. What are these 2 lines doing for you: $result = $con->query($sql2); if (mysqli_query($con, $sql2)) { You seem to be running the same query twice -
get new value of type='date' field in its onchange event
ginerjm replied to ginerjm's topic in Javascript Help
Kicken - Thank you for what appears to be a concise solution for me. But I have this error. Code: function getDay(dt_id, nam_id) { var str3 = document.getElementById(dt_id).valueAsDate.toUTCString().substring(0,3); alert("Got str3 "+str3); document.getElementById(nam_id).value = str3; return; } This works great for what I need. Thanks again. -
get new value of type='date' field in its onchange event
ginerjm replied to ginerjm's topic in Javascript Help
What do I do with a "console.log" instruction? -
get new value of type='date' field in its onchange event
ginerjm replied to ginerjm's topic in Javascript Help
Nothing I've seen has helped me resolve this issue. And WHY is it a timezone issue? I'm not playing with timezones. It has been set (php wise?) at America New York always. Why does the datepicker bring it into play? If I was just using it to alter the date it does it just fine. The problem is the event handlers make it difficult. I have an html input tag of type=date. I want to capture some event when the user (me) clicks on the field and chooses a new date from the pop-up calendar. When I select a new date I want to get the day (Mon,Tue....) of the new date and set another field with it. That is all. Show me how please. You guys/gals have seen me on these forums for a few years now. I"m pretty good at doing the PHP thing and sometimes JS. This issue is something that has me struggling and nothing I've seen so far here has been clear to me. Sorry but that's the way it is. I would completely get rid of my current code if someone would just show me how simple it could be. Kicken - you say I've been shown 3 ways to resolve it. Well, I'm not seeing it. Sorry if I'm seeming stupid but it just isn't coming to me. -
get new value of type='date' field in its onchange event
ginerjm replied to ginerjm's topic in Javascript Help
I don't do JQ - only JS. Although it does resemble what I was trying to do I think. -
get new value of type='date' field in its onchange event
ginerjm replied to ginerjm's topic in Javascript Help
Requinex - I appreciate your response and I tried it but the answer that it gives me is simply a number - the day value of my new date. That is not what I am seeking. I am trying to get the day name such as Mon, Tue.... Gizmola - Yes I have a date stored in my db. My timezone is America/New York. Whatever that means to you I don't know. I write things for me and my friends that we use locally, so that time works for us. My current issue has nothing to do with timezones and such. All that I am trying to get using JS is the day (Mon, Tue...) from the new date that the datepicker calendar provides and I don't have the right JS knowledge apparently to derive that from the value of my date field when it is changed. I am not storing it. I am just trying to place a literal on the input form to help recognize what day the current date references. I didn't know there could be so much discussion on right and wrong over this little problem. -
get new value of type='date' field in its onchange event
ginerjm replied to ginerjm's topic in Javascript Help
Well if someone has a true solution why not show me? I have an input tag with type='date'. I have PHP logic that looks at that date and derives the 'day' that it represents and puts it into a separate field to show a complete date and day pair when the data is sent to the client. But when I click on the calendar to alter that date value I need some JS to make that day field keep up with the new date value. I figured this out because I am by no means a JS pro. I know enough to usually get by. This obviously is not one of those times. So show me how you would do it. -
get new value of type='date' field in its onchange event
ginerjm replied to ginerjm's topic in Javascript Help
Ok - How does this look as a solution? Corny but since it is only for me in my location it works. new_dt = document.getElementById(dt_id).value; // shows new value new_dt = new_dt + ' 05:00:00'; I simply grabbed the basic 'value' and appended 5 hours to it and now my calcluation comes out correct. -
get new value of type='date' field in its onchange event
ginerjm replied to ginerjm's topic in Javascript Help
I agree that the time is irrevelant since I am not at all interested. I just want the date so I can determine the day. What I don't get is why I am not able to get a date value having 2/25 in it. Or even a string value. -
get new value of type='date' field in its onchange event
ginerjm replied to ginerjm's topic in Javascript Help
Ok - here is my code and the output I am seeing. new_dt = document.getElementById(dt_id).valueAsDate; // shows new value alert("1 in changeDay with input value of "+typeof new_dt+": "+new_dt); dt_new = new Date(new_dt); //converts str to date obj but wrong value alert("2 in changeDay dt_new is "+ typeof dt_new + ": " +dt_new); dt_val = dt_new.toString(); alert("3 in changeDay dt_val is "+typeof dt_val+": "+dt_val); document.getElementById(day_fld).value = dt_val.substring(0, 3); Alert 1 shows: 1 in changeDay with input value of object: Fri Feb 24 2023 19:00:00 GMT-0500 (Eastern Standard Time) When my datepicker was popped up I chose to move the date from 2/24 to 2/25. I do understand why the time shows as 19:00 but the date is not what I expect but I am guessing it is the "pre" value and not the "post" value of the whole onchange process. Alert 2 shows: 2 in changeDay dt_new is object: Fri Feb 24 2023 19:00:00 GMT-0500 (Eastern Standard Time) I am interpreting this output to be showing the original value of the date field since it is not the date that I clicked on in the calendar window. I tried to change the value from 2/24 to 2/25. But now I have a date object and not a string only thing is that it is the wrong date. Alert 3 shows: 3 in changeDay dt_val is string: Fri Feb 24 2023 19:00:00 GMT-0500 (Eastern Standard Time) Now the process is done and the date field shows the new date as desired. My issue is that the JS code never shows me a date of 2/25 which I need since my logic is trying to show the name of the Day for each date that is displayed. So instead of changing my day field from Fri to Sat it uses the wrong date value to determine what the Day should be, hence it remains as Fri instead of being altered to Sat. As you can see (and wonder about) the last line of my code is simply pulling the day name off of the beginning of the result string and placing it on the page but since my code never sees 2/25 it gets the wrong day. ****************** Ok - I figured out what to do with the link you provided. Don't understand why UTC and Local are now a concern. I can certainly see why they are different values but since it is early in the day here in EST I don't now why UTC value is 2/25 already. -
get new value of type='date' field in its onchange event
ginerjm replied to ginerjm's topic in Javascript Help
MY last has a small typo that may be confusing. I should have typed "It is NOW 2/24/23" and not said 'not 2/24...' -
get new value of type='date' field in its onchange event
ginerjm replied to ginerjm's topic in Javascript Help
Kicken - so you're saying to use valueAsDate instead of value when I get the input from the html field. So here's my new code: new_dt = document.getElementById(dt_id).valueAsDate; // shows new value //alert("1 in changeDay with input of "+typeof new_dt+": "+new_dt); // confirms a string value of new date. dt_new = new Date(new_dt); //converts str to date obj but wrong value Same result. The problem is how to catch the newly chosen date from the calendar pop-up that the type='date' brings up. It is not 2/24/23 here in the usa and I am clicking on 2/25 in the calendar. When I click it away the JS code pops up and immediately shows me the 2/24 date still and not the date I selected - 2/25. That is what I'm trying to figure out. How to get the 'new' date value (which shows up on-screen once my JS code finishes) instead of the old one.