-
Posts
6,073 -
Joined
-
Last visited
-
Days Won
154
Everything posted by gizmola
-
It's a great question. I have to think that it was extra work to create the associative array version, so it never really made a lot of sense why having two versions of the same data returned in the same array, would be the default.
-
Barand as usual offers an expert solution. Looking at your original schema model, please don't include a prefix for the table name like q_column etc. Also don't use Enums. They violate a basic tenet of relational database theory (any field/attribute in a row should contain a single value). If you really want category and type, those are foreign keys to separate tables. In cases where the PK is a char, I will tend to name that column "code", just to be clear that it's not a sequential key. For example, I often have fairly static type tables, like "status" where the allowable values are things like "new", "active", "deleted", and I'll use a char(1) and 'N', 'A', 'D' for those values in a status table with "code" and "description" as the only fields. I personally have done what Barand did (using table_id) many times, primarily to make it easier for the design tool(s) I typically used, but most ORM's like it if you just name your table pk "id". When you add a foreign key, then make that "tablename_id". A lot of ORM's will pick up on naming conventions for keys, so it makes things easier, as the ones I've used will default to the assumption that the "id" field is the primary key for the table. Not a huge fan of these types of columns, but created_at, and updated_at are good for timestamps like your "q_added".
-
Just a quick comment on this. A user does not need to see a button to call Ajax in order to exploit the Ajax. All they need is to know that it is there, and they can use whatever technique or tool that they want to, to post to the Ajax url. Anything that needs to be secured should have a separate permissions check. A simple common solution would be to check something stored in the session that indicates someone is an admin, or some other user level. Then your Ajax code should check that and only execute the actual deletion code when their status is affirmed.
-
This is the mod_rewrite rules of a typical current wordpress: RewriteEngine On RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] What this shows, is that Wordpress implements a front controller. I don't know exactly what the issue is, because my example was: user's url -> rewritten to And it appears to me that you presented: rewritten to -> user's url Requinix has tried to steer you towards this, so I'm going back somewhat to the start, and suggesting you add this to the bottom of your rules: RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)/ page.php?slug=$1 [L,QSA]
-
The eclipse PHP environment (PDT) is built upon the eclipse "Dynamic Languages Toolkit"(DLTK). What the DLTK does is build the internal structure that PDT depends upon to map and index the project files. It utilizes the project source tree, so in general, there is no need to go farther than that, and as php has evolved with the advent of composer, there isn't much need to specify the location of libraries that exist outside of the source tree. In the olden days of PHP when people used PEAR libraries, you would have pear libraries that were put in a shared location, but PEAR is entirely deprecated now that we have composer for component library management. I don't use Eclipse PDT much these days, other than for a specific maintenance project, as I find that PHPStorm or VSCode with the inteliphense plugin are both much better IDE's for PHP development at this point in time.
-
In the code you provided, it assumes there is a function ConfirmCancelOrder. As requinix stated, if this is your choice, you only need confirm. From a style and usability standpoint, builtin modals like alert and confirm are not used much anymore, because they depend on the browser/os UI kit, and can't be styled to look like the rest of the UI, which looks amateurish. Most people implement a modal dialog window. Most css frameworks come with widgets (css + javascript) that are easy to use. Twitter bootstrap is the grand parent of this idea, and while I don't offer this a recommendation, if you already happen to be using twitter bootstrap, here's a link to documentation for their modal. Most other css frameworks, or javascript ui frameworks, have similar helpers. The general idea is simple and reusable -- your markup will include the div for the modal which starts out hidden, and when needed, you pass some parameters to it for the specific title and message. You can usually build your code in a way that makes it easy to include the partial html and javascript you need for any pages that have html forms where you also want confirmation.
-
[eclipse] open php file without extension
gizmola replied to rick645's topic in Editor Help (PhpStorm, VS Code, etc)
Making a file without an extension work with any sort of serverside language, requires configuration to associate those files with the serverside language. The same sort of association can be made in an editor, but as previously commented, using the rewrite capability in apache mod_rewrite or nginx is the best practice. -
How do I count results in a nested array generated by Preg_Match
gizmola replied to marmelade7's topic in PHP Coding Help
It seems like you are fixed on using $matches. People tried a few different ways to tell you that the function returns the number of matches, so this is your original code re-written. $c = preg_match_all('/[0-9]{1,}[-]{1}[0-9]{1,}/', $txt, $matches); $d = preg_match_all('/[A-Za-z]{1,}[-]{1}[A-Za-z]{1,}/', $txt, $matches); echo "c count=$c"; echo "d count=$d"; The reason for this, is that any regex can have groupings (capture groups) that produce partial matches, and all of these are returned in the $matches array. The return value only returns the actual number of full matches, which is clearly what you want. -
On the most recent screenshot you provided, what do you see when you click on the "manage" link next to line that shows php version 7.4?
-
Not that this explains the problem, but if you want a grouping for these 2 products, then group by product.product_id, not product_name. Also, no reason to do this: JOIN products ON (products.product_id = 55 OR products.product_id = 51) You should be joining from the salesdetails row to product. JOIN products ON (products.product_id = salesdetails.salesdetails_product_id)
-
In addition to what requinix said, consider that private networks are using private "non-routable" IP ranges. Outwards, your router is doing "Network address translation" (NAT) When you want to access a particular computer on a particular port that is inside a private network, there is simply no way to do that, because these IP ranges like 10.x.x.x and 192.168.x.x and 172.31.x.x are reserved for private network use. Core routers will never route packets with those IP addresses. A VPN is giving you a private IP on the private network, and intelligently routing traffic meant to go to your intranet. Production networks use the same ideas. As requinix already explained, there are many good reasons to isolate servers inside a private network, and even subnet the private network to isolate groups of computers from each other. Tunneling allows you to use a gateway server for entry into a private network, just as a vpn server does. And you can then hop to another server, and perhaps others if need be, in order to create a secure tunnel that gets you network access to the server you want. Most system administration is enabled by the use of SSH to connect and tunnel through servers to access other servers, that otherwise would be unreachable.
-
If you can afford it, PHPStorm is pretty much the professional standard. A lot of people also use visual studio code, in combination with the "Intelephense" plugin. Intelephense provides a good number of features for free, but you can also license it for $20 to unlock the rest of the features, which I would highly recommend.
-
I looked at the site, opened the menu and tried to navigate to: http://whymyphp.online/galery/fetchit.php which produces a 500 error. This is the same issue we've been looking at, and we keep coming back to the fact that mysqli is not the version that has been linked to the myslqnd driver. This is not by any means a new issue. See this 4 year old SO question. The confusion relates to godaddy and cpanel, and the specific extensions that are enabled through cpanel. At this point, it is pretty much up to the OP to enable the right extensions through cpanel.
-
Phpmyadmin is just a PHP application. Access to the CPanel setting you want is described here: https://www.godaddy.com/help/view-or-change-the-php-version-for-my-linux-hosting-16090
-
It would not work any better in Oracle, because your logic is faulty. Keep in mind that inside your parens, if any of those items are TRUE, then the entire group is true. team_name is not null or team_name !='' or team_name NOT LIKE '%[teamname]%') In the row you don't expect, consider each condition team_name is not null ---> true team_name !='' ---> true team_name NOT LIKE '....' ---> false. So you get the row, despite the fact that the 3rd condition is false. What it appears you really want is: team_name is not null AND team_name !='' AND team_name NOT LIKE '%[teamname]%')
-
This is really the crux of the issue. Applications are rarely written from scratch -- they are assembled from component libraries (a collection of OOP classes). You don't have to know how to write your own OOP code immediately, or even to write any sophisticated OOP to make use of other peoples components. This is why you really want to start with composer and learn enough about that to start making use of components that will make your application faster, and better quality in the vast majority of cases. You can always verify the quality of the component, by looking at and even running unit tests they have written for the library. You need to know the basics of oop, but you don't have to be an OOP expert.
-
Along with validation, using the developer tools is an excellent iterative way to explore the state of the DOM, and to find syntax errors in javascript, or to explore layout and effective styles. The network tab is also extremely valuable, in examining request/response data for ajax or regular form processing via get or post requests. That should always be your first step in starting to debug things. Most modern code editors people use to develop PHP with will also catch a lot of syntax errors, although code that renders html will typically look valid so long as the php code is valid. Moving html into a template engine, or even making use of heredoc and nowdoc is helpful in many ways to separate markup from your logical code.
-
The purpose of phpfreaks is to help people learn about and develop web applications. Ultimately, all we want is people who are genuinely making their best effort. There's no reason for anyone to be angry with you or this thread. I do appreciate you providing an update on your progress, and the reasoning behind your conclusions.
-
GoDaddy has a bunch of different hosting plans, and lots of servers. Experience with one particular server, doesn't predict exactly what you might experience with a different account, that is likely hosted on a different server. You can get a lot of information just using phpinfo() on each. As Requinix has already discussed, the issue points to lack of the mysqlnd driver. In GoDaddy's cpanel, you can change php configurations using the Select PHP Version. In the menu, I'm guessing you'll see mysqli checked, and nd_mysqli unchecked. There should also be a choice for mysqlnd, that may or may not be checked. If it is not checked, check it. Uncheck the mysqli option, and check the nd_mysqli option. Save this new configuration, and then retry your code. Please let us know if this fixes the issue.
-
trying to insert multple form data into msyql database
gizmola replied to jcarney1987's topic in PHP Coding Help
I should add, you could attach this code to the onclick of a button you have separately, or add to every new row. Obviously, as you can see, setting the onclick for the buttons this way makes it very easy to render an equivalent button without having to also manage a call to addEventListener for each new row that's generated. If you only want to have one button for adding new rows, then I'd give that button an id and use element.addEventListener instead. -
trying to insert multple form data into msyql database
gizmola replied to jcarney1987's topic in PHP Coding Help
In this case you don't need ajax. The way to think about a feature like this, is to make sure you are clear on what is happening in the browser when you are on a web page that has already been delivered to your browser in an HTTP response. The page has the DOM loaded, and is running completely disconnected from the server. If you were looking at network traffic, you would likely see that there is no connection to the web server open. So the way to think about it, is that you have a javascript application running in your browser. A traditional form, when submitted, is a new request to the server. Depending on if it's GET or POST method, a new HTTP request gets sent, the browser waits for the response, and the entire DOM is rebuilt based upon the response data, which is going to be more HTML (along with associated javascript, css etc.). Ajax was added to the DOM api, in order for there to be a way that a page could send and receive data, without this entirely new HTTP request/response. It's an HTTP request through javascript, where the data returned can then be evaluated within the running javascript and used to update the page. So ajax is an alternative to standard HTTP request/response, typically with forms, but now, with many other aspects of dynamic DOM manipulation with javascript. So, hopefully that helps you understand ajax, and why it is extremely beneficial and useful in modern web applications. In this case, it is absolutely not needed. So to go back to the page in your browser, that page is running locally as an application hosted within the browser. It has to be able to handle mouse and keyboard events, and unless it's a standard click on a link, or a submit button for a form, there won't be a new http request generated by default. What you have is a form, where you have rendered a table inside of it with a series of HTML form elements to be filled in. You want to be able to add a new set of these form elements, and all that is required there is javascript, running locally to dynamically manipulate the DOM and add a new row to the table with a new set of table elements. jquery is the grandfather of javascript frameworks. It was designed to make it easy for people to do DOM manipulation of the type you need, and it also has functions that make ajax easy. Most developers who have been around a while, have probably used it in the past, and it was part of the first really popular css ui framework (Twitter Bootstrap). It's got a lot of capabilities, but it's also a bit bloated by today's standards. As things have evolved and changed in the javascript UI world, a lot of other libraries and javascript frameworks have emerged, and many of the things jquery was used for in the past are being done instead with a framework like react or vue. So I won't show you how to do this in jquery, since if you already aren't using it in some way, I won't suggest to start down a path that isn't being used for new development. Here is some simple javascript that will dynamically add a new row to an existing table. It isn't exactly matched to what you have now, but is based on it. function addRow() { console.log('clicked addrow'); const table = document.getElementById("form_wrapper"); const row = table.insertRow(1); let c1 = row.insertCell(0); let c2 = row.insertCell(1); let c3 = row.insertCell(2); let c4 = row.insertCell(3); c1.innerHTML = '<label>Item:</label><input type="text" class="item" size="5" name="item_number[]">'; c2.innerHTML = '<label>Desc:</label><input type="text" class="description" size="20" name="description[]">'; c3.innerHTML = '<label>Qty:</label> <input type="text" class="quantity" size="3" name="quantity[]">'; c4.innerHTML = '<button type="button" name="add_row" onclick="addRow()">+</button>'; } Here's a codepen, for demonstration purposes: https://codepen.io/gizmola/pen/jOQLKBd I think you'll find that this use of document.getElementById, is the most common way to select an item that has an id attribute. There should only ever be one element on a page with that id, so it's perfect for selecting the table. Once you have the table element you can dynamically add a new row, and the cells you need. -
I don't think you understand rewrites. Rewriting in this way allows you to use a non-existent url like /slugname/ to the scripts that can actually process them. You can't "rewrite" the actual scripts to a non-existent url. They could never be resolved. Rewrites are not magical "rewrite my url's to the rest of the world on the fly". It's the responsibility of your markup and code to display your url's in the virtual/ pre-rewritten form you want users to see them. If I've misunderstood your statement, please let respond with a specific example as in: Client sends https://www.domain.com/a/ ---> Server rewrites to https://www.domain.com/page.php?slug=a
-
The fields that are part of the result from 4 joined tables, isn't really important in comparison to the number of rows in the result set, and any limiting where clause criteria. As @requinix stated: EXPLAIN query... is your analysis tool. We'd need to see the query and its explain plan to offer further insight. Many times, if performance is bad, you'll be able to see the reasons in the explain. Depending on the criteria, adding a covering index might solve your performance issue, but the only way to know for sure is via the explain. You want to take a look at the rows and key columns to see how many rows are being examined, and what indexes (if any) are used in generating the final result.