-
Posts
5,992 -
Joined
-
Last visited
-
Days Won
150
Everything posted by gizmola
-
@ginerjm makes a good point here. Omit the ending tag in all your scripts, unless you are going in and out of php mode. Even if you are doing that, you still never need a php end tag "?>" at the bottom of your script. Having one can lead to hard to debug errors, particularly when you are include/require scripts which you did in your code with your "settings.php" script.
-
Hello Sanjay. Just to be clear, the way this and other forums work, is that people ask questions, and other members are free to read those threads and participate with responses and advice if they would like to. A good way to start is to use the Activity menu/My Activity Streams/Unread Content and browse the threads to see if there is anything of interest to you.
-
No, log file deletion is not going to bring down Wordpress. Logs are logs, and intrinsically disposable. Most get "rotated" aka archived and deleted on a rotating schedule. A required config file getting deleted might also crash the server, but it doesn't sound like that's the problem. What's possible is that what got deleted were MySQL or MariaDB log files, so now the server is crashed. You stated you think the database is fine, but I question that assumption. The assumption could easily be verified using the cli mysql client, or perhaps a phpMyAdmin setup or something similar if the control panel has that, or it's installed somewhere on the server. It's possible that an expert MySQL dba could find a way to get a MySQL server running again, after something so catastrophic as the deletion of required InnoDB logs, but more than likely you will need to reinstall mysql, and recreate the database(s) from mysql backups/dumps. There are different ways to configure the InnoDB server, so there's not one cut and dried prescription for how one might approach a problem like this. If there's no backup, well then --- it's very likely there's no "recovery" option. In general "recovery" is facilitated by database log files, and is designed to recover from issues that happen outside the log files. These are more accurately referred to as "transaction logs" and should the server crash, these logs are used to rebuild the database and recover it to the most recent transactions, which usually happens automagically when the mysql server is restarted. You're just asking us to guess, but that's a reasonable one for you given the limited information available to us.
-
Just to be clear, you implemented the fix for the bug that cyberRobot provided? if( $admin == 1 ){ So at this point your entire question has changed! Now you are always going to index.php rather than admin_index.php? A few general comments, and things I noticed: The correct valid form of the location header is: header("Location: index.php"); Notice "Location" not 'location' and the space between the colon and the url. MDN is a good place to verify these types of things: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location These small details often aren't a problem, until they are, and something doesn't work right, and you can't figure out why. In general, you are at the point, where you need to verify your assumptions one step at a time, with debugging output, using var_dump(), die("something...), or something like what @cyberRobot provided in your last message. The other option is to get xdebug working, so you can step through your code. Setting it up can be difficult for some people, depending on your development environment and IDE being used, but it is often a tremendous aid to developers who are learning. If you want to let us know what your development environment is (os, php setup, code editor etc) we might be able to locate some resources or tutorials to help you with the setup. This code appears to be wrong: $_SESSION['$username'] = $row; $_SESSION['user'] = $username; First you have $username, which is an odd key, and makes me wonder what you are trying to do there. It also looks like these assignments are mixed up. I would assume what you really want is: $_SESSION['username'] = $username; $_SESSION['user'] = $row; Last but not least, I would strongly urge you to start looking at how to employ functions, to make your code more manageable and DRY. Look at how many places you are doing a header location! Consider this simple function: function redirect($url): void { header("Location: $url"); exit; } You might notice that whenever you redirect using the location header, you can not trust the browser to perform the redirect, so you should always exit() so that no additional code will be run. Putting it in a function, helps insure you don't forget. With this function, your code would become: if (isset($_POST['login'])) { extract($_POST); $query = "SELECT * FROM users WHERE `username` = '$username' AND password ='$password'"; $result = mysqli_query($con,$query); $num_row = mysqli_num_rows($result); if( $num_row > 0){ $row = mysqli_fetch_assoc($result); $id = $row['id']; $_SESSION['user'] = $row; $_SESSION['username'] = $username; $admin = $row['admin']; if( $admin = 1 ){ redirect("index_admin.php"); } else { redirect("location:index.php"); } } else { redirect("login.php?msg=error"); } This is more of a best practice recommendation, but when you have code like this, that has a functional flow that ends/exits/returns, it is best practice not to employ nested if then else blocks when you can avoid them. Your code can be rewritten this way: if (isset($_POST['login'])) { extract($_POST); $query = "SELECT * FROM `users` WHERE `username` = '$username' AND `password` ='$password'"; $result = mysqli_query($con,$query); $num_row = mysqli_num_rows($result); if ($num_row < 1) { redirect("login.php?msg=error"); } $row = mysqli_fetch_assoc($result); $id = $row['id']; $_SESSION['user'] = $row; $_SESSION['username'] = $username; $admin = $row['admin']; if ($admin = 1) { redirect("index_admin.php"); } redirect("location:index.php");
-
You have this code: $query = "SELECT t.transactioncode AS tCode, c.transactioncode AS cCode FROM tsc AS t LEFT JOIN Candidates AS c USING (transactioncode) WHERE transactioncode = ?" $stmt = $conn->prepare($query)->execute([$tcode]); $result = $stmt->fetch(); Look at the 3rd line here. Your code assumes that $stmt is a valid result set that you can use to fetch results. The problem is that if your query fails, $stmt will not be a result set, and you will not be able to fetch with it. This is what is happening. You need to figure out what is wrong with the executed query, but also as @ginerjm showed you, you also should not have code that assumes a query worked to generate a valid result, as your current code does. You should check that $stmt is true/valid first.
-
Great advice. And there is also a built in debugger, where you can set breakpoints in your javascript code, and step through line by line to see how variables change (or not). You use the sources tab for that.
-
It is pretty hard know what to tell you, as there are a lot of potential variables regarding the type of mac you are using and the OS version. If one of your primary uses of your mac is java development, then I wouldn't recommend homebrew. I would suggest that you install either the openjdk or oracle version of the sdk. This article covers installation of the current version of OS/X (Ventura) https://wolfpaulus.com/tomcat/
-
Need more information other than "something is wrong". What exactly is not working the way you expect? Do you get any errors? Some obvious things that jump out are: await fetch('http://localhost:80/api/login.php' Just use a relative url here: await fetch('/api/login.php' This header does not make sense for development. header('Access-Control-Allow-Origin: http://localhost:3000'); Start with something permissive and determine later if you can lock it down. header('Access-Control-Allow-Origin: *'); Why are you posting the data as json? JSON is great for javascript, but has no value for PHP. I would recommend just making a standard post structure. Then you can dispense with having to json_decode it and you can use the $_POST superglobals. $email = isset($_POST['email']) ? isset($_POST['email']) : ''; $password = isset($_POST['password']) ? isset($_POST['password']) : ''; At any rate, when you return json, you need to set the Content-type if ($_SERVER['REQUEST_METHOD'] === 'POST') { header("Content-Type: application/json"); Last but not least, remove any PHP end tags. End tags are never a good idea, and only should be used in a script where you need to mix html and PHP together. You should never end a script with a php end tag. See PSR-12 for this and other coding standard recommendations.
-
People can not help you debug if you don't provide information about the failure. How is it that you know it doesn't insert in the database? Is it because there's a 500 error, or the script runs and displays "Booking failed" or what? You don't provide the form code, so that could be an issue. Probably the statement execution is failing with a sql error but you don't capture/log the error. Beginners seem to always do what you are doing and create a bunch of variables that just copy values from the superglobal for no reason. $Bus_id =$_POST['Bus_id']; $city = $_POST['city']; $Destination = $_POST['Destination']; //etc Several things jump out at me: The $_POST array is already an array variable, and you can use it to pass the values. Don't make a bunch of other variable names for no reason There is an established variable naming standard for php. It's camelcase. Don't make a variable named $Bus_id. It should be $busId. $Destination should be $destination. Be consistent with your html attribute naming. You are all over the place. You have 'Bus_id' and 'city' and 'Destination'. The most commonly accepted convention is "all lowercase, with words separated either by a '-' or an '_'. I would suggest underscore as html is often manipulated later with javascript, and the '-' is a symbol in javascript, but otherwise choose which one you like. So fixing your form input names 'bus_id' 'city' 'destination' The other question that arises in your code, is why you have a bus_id and not a city_id and destination_id? At any rate, I bring up the lack of rigor in your html and php variable naming, because lack of standards often lead to bugs that get traced back to inconsistent variable naming.
-
Creating a Quiz in PHP/PDO - help with ERD
gizmola replied to webdeveloper123's topic in Application Design
This really depends on whether or not you will expand or use this same schema for other things. Certainly you should have a separate table for assets, as that is almost always a better idea that just having a varchar in the table. Once you've done that, it's much easier to provide a failsafe against things like corruption of an image during replacement, or generating a filename that isn't the same as the original name of the image. The other obvious thing that jumps out, is whether or not you might want eventually to have an image associated with the answer So the question here, is really should you have asset_id as a foreign key in the question table, or might there be a question that requires multiple images. If you make a foreign key (or just include the string as you have) then you aren't able to support that. I also think relationally, you could argue that a url string is not a core attribute of a question, and thus begs the question of what entity really applies (which would be asset or image). -
Laravel and Php Based application
gizmola replied to Rphp's topic in PHP Installation and Configuration
You need to provide a lot more information than that. -
Controllers are not models. Having a controller that handles CRUD for Categories is irrelevant to controller built for products (that happen to include Categories. In your product controller, you should use eloquent to query for the categories. I'd expect to see something like this: $categories = Categories::all(); return view('products.create', ['categories' => $categories]); Then in your product blade template you will build the category drop down in the list using something like: <select name="category" id="category"> @foreach ($categories as $category) <option value="{{ $category->id }}">{{ $category->name }}</option> @endforeach </select> It's good to put this into its own partial template and include it, if you expect to use this type of code in multiple places. That way any style classes you might add or changes, will be reflected throughout the system, rather than having to go through and change the same code multiple times. So you will want to put code similar to what I have shown in it's own blade file, which you might name category.blade.php. Make sure you understand where you need to put templates and how you will reference them when including. So your product.blade.php template would include category.blade.php using something like this: <form method="POST" action="{{ route('product.new') }}"> // whatever other stuff @include(category) <button name="submit" type="submit">Submit</button> </form> This assumes that you have a method in your product controller that has a named route setup for it, pointing to product.new. Hopefully you get the idea.
-
My isset() function runs before i click the button
gizmola replied to GamesBond008's topic in PHP Coding Help
You really have to use an editor with indentation and make sure that you are matching braces. The code you provided is missing a matching bracket. There's also an obvious problem which is that you output errors, before you've started the html section of the page (in cases where there is an error). This will at best malform your html document. The other issue is that you don't have a form, nor does that form set the method to make a POST, so there's no way that the code can work as you intended. You also don't have a form element to test against Here's something more likely to work, based on what you provided: <?php $errors = array(); if (!empty($_POST["submit"])) { $fullName = $_POST["fullname"]; if (empty($fullName)) { array_push($errors, "Fullname is empty"); } } ?> <!DOCTYPE html> <html> <head> <title>Help</title> </head> <body> <?php if (count($errors)>0): ?> <ul> <?php foreach($errors as $error): ?> <li><?= $error ?></li> <?php endforeach ?> </ul> <?php endif ?> <form method="POST"> <input name="fullname" type="text"> <input class="submit-btn" name="submit" type="submit" value="Register"> </form> </body> </html> -
Just looking at the way the world has gone, the interest in having issue tracking systems that aren't integrated into source code management, which is something you get from Github, Bitbucket, Gitlab and Launchpad to name a few of the better known options, means that there is isn't much incentive for anything new to appear. MantisBT has a large and active userbase, so I think you are in good shape going with that project, and it has been around for over 20 years. I'm not sure what you are using Issue tracking for, but there are also any number of free hosted solutions beyond the ones I mentioned, all of which have some level of free use. Atlassian for example, which has the well known Jira and Confluence products, offers free hosted cloud accounts, for up to 10 users. Last but not least, you can always fork Flyspray on github and maintain it yourself if it works for you. It's LGPL 2 licensed, so the worst case scenario is that someone might need to takeover the project, if the current maintainers have given up on it. That doesn't seem to be the case from what I can see, but it does seem that their project flyspray base has lost hosting, and they haven't figured out a new solution. Arch Linux (which has really gotten a boost with the popularity of docker and the many container images that start with it) continues to use Flyspray as their bugtracker, so I don't think there's an emergency. If you're using a packaged version, and support for a new package is lagging or non-existant, you can always just git clone the project repo: https://github.com/flyspray/flyspray Assuming your workstation can support Docker, you can run a PHP container pretty easily with a prior version that supports your Flyspray version. *update* Just looked at github and the main contributor Peterdd made some commits as recently as february, so certainly not a ton of new activity, but not dead either.
-
He hasn't been on in a few weeks. Hopefully he is doing fine, and just taking a break or a vacation.
-
my MacBook Pro doesn't like java...
gizmola replied to maya8989's topic in Other Programming Languages
Older versions of java that were created before the Apple Arm (M series) chips will not work with the M1 macs. The only builds they have are for Intel based macs. In order to get support for the newer ones you need a newer version of Java. Your older apps should work with newer versions of Java and Tomcat. You might also consider trying to use Docker. Here's the official Tomcat docker image: https://hub.docker.com/_/tomcat If you want to try it out (assuming you installed Docker) scroll down the page to the section that says "How to use this image." and follow those instructions. I would 100% be using Docker to run a local tomcat for development. -
I would take a look at the NFSen project, which is written in PHP and Perl. You are also able to extend it with modules written in either of those languages. https://nfsen.sourceforge.net/
-
Return $this if static method called on an object
gizmola replied to NotionCommotion's topic in PHP Coding Help
Conceptually, static methods are part of a class, given how they are called, but the reality is that there is a magic object created, so that for example, static variables have a place to live. This code works, and you can consider it, if you would like. There are also several alternatives like return new self() or return new static() as well as return __CLASS__. I'm fairly sure all these actually work with PHP 8. Consider this code: <?php class Foo { private static $callCount = 0; private $previousCallCount = 0; public static function addCount() { self::$callCount++; return self::class; } public function setPrevious() { $this->previousCallCount = self::$callCount; } public static function getCount() { return self::$callCount; } public function getObj() { return $this; } public function getPreviousCallCount() { return $this->previousCallCount; } public static function getCurrentCallCountStatic() { return self::$currentCallCount; } } echo "start " . Foo::getCount() . PHP_EOL; Foo::addCount()::addCount(); $foo = new Foo(); $foo->setPrevious(); $foo->addCount(); echo "addCount was called, now " . Foo::getCount() . PHP_EOL; $fooObj = $foo->getObj(); $fooObj->setPrevious(); $fooObj->addCount(); echo "addcount was called, now " . Foo::getCount() . PHP_EOL; echo "What is fooObj's addCount? " . $fooObj->getCount() . PHP_EOL; echo "Previous: " . $foo->getPreviousCallCount() . PHP_EOL; echo "Next: " . $fooObj->getPreviousCallCount() . PHP_EOL; echo $foo === $fooObj ? 'Same objects' : 'Different Objects'; So I like to think of it as "there's this one object that exists to support static class use. It's actually kind of a mess, but this code works, and even has some surprises in my opinion as in how $previousCallCount is handled. I'm not sure what problem this solves, or why this is a good sensible solution. If you want a fluent interface you can return the magical static object and use it fluently if you have a bunch of non static methods you would call. From time to time I've seen people utilize this feature, but I don't recall where I last saw it, or if I understood the motivation. A lot of your questions seem to be missing clear obvious context, so I'm never quite sure if I get why you want to explore this stuff, but I commend your consistent interest in exploring ideas within what php allows. -
It kinda depends on how you set things up. For example, you are referring to Laragon. Did you use that to install PHP on your new computer? If so, are you able to open up a command terminal, and type php -v and get the cli client? If so, I don't think you need anything that you are currently trying to do, so you're making a mess. Also I would recommend this: Install the intelephense plugin or the php tools plugin from devsense Follow the instructions carefully to configure either one The default php extension is borked and basically doesn't work right. Setting you are making aren't relevant to either intelephense or to php tools. These instructions include disabling the default extension that will conflict with intelephense if you don't disable it see https://marketplace.visualstudio.com/items?itemName=bmewburn.vscode-intelephense-client This videos is the most complete coverage of setup of a PHP environment on windows i've seen. He demonstrates and advocates for many extensions he finds useful for php web development and what he uses them for. He also shows you how to use WSL integration as an alternative to local php on windows dependence, which has some advantages.
-
Hmm, what do you think about the messages it provided? Manual says: https://www.php.net/manual/en/function.spl-autoload-register.php Assuming you identified the offending line of code as being error_log(......) one of the parameters you are passing is actually an array, and you are treating everything as a string. If I were to guess, it's probably whatever is being passed in $context. Again, see the php manual for the function error_log: https://www.php.net/manual/en/function.error-log.php
-
Perfect approach. If you would like me to answer some of the domain questions for you, feel free to PM me the domain and I'll search the DNS and determine what services are being used, if you are having trouble figuring that out. Either way I think you are on the right track. With that said you need to understand how to install and require the phpmailer libraries. Typically people will use composer to install the library. It can be downloaded and specified manually, but you will notice in that code namespaces, which if you are new to PHP maybe over your head. They are very important these days, and you'll see looking at that other thread, that the libraries are referenced at the top with use statements. Those are not magic without either include/requiring the individual files, or using an autoloader script (which is part of what composer will do for you --- generate an autoload.php script you can include. If you use the autoloader, then you don't need anything other than the use statements, as PHP understands how to look for and locate the library source scripts. You might already know all this, but if you don't, this is why the php composer tool is pretty much essential to professional php development these days. It provides dependency management and location and setup of 3rd party/component libraries like phpmailer. I would highly recommend that at least for this script, this is how you integrate phpmailer into your script.
-
Call to undefined function CommonMark\Parse()
gizmola replied to rick645's topic in PHP Installation and Configuration
I will try and clarify a few things for you: PHP has the ability to integrate libraries known as extensions Many extensions can be installed directly via PECL, but there are cases when an extension isn't available via PECL Other extensions have been pre-compiled and packaged such that in a particular linux distro you can add one just by using a system package manager An extension can be enabled or not, by referencing the location of the extension library in the php.ini. The php.ini has an include that will search a directory for other files to include Often extensions not only have a shared library path that is required, but also have some settings that can be configured. For this reason, as Kicken stated previously, most packages and extensions include a config file in .ini format that will go into a typical location like /etc/php.d or similar. The benefit of this is that you don't touch the primary php.ini file. At the risk of overcomplicating, it is also not unusual for there to be multiple php.ini files (one for web integration and another for command line php (cli) settings. For example, some systems may have long lived cli programs they run from cron, and might want to allocate more memory and execution time to those than they would be comfortable with for php web processes. On many distros you have to trace where the actual current php.ini lives. Many distros handle php version updates by providing a base php.ini that they then symlink to a typical location like /etc/php.ini. You might need to investigate the server install and phpinfo() etc. to be sure you understand what config files are being loaded from where. Regardless of that, since you have a directory for extensions already, most people in your situation would: Create a cmark.ini file in that directory and put the extension statement in that file rather than editing the php.ini. You are in a situation where you can't install from an extension nor use pecl, so you're having to use option C, which is to build the extension yourself and enable it. This is what phpize does. It is simply setting up the environment so that the extension code can be configured,compiled, and installed. How to uninstall in this situation? There really is no uninstall. Once you are done with the compilation from source, you get the extension library. It will only be available to php if the extension is enabled. You no longer need the source code and can delete it entirely once you've made it. All the make install does is move it to the system extension directory (which is a convenience and not a requirement), and may add an entry enabling the extension in the php.ini. Commenting out the extension, and it will no longer be part of php If you don't need it, further, commenting out, or removing the line of extension.ini file (if you made one) will disable it. You can delete the extension or not, but it's not registered in the OS or anything like that. Depending on how you run PHP you probably will need to restart "php" which might be restarting the webserver, or restarting php-fpm if that's what you are using. There is nothing else to it. -
We do get these type of questions regularly. If you look at the code for this person it will give you a good idea of how you would utilize phpmailer. The basic mail() function -- I don't want to write up a manual on it, but it has a few different possible modes, although in general it's not what you want to use here. Probably it is dumping mail to GoDaddy's servers, which also aren't setup to be the MX for the customer's domain. So you have a few different options here: Change everything so GoDaddy is hosting email for the domain Use the current mail exchanger (assuming it's Microsoft right now). You may need to be able to modify/make changes to the customer's DNS entries for their domain, depending on how things currently work, and whether or not you want to change. Here is a fairly recent thread: So, again I'm still not clear on the moving parts here, but I can tell you what is feasible. Things you need to clarify: For the customer's domain, who is hosting mail? In DNS entries, this is the company/servers that are accepting mail for the domain Is this Outlook/aka Office365? Keep in mind these are different brand names for Microsoft hosted email. It also includes Hotmail or used to. This is not to be confused with the windows IMAP client "Outlook" that was/is part of what was microsoft office and is now rebranded as Office365 -> https://www.microsoft.com/en-us/microsoft-365/outlook/email-and-calendar-software-microsoft-outlook When you say that the client uses Outlook, we need to be clear. Anyone can use outlook with any system. I can setup outlook to work with a domain I personally own, that is a fully functional self hosted email system if I want to, because outlook supports IMAP, and I provide IMAP services for my domain(s). With that said, as part of office, Outlook is very popular in a lot of corporate "all microsoft" shops because it has built in support for Active Directory, exchange, and microsoft networking and file services that many companies use. IMAP includes integration with things like calendering, which is another reason people tend to like it. I also understand if they don't want to change from (whatever they have now) because emails are stored on whatever server they are using now. Changing to use Godaddy's server could work with Outlook, but all the mail that was on the old server would be gone. Email could be moved in a variety of ways, but with only client access, it could be a time consuming and error prone process if they have a large number of emails being stored. Because I don't know the facts, I can only guess at the obstacles, and options. Again, *if* current business email for the customer's domain is being hosted by microsoft, then the path of least resistance is to determine the protocol and credentials needed to setup SMTP mail delivery into the customer's system. This involves something like: configuring the phpmailer configuration settings to use smtp, along with TLS, and a user name and password for the account(s) they pay for from microsoft as part of their email hosting. Once you set this in phpmailer, you make the to: be that account (ie. From: [email protected], and then To: is customer. If this was working previously, as I said, any mail sent directly to the same user (same to/from) stays in microsoft's system and goes right into their box. Most of these systems also allow aliases to be created, so typically a different user alias like [email protected] can be setup within the microsoft configuration for the hosted account, and you could instead have phpmailer configured to send mail from that address rather than [email protected] I think I'm going to leave it at this now, as I still have way too many frustrating questions about this, and the various branding of microsoft products and services with overlapping names doesn't help. Given everything I've written, there could be an entirely different set of factors at play here, and without detailed and specific information about the domain MX record as well as any other entries like SPF, there's really no way for us to help you further other than just guessing.
-
^^^^^^^^^^^^^^^^^^^^^^^ 100% This video is highly recommended. Try out some of the simple code he shows, and you should be able to figure out how to make it apply to your desired layout. The video does a great job describing which use cases are better suited to a particular layout.