Avatar of Chris Millard
Chris MillardFlag for United Kingdom of Great Britain and Northern Ireland

asked on 

Wordpress page - incorporating PHP form which returns results of a MySQL query

I have written a PHP web page with a form that runs a search query on a custom MySQL database and returns the results as a table.

Is there a way that I can incorporate this PHP form within Wordpress so that it follows the same theme layout and will still be able to return the results of the search while again, displaying the results with the same theme layout?
WordPressPHPMySQL Server

Avatar of undefined
Last Comment
Chris Millard
Avatar of Jason C. Levine
Jason C. Levine
Flag of United States of America image

Yes, just make a custom page template by copying your theme's page.php file:

https://developer.wordpress.org/themes/template-files-section/page-template-files/page-templates/#creating-a-custom-page-template-for-one-specific-page

and in that specific template, add your own PHP scripts and returns as desired.
Avatar of Chris Millard
Chris Millard
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

I have done this, but the MySQL query isn't returning any results, even though the same PHP script works when in a standalone file.

I know that the parameters being passed back to the page are getting through OK, as I am echoing the query to the page and the query is correct.

I also don't get any MySQL connection errors either.
ASKER CERTIFIED SOLUTION
Avatar of Chris Millard
Chris Millard
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Chris Millard
Chris Millard
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

Got my answer from the Wordpress support site. I needed to use the WP_Query class to communicate with my database
PHP
PHP

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

125K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo