Jump to content
#StayAtHome ×

Leaderboard


Popular Content

Showing content with the highest reputation since 02/29/2020 in all areas

  1. 2 points
    Why are you even attempting to store that duration. You can get it any time you need it with a query. Rule of DB design - don't store derived data. If you really insist on storing it, why do need two queries? UPDATE attendance_records SET duration = timediff(...) WHERE ... - a single update would do the job
  2. 2 points
    They aren't the same width because you don't have any sort of CSS in there that says anything about a width. It's not like the browser can read your mind about how you want it to appear... Have you tried giving the buttons a width?
  3. 1 point
    Yes - forums (including this one) DO help people. But not with all of their tasks. Forums like this one help you address your code. Help you correct it or debug it or help you amend your solution. We are not here to just plain write it for you. We are here for people who are having difficulty but that means showing us the difficulty.
  4. 1 point
    I'm sure it was not malicious, but most people don't appreciate it when someone has homework and uses forums like ours to get the answers. Next time, please remind us that you're learning and let us know that your tutor asked you to do something. That way we can help you get to the right answer without accidentally writing all the code for you.
  5. 1 point
  6. 1 point
    This isn't a "write some code for me for free site", it's a "here is what I tried, can you help me with my code" site.
  7. 1 point
    My code example defaults to 0 for both of those if they aren't set.
  8. 1 point
    Perhaps $cartidOK = $_SESSION['cartid'] ?? 0; $cartitemOK = $_POST['cartitem'] ?? 0 $quantityOK = isset($_POST['quantity']) && is_numeric($_POST['quantity']); $lockedcard = $_SESSION['lockedcard'] ?? 0; $lockedpaypal = $_SESSION['lockedpaypal'] ?? 0; if ( $cartidOK && $cartitemOK && $quantityOK && !$lockedcard && !$lockedpaypal) { // do it }
  9. 1 point
    You would need to test for the oracleid in the staff table IE WHERE s.oracleid = ? AND a.oracleid IS NULL since it is doing a LEFT JOIN the attendance_records table (alias a) to find missing dates.
  10. 1 point
    Check the value of userid. Is it not a varchar? WHERE a.oracleid = '$userid' If you write code this way, you are using variable interpolation which opens your code up to SQL Injection. That is why I showed you the parameter passing method, which uses prepared statements and bound variables. You would not need the single quotes if you used the parameter, as it will determine the datatype from the type of the variable being passed.
  11. 1 point
    You don't say what the error is but that is a different problem. Start an new thread on the MySQL forum.
  12. 1 point
    javascript, for example ... var a = $("#surname").val().substring(0,8).toLowerCase() var b = $("#firstname").val().substring(0,1).toLowerCase() $("#username").val(a+b)
  13. 1 point
    So it is now clear that ABSPATH is not being substituted the way you expect. How is it defined and where? I don't normally use constants but somewhere you must have a "define('ABSPATH',<whatever>);" but is not executed before that include.
  14. 1 point
    With older symfony apps there is the concept of environments. Symfony used to come with a seperate controller for 3 environments (prod [production], dev [development] and test [unit tests]). So I would expect that you are configured as production, which means that your app is running the app_prod.php front controller. This will be setup to operate in the same way that apache will often be configured to run by default an index.php file if you access a webspace path directly as in http://www.somesite.test/. With Mautic, things have been configured to run the app_dev.php frontcontroller for every application request. The other thing you have to understand is that symfony generates lots of code, which is what actually gets run. This involves twig templates, doctrine models, routes and lots more stuff. Symfony comes with a console app that has various command that let you generate this code, however, it may be that the apache user doesn't have effective read perms on the files the OS user generated. So my simple fix would be to do this: -have script delete the entire app/cache/* contents recursively, which your bash command list does. Prior to doing this you might want to explore the contents of that dir. You will have a directory for any environments that ran, which I would expect ideally would only be a prod directory. As you can see in the logs you showed, the runtime is trying to access some doctrine orm model proxies that couldn't be opened. Assuming this is the issue, once you delete the directory, open the Mautic app. This will cause all the code generation to kick in and all these files and directories will be owned by the effective web user. That user does need the ability to read/write/execute in the app/cache directory. It might take a few seconds for all the code generation to occur as you are essentially "warming the cache" manually, but once the files are generated they won't be generated again and everything should run at full speed. You could also add your own web function that would clear the cache from the web app, but if the web app is in a situation where it doesn't actually own the directory and/or files in question, there is no way for that user to fix anything once it's broken, and only the account that owns the files will be able to delete/chmod/chown them (or via root or sudo). Assuming you deleted the app/cache/prod user, and ran the Mautuc app, you shouldn't encounter any problems. Not knowing what came with Mautic, it could be that there are scripts being run on some schedule that undo the issue you will be fixing, but removing the app/cache/prod directory should fix the problem.
  15. 1 point
    Hi Tony, Is this a symfony app? Are you getting incorrect ownership due to running command line as an OS user? My first suggestion is to stop doing that, as it's guaranteed to mess up your ownership in this type of scenario. I'm not seeing why you need ssh whatsoever. A bash or php script would do the job. Look at the various exec and related commands. I would have to question why you don't simply cron your bash script and run it every 5 minutes. Much simpler and less invasive. Write the script, put it in /usr/local/sbin or /usr/local/bin. sudo su - {appropriate user to run script}. crontab -e. Add an entry to run at the periodicity you desire. I don't know that you want to blindly delete the app/cache dir contents every 5 minutes if you don't have to. Bash is a relatively full programming language where you can do standard if-then-else logic. With that said, you can also write a command line php script and invoke it in a cron exactly as you would a bash script. Or you can call the php command line scripts from bash. None of these ideas require ssh, and I don't really see what you need to run this remotely for if you have it running under cron automatically for you. If you are convinced you need remote execution, you could exec a script from a php page, but of course that will run as the OS user, and if you need sudo to correct some problems, you certainly wouldn't expect the apache user to have either a shell or su or sudo. A sysadmin/Devops person would turn to Anisible or Puppet for on demand controlled execution and administration of a cluster of servers, vpc's or what have you, but Ansible could work for you as well. Of course it might not be possible for you to install these tools in a shared hosting situation.
  16. 1 point
    You need to set a few attributes when you create your PDO connection. $conn = new PDO("mysql:host=$servername;dbname=timeclock", $username, $password); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $conn->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); $conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); Then you will be notified of any sql problems. Did you read my edit to earlier post about subtracting 1 day from the dates (to get Sun - Thu working week)?
  17. 1 point
    I thought you might be able manage that bit. Here's a fuller version <?php $month = 'March'; $start_date = new DateTime("first monday of $month"); $incr = DateInterval::createFromDateString('next weekday'); $period = new DatePeriod($start_date, $incr, new DateTime()); // create temporary date table $conn->exec("CREATE TEMPORARY TABLE date (date date not null primary key)"); // populate it foreach ($period as $d) { $dates[] = "('{$d->format('Y-m-d')}')" ; } $conn->exec("INSERT INTO date VALUES " . join(',', $dates)); // now get the days absent $res = $conn->query("SELECT s.oracleid , s.name , date_format(date, '%W %d/%m/%Y') as absent FROM attendance_staff s CROSS JOIN date d LEFT JOIN attendance_record a ON s.oracleid = a.oracleid AND d.date = DATE(a.clockingindate) WHERE a.oracleid IS NULL ORDER BY s.oracleid, d.date "); $tdata = ''; foreach ($res as $r) { $tdata .= "<tr><td>" . join('</td><td>', $r) . "</td></tr>\n"; } ?> <html> <head> <title>Example</title> <style type="text/css"> table { border-collapse: collapse; width: 600px; } th, td { padding: 8px; } th { background-color: black; color: white; } </style> </head> <body> <table border='1'> <tr><th>ID</th><th>Name</th><th>Absent</th></tr> <?=$tdata?> </table> </body> </html>
  18. 1 point
    https://www.php.net/manual/en/book.ssh2.php
  19. 1 point
  20. 1 point
    I'm confused. Are you installing a 3rd party application or trying to access a script from PHP that you wrote? Is this a CGI script?
  21. 1 point
  22. 1 point
    Check the permissions for /tmp. It should be (777): drwxrwxrwt. 22 root root 12288 Mar 21 14:01 /tmp Any user can write to /tmp. The 't' sticky bit handles the security issue. What ever user writes to /tmp is the only user that can access that directory/file (700) unless that user specifically chmod's something else. Also check session_save_path and its permissions.
  23. 1 point
    When you're using prepared statements you pass the query string to prepare(). You don't use query() at all.
  24. 1 point
    Your math is off. There are 1,000 mm in a meter. But there are 1,000,000 square mm in a square meter. You should divide by 1,000,000 if you use the approach in your original post. 900mm * 1500mm / 1000000 = 1.35 sq meters
  25. 1 point
    the associative index for the COUNT(*) expression is actually something like $row['COUNT(*)']. to simplify this, add an alias name for the COUNT(*) expression in the query and use that alias name for the associative index. next, both of the query examples you have shown will/probably match at most one row. why you are using a loop to fetch the data. just fetch the single row without the loop.
  26. 1 point
    Why don't you do some good old experimentation and see where it works? Or you could look it up in a manual.
  27. 1 point
    Typing it is a good way. Put it after the FROM section and before the ORDER BY.
  28. 1 point
    Id stay away from Eclipse if I were to chose an IDE to code in...... not for lack of speed (refactoring slows above 10k of lines of code), but mainly because of lack of seamless update process. Its PITA, as its automation is completely broken. Java IDE is also of great value...... I tried PhpStorm once and now Im paid customer. There is no better IDE.
  29. 1 point
    By far the best php editor! Should probably clarify that the company is JetBrains. Here's a link to the PhpStorm version. Started out as a Java IDE (IntelliJ Idea), and it's essentially the same base editor across the line, but I'd still recommend that you buy the Php specific version. There's a 30 day trial you can use to check it out. Has a huge number of plugins and configuration options available, so you can configure your code style, apply rules from various codesniffers and standards. As for a free editor, I'd go with Eclipse PDT.
  30. 1 point
    1. As far as I can tell, the "rules" is supposed to be a string - not an object. If you didn't need to account for is_page_loaded then you should say <validation-provider ... rules="required|positive_price"> 2. The validation function needs to return true or false. You are returning string or false.
  31. 1 point
    By far the fastest way is to use the SQL statement LOAD DATA INFILE Specify FIELDS TERMINATED BY '\t'
  32. 1 point
    You should only be using one timezone in all your code and storage. UTC works well but pick whatever you want and use it. By using a single timezone and datetime types then most of this problem goes away. Regardless of what the users local timezone is, you store the date and time in your chosen timezone. Then whenever you want to compare to it you also compare the current time in your chosen timezone to that stored date and time. If you want users to view dates and times in their timezone then convert them from your chosen timezone to their timezone just prior to display. If your using generated times then things are pretty easy in general. If your taking user-submitted dates and times, then things can potentially get a little more complex. If you want users to deal with things according to their local time you'll need to convert their input from their timezone to yours before doing and processing. This is just something you need to decide as one of your business rules. You also need to decide if whatever date you pick is inclusive or exclusive. If I were to subscribe on 2020-04-17 @ 5:20, for one year then does my subscription run 2020-04-17 @ 5:20 -> 2021-04-17 @ 5:20? 2020-04-17 @ 0:00 -> 2021-04-17 0:00? 2020-04-17 @ 0:00 -> 2021-04-17 @ 23:59:59? Up to you to decide. If it were me, I'd probably go for for the last option as I think it's the most intuitive and what people would expect. People are not going to remember the exact minute they signed up, and on the scale of a year I wouldn't nit-pick a few hours.
  33. 1 point
    You need to set your timezone. It obviously is already incorrect. https://www.php.net/manual/en/function.date-default-timezone-set.php You will have to look up the correct name for your location
  34. 1 point
    My guess is your XAMP configuration is pointing to the wrong folder for Document Root. Looking at your File System image, I see a folder named "public". This is often the name of the document root. Perhaps your AMP configuration is pointing to SchoolApp-master when it should be pointing to SchoolApp-master/public. In the public folder there should be an index.php file and a .htaccess file. There is probably also a folder in there called auth.
  35. 1 point
    Either you did not follow the instructions correctly and you extracted the files to the wrong place, or the instructions are wrong and you need to contact whoever wrote them to fix them. Beyond that, I told you what to do.
  36. 1 point
    You just have to make sure the date formats match. MySQL only uses yyyy-mm-dd, so: $curdate = date("Y-m-d");
  37. 1 point
    First, don't embed your PHP code like that. Separate your HTML from the PHP code. Second, don't use * in your select. Extract only those variables you plan to actually use. To do what you want, you need to create a form that submits your data when you click one of the buttons. See this article about using forms and passing data to PHP.
  38. 1 point
    I agree with Requinix. The better approach (if you really need to do this) is what cruise ships have been doing for years. When passengers come back on board they line up and go thru a metal detector (of course!) and a baggage check and they scan their id card that was created when they arrived for their trip. This card is linked to a photo taken by the registration staff and when the card is scanned a picture shows up so that the crew knows for sure that the person now boarding is the person who is registered to that card - just like what you want to know. The difference is they rely on a staff member doing the immediate supervision of this interaction, not a computer check in a back office. (I hope I made sense here)
  39. 1 point
    If someone doesn't want to be seen they'll just hide from the camera. Or worse, they'll take their own picture of the person they want to log in as and use that. Know that this is not real security. But as said, yes: you can use Javascript to get a still from the camera, then upload that like any other file.
  40. 1 point
    An alternative to the 2-table option is to treat costs as transactions, just like payments (cost amounts +ve, payment amounts -ve in this example)... DATA TABLE: payment +------+------+------------+--------------+---------+ | uid | name | trans_date | payment_type | payment | +------+------+------------+--------------+---------+ | 1 | kim | 2020-03-01 | cost | 100 | | 1 | kim | 2020-03-02 | card | -100 | | 2 | lee | 2020-03-01 | cost | 95 | | 2 | lee | 2020-03-02 | cash | -95 | | 3 | kent | 2020-03-01 | cost | 100 | | 3 | kent | 2020-03-03 | cash | -50 | | 3 | kent | 2020-03-04 | card | -50 | | 4 | iya | 2020-03-01 | cost | 80 | | 4 | iya | 2020-03-05 | cash | -40 | | 4 | iya | 2020-03-06 | card | -20 | +------+------+------------+--------------+---------+ then SELECT uid , name , date , cost , cash , card , total as balance FROM ( SELECT name , DATE_FORMAT(trans_date, '%b %D') as date , CASE payment_type WHEN 'cash' THEN -payment ELSE '-' END as cash , CASE payment_type WHEN 'card' THEN -payment ELSE '-' END as card , CASE payment_type WHEN 'cost' THEN payment ELSE '-' END as cost , @tot := CASE @previd WHEN uid THEN @tot+payment ELSE payment END as total , @previd := uid as uid FROM ( SELECT * FROM payment ORDER BY uid, trans_date ) sorted JOIN (SELECT @previd:=0, @tot:=0) initialize ) recs; +------+------+---------+------+------+------+---------+ | uid | name | date | cost | cash | card | balance | +------+------+---------+------+------+------+---------+ | 1 | kim | Mar 1st | 100 | - | - | 100 | | 1 | kim | Mar 2nd | - | - | 100 | 0 | | 2 | lee | Mar 1st | 95 | - | - | 95 | | 2 | lee | Mar 2nd | - | 95 | - | 0 | | 3 | kent | Mar 1st | 100 | - | - | 100 | | 3 | kent | Mar 3rd | - | 50 | - | 50 | | 3 | kent | Mar 4th | - | - | 50 | 0 | | 4 | iya | Mar 1st | 80 | - | - | 80 | | 4 | iya | Mar 5th | - | 40 | - | 40 | | 4 | iya | Mar 6th | - | - | 20 | 20 | +------+------+---------+------+------+------+---------+
  41. 1 point
    I totally agree with @requinix regarding the two tables. However, if you are willing to compromise over the output, you could do something like this SELECT uid , name , SUM(CASE payment_type WHEN 'cash' THEN payment ELSE 0 END) as cash , SUM(CASE payment_type WHEN 'card' THEN payment ELSE 0 END) as card , cost , cost-SUM(payment) as balance FROM payment GROUP BY uid +------+------+------+------+------+---------+ | uid | name | cash | card | cost | balance | +------+------+------+------+------+---------+ | 1 | kim | 0 | 100 | 100 | 0 | | 2 | lee | 95 | 0 | 95 | 0 | | 3 | kent | 50 | 50 | 100 | 0 | | 4 | iya | 40 | 20 | 80 | 20 | +------+------+------+------+------+---------+ If you really need every transaction listed, the SQL becomes quite complex involving user variables and subqueries. It would be much easier to do in the PHP as you output each row. [EDIT] ... For the sake of completeness SELECT uid , name , cash , card , cost , cost-total as balance FROM ( SELECT name , CASE payment_type WHEN 'cash' THEN payment ELSE 0 END as cash , CASE payment_type WHEN 'card' THEN payment ELSE 0 END as card , cost , @tot := CASE @previd WHEN uid THEN @tot + payment ELSE payment END as total , @previd := uid as uid FROM ( SELECT * FROM payment ORDER BY uid ) sorted JOIN (SELECT @previd:=0, @tot:=0) initialize ) recs; +------+------+------+------+------+---------+ | uid | name | cash | card | cost | balance | +------+------+------+------+------+---------+ | 1 | kim | 0 | 100 | 100 | 0 | | 2 | lee | 95 | 0 | 95 | 0 | | 3 | kent | 50 | 0 | 100 | 50 | | 3 | kent | 0 | 50 | 100 | 0 | | 4 | iya | 40 | 0 | 80 | 40 | | 4 | iya | 0 | 20 | 80 | 20 | +------+------+------+------+------+---------+
  42. 1 point
    Are these links appearing in a particular section (e.g. page footer) of the website? If so, the styles could also be applied to all links in that section. That way you don't need to create extra classes. For example, if your links are in an HTML5 footer tag: <footer> <p class="mylink"><?=$echo?></p> </footer> You could style the links with the following: footer a { font-size: 4pt; color: #FFFFFF; }
  43. 1 point
    Horrible coding practice to use a placeholder in place of a <label>.
  44. 1 point
    so why would you expect to find it by defining a path starting with "inc/"?
  45. 1 point
    Input fields also work better when they have "name" attributes
  46. 1 point
    Plus - your script is confused as to where it is. You begin by outputting your form (with problems) and then you ask if the POST has been created. Obviously it has not so you won't see any echo there. The PHP code should always be at the beginning of your scripts and your html at the end after all of your logic has had a chance to execute. In your case if no POST has been received yet then you need to send out the blank form and exit. If it has, that's when you check what has been sent back and send out your echos or whatever results you generate and then exit.
  47. 1 point
    There is no such thing as a "from" tag.
  48. 1 point
    The better way to "style HTML tags" (not php ones) is to use formal css code placed into the HTML <style> tag section of your html code. That way you don't have to place attributes into multiple places in your html. You can style similar things by defining CSS code for a tag name (ie, td, tr, p, span, whatever) and then referencing that css id name like this: in the head tag section add <style type='text/css'> #style1 { padding: 4px 6px; margin:1%; } and then in the html: <div id='style1'>
  49. 1 point
    <div class="section" style="<whatever css style you want>"> <?php if(isset($_SESSION['uid'])) { echo 'Hello,'; echo $_SESSION["uid"]; } ?> </div>
  50. 1 point
    Don't do that. Not in the actual table at least. Some people recommend this stupidity to try and avoid name collisions in their queries (such as two tables have a Label column) but such issues can be easily handled using the table.column syntax in your query rather than cluttering up column names in the table. SELECT o.Label as o_label, s.Label as s_label FROM order o INNER JOIN status s ON s.Id=o.Status One of the applications I work on was original designed using a scheme like that where every column has a table specific prefix to it and it's super annoying (long names, broken autocomplete) for no real benefit. I've been slowly undoing that when I can and just giving the columns nice simple names. I'd also suggest just using the full table name in your constraint names rather than some alias. It makes things very clear when someone 6 months later needs to decipher things.
This leaderboard is set to New York/GMT-04:00
  • Newsletter

    Want to keep up to date with all our latest news and information?
    Sign Up
×
×
  • Create New...

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.