Jump to content

ajoo

Members
  • Content Count

    709
  • Joined

  • Last visited

Everything posted by ajoo

  1. ajoo

    convert a query into one using joins

    OK, I got it. Thanks !
  2. Hi ! I have a query select @rownum:=@rownum+1 as row, tbl_country.Level, tbl_country.TimeOfLogin, register.email, tbl_country.SessionStatus FROM tbl_country, register,(SELECT @rownum:=0) r WHERE tbl_country.UserLogin = ? AND (tbl_country.UserLogin = register.Username) order by row desc limit 1; that works great but I want to change this to use JOINS. Please can someone show me if and how that can be done. I am not sure how and where to place (SELECT @rownum:=0) r in the query with joins. I have tried but it fails each time. Thanks all !
  3. Hi Benanamen ! Thanks for the response. Please bear with me for a day or so while I am doing a quick run through of my code. I'll come back and revert shortly. Meanwhile, here's a link, in case you would like to check out the near same discussion earlier on this topic. https://forums.phpfreaks.com/topic/301981-query-woes-confused/ Sorry for this delay. Thanks.
  4. Hi all, Does the statement "CREATE TEMPORARY TABLE temptab as SELECT ... " provide some sort of a return value to check the null/number of rows in that table? Running the same in phpadmin definitely gives the number of rows affected but i don't know how to tap into that value. I tried using the $stmt->bind_result($count); after executing the query thinking it might be the same as the Select query but that returns no value while my table has about 7 rows generated. If someone can show how, if the value can be retrieved. Thanks.
  5. SIr, The following query however fails to give the number of affected rows. SELECT table_A.uid, table_A.pole, table_A.act as Status FROM table_A UNION SELECT table_B.uid, table_B.pole, table_B.confirm_A as status FROM table_B UNION SELECT table_C.uid, 'User' as pole, (table_C.confirm_A + table_C.confirm_B) as status FROM table_C; There are about 9 rows that are actually formed so I wonder if that is the same as rows affected. Is there a way to find the number of rows formed from the above query ? Presently I encompass the above query with an additional SELECT COUNT(uid) FROM { }bb; which provides the rows that are available as 9. Running the 1st query is faster in this case. I was wondering if I could do without the COUNT(uid) thingy ! Thank you.
  6. ajoo

    Errors turned up by code analyzer.

    Hi all ! Just nudging this once again in hope of some more replies and thus some more information on this , I think, rather critical issue, which I am sure lots of coders become aware of rather late in the day !! Thank you all !
  7. Hi all ! I just passed my code through an analyzer and it showed that a lot of it was not following best practices. Some examples are below: 1.Direct use of $_SERVER Superglobal detected. if($_SERVER['REQUEST_METHOD']==="POST"){ if(!isset($_SESSION)) sess_start(); if(isset($_SESSION['timeout'])){ $_SESSION['user']=$user; 2. Direct use of $_POST Superglobal detected. if(isset($_POST['submit']) && $_POST['submit'] ==='Logoff'){ $_POST = array(); $usertype = fcheckRecruiter($_POST['usertype']); and many more like these concerning the use of SUPERGLOBALS. 3. Discouraged functions : header(), session_unset(), mysqli_close(), session destroy() & require_once to name a few besides a lot of other common php functions. header ("Location: donepage.php"); session_unset(); mysqli_close($link); session_destroy(); Well the question is obviously how to tackle these. The surprising part though is that prior to checking the code by an analyzer, I had no clue, like many other coders on this forum perhaps, especially the newbies, that my code was flawed or at least not following the best practices. I never found a single piece of code on the net, in examples, even in examples in the PHP manual that showed the correct usage of these as per best practices. The most surprising of these were of course the SUPERGLOBALS since they are used everywhere and by almost everybody. Googling the internet shows that hardly anyone is clear about these. People are debating on the direct usage of suberglobals where they are used for checking the existence of the variable. So it's all very moot and very grey it seems. Then there are common functions some of which i mentioned above. For example how would I reset the super global $_POST if not by setting it to a blank array? $_POST = array(); Why are these functions, enlisted above, being discouraged from use and what and how should the alternate functions be used ? How to achieve the same functionality in an alternate way? For the use of superglobals I found that it's proposed to use the filters or filter functions to sanatise or validate the input. If i recall correct, Guru Jacques strongly advised against sanitizing any user input. While I can understand validation of user input, sanitization of it seems to be wrong ?? I would be very grateful if someone can shed some light on these very basic and important questions and provide, if possible, some examples of the correct method of using these in code. Thanks all !
  8. Hi, Is this renark fellow hacking or attempting to hack the forum or what ??? I hope not. Thanks
  9. No sir, I hadn't. 🙏Thank you Guru Barand !!
  10. ajoo

    Values not passing to form?

    Sorry, My suggestion is incorrect. I did not take a closer look. Kindly discard the previous reply.
  11. ajoo

    Values not passing to form?

    You are using $item_Annual at one place and $itemAnnual at another.
  12. ajoo

    How to short hand this

    A simple for loop would do the trick.
  13. ajoo

    Errors turned up by code analyzer.

    Hi NotionCommotion, The code analyzer I used is codacy. It's a static code analyzer. I do not think it is using any framework and I am not using any framework for my code either. I have never used any autoloader ever & have no idea about it. I have also never tried composer either. Are these not to be used with frameworks ? Or can I use them in my project which uses no framework or OOPS? If so , then a small example of their usage would be great and get me going. $_POST = array(); $_SESSION() = array(); I have used these just before destroying a session and logging out a user out. mysqli_close. I have used prepared statements throughout. Thanks for the response. I hope some more inputs on this will follow till something concrete can be used to replace the faulty code or it be proved that some of the errors may be superfluous & the code may be used safely as is. Thanks !
  14. ajoo

    Best approach to send complex data to the server

    Hi ! What you guys are saying is that it is possible to submit form data to a server using a method other than GET OR POST submit. Would you please confirm if you are referring to submitting the form data using JSON format via an AJAX request using JS or JQ OR is this something else ? Thanks.
  15. Hi all, I have the following menu : <li> <a href='index.php?page=page1'>Home</a> </li> <li> <a href='index.php?page=page2'>Games</a> </li> <li> <a href='index.php?page=page3'>Gallery</a> </li> <li> <a href='index.php?page=page4'>Print</a></li> Of these, I want the Print menu to be disabled and invisible for all pages except when it is invoked via a button called View on the Gallery page. The landing page / URL in that case would be index.php?page=page4 and I want the Print menu to be disabled (the link )and made invisible when the user navigates away from the Print page. I know I have to use something like the following for disabling the link but all variations i tried on it seem to fail. $(window).on('hashchange', function(e){ $('a #page4').bind('click', function(e){ e.preventDefault(); }); . . . }); Kindly help to resolve this. Thanks !
  16. Hi requinix, Oh great ! I wish you had told me in #7 to replace session with get, that would have solved it. tI did occur to me to do so, but then I thought choosing $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] was a better option because here I got the complete URL for comparison. Simply using the GET can be manipulated because then someone can send $_GET['childprints'] from a different page and trigger the PRINT menu. However you said that SERVER_NAME and REQUEST_URI was not a good idea. I wish you would tell me why that is not a good idea. In any case I have dropped using the print menu altogether and have instead created a PRINT button on childprints which would eliminate the need to go this route altogether. However I thank you for the discussion which is always there for learning. If you can answer the last question ( requested as a wish above ) I would be grateful. Thank you.
  17. ok I get what you want to know. The View submit is a part of the form therefore <form action='flogin.php?page=childprints' method='post' > the action takes it to that page. Then it falls through the code shown also shown previously user_pages.php which is included in flogin.php include "header.php"; include"navbar.html" // --- The menus are decided and displayed here. . . . if(isset($_GET['page']){ $page = $_GET['page']; swicth($page) { // all pages go here // ... case "home": ... break; case "gallery": ... break; case "childprints" include("fra_prints.php"); break; ... } } So correct it has to d\go through the $_GET['page']; hmmm With the menu already shown by navbar.php wouldn't the detection on childprints.php be futile ? The condition needs to be set before the navbar.php is encountered. Really sorry but i do not understand what you mean by this. Maybe you can show me how to go about it. Thanks.
  18. Hi requinix, My answer #7 describe the precise conditions which I will put down again for your convenience. I have a page layout like this HOME GAMES GALLERY // Menu User1 --- data1 --- data2 --- data3 ---- VIEW // Table with View Buttons. On page say Gallery. User2 --- data4 --- data5 --- data6 ---- VIEW . . UserN --- dataX --- dataY --- dataZ ---- VIEW When the view submit button is pressed, the user lands on childprints page, which has information laid out for printing and the PRINT menu needs to appear when it lands on this page. I hope that is clear. Please let me know if you need any further clarification. Thank you.
  19. hmmm, you see this is the last and the only one page of it's sort that requires this conditional menu appearance / disappearance, as of now, that I need to fix before I put up the application. So the question of longer really doesn't arise. I am at the last. Could you please elaborate? If you are saying that I should do as I have been doing for the pages to display the menu so far, then that cannot work for this, because the menus are set for the user on login and remain the same for the length of the session. This print page is the only rogue page in that sense. Then how do I do it ? Thanks loads !
  20. Hi requinix, Thanks for the reply ! Would it be a problem if I instead check for the Page URL like i did earlier because your suggestion, must definitely be better, is a bit long drawn out it at this stage of the project. If the above solution, of checking the url and displaying the menu, has no security implications I would rather use that for this page and maybe come back to it later and make the changes you recommend. That solution works fine but i don't know if there is a serious downside to it. Please let me know. Thank you !
  21. HI requinix, I do not think that this, as you suggested, would work in my case requinix because my program structure and page flow is like this. include "header.php"; include"navbar.html" // --- The menus are decided and displayed here. . . . if(isset($_GET['page']){ $page = $_GET['page']; swicth($page) { // all pages go here // ... case "home": ... break; case "gallery": ... break; case "childprints" include("fra_prints.php"); break; ... } } The menu is displayed before the page is included. So setting the variable in the relevant case comes after the menu is already displayed. What do you think ? Is that correct or am i reading you wrong ? Thanks !
  22. The way to check for the landing page URL and display the print menu accordingly. Thanks.
  23. Hi Requinix, I really do wish that sometimes you would solve the problem without handing me out another one to work on !!😊 This $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] seems to be the way to go about it. Is this what you had in mind ? It does as required. Thanks
  24. Ya all right, I'll try and be clearer. When a user logsin say as an admin, his menu is set for all pages. As of now he has this menu : HOME GAMES GALLERY with submenus. There is one page print page that is invoked not via menu but via a submit button on a form as below User1 --- data1 --- data2 --- data3 ---- VIEW User2 --- data4 --- data5 --- data6 ---- VIEW . . UserN --- dataX --- dataY --- dataZ ---- VIEW Now when the Admin presses the VIEW submit button , he lands an a page which can be printed and so now I want the menu on this page to be HOME GAMES GALLERY PRINT. I feel that here when the button is submitted i have to use JS or JQ to set the session variable to print so that the following code can invoke the PRINT menu <li> <a href='index.php?page=page1'>Home</a> </li> <li> <a href='index.php?page=page2'>Games</a> </li> <li> <a href='index.php?page=page3'>Gallery</a> </li> <?php if(isset($_SESSION['print']) && $_SESSION['print'] == "print"): ?> <li> <a href='flogin.php?page=childprints'>Print</a> <?php endif; ?> Is that correct? I hope I have been able to make it clear. Also is there an all PHP way to do this ? Thanks !
  25. HI requinix, Thanks for the reply My menus are set on user login and depend upon the user login. Like separately for the admin and other users. The are set using a navbar and then the pages are included in the page area below it. In order for the additional menu to display on a required page and not on any other I had thought i would use a session variable. However this would have to be set and evoked on a button submit which includes the printable page. Wouldn't I still have to use jQuery to set the value of the session variable on a button submit for the menu to be displayed on the landing page? I know this is a different strategy from the one in the question above although it would still useJQ or JS. Is there a better all PHP way to do this ? Thank you.
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.