PHP inside HTML not running

This section is for posting questions which are not directly related to WYSIWYG Web Builder.
Examples of off topics: web server configuration, hosting, programming related questions, third party scripts.

Note that these questions will generally not be answered by the administrators of this forum.
Post Reply
zxspectrum2
 
 
Posts: 8
Joined: Sat Sep 28, 2024 6:28 pm

PHP inside HTML not running

Post by zxspectrum2 »

I have a HTML object and inside it is this PHP script, database details blanked out for here :-

Code: Select all

<?php
echo "DB Test";
// Database connection details
$servername = "";
$username = " ";
$password = "";
$dbname = "";
echo "DB Test connecting";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
echo "DB Test done";
echo $conn;
// Check connection
if ($conn->connect_error) {
   
    die("Connection failed: " . $conn->connect_error);
}
echo "<p>2ID: "  . " - title: " .   "</p>";
// Write a SQL query to select data from a table
$sql = "SELECT id, title FROM filedownloads";
$result = $conn->query($sql);

// Iterate through the result set and display data
if ($result->num_rows > 0) {
    // Output data of each row
    while($row = $result->fetch_assoc()) {
        echo "<p>ID: " . $row["id"] . " - title: " . $row["title"] . "</p>";
    }
} else {
    echo "0 results";
}

// Close the connection
$conn->close();
?>
The PHP code is syntactically okay but whether or not it is good PHP is another question.
When I run it I get the following output.
DB TestDB Test connecting

Is there something I am missing?
User avatar
Pablo
 
Posts: 22472
Joined: Sun Mar 28, 2004 12:00 pm
Location: Europe
Contact:

Re: PHP inside HTML not running

Post by Pablo »

First note that this is unrelated to the software.
The code will be inserted "AS IS" , so if it does not work then there is most likely something wrong with the code.
If there is no error in the browser then you can look it up in the PHP error log on the server.
zxspectrum2
 
 
Posts: 8
Joined: Sat Sep 28, 2024 6:28 pm

Re: PHP inside HTML not running

Post by zxspectrum2 »

Okay thanks Pablo, I will need to test this outside of the web builder app.

Regards
Ken
wwonderfull
 
 
Posts: 1439
Joined: Fri Aug 21, 2020 8:27 am
Contact:

Re: PHP inside HTML not running

Post by wwonderfull »

Try to do things correctly if possible as it is database related code so any mistake will lead to information leakage. I hope you know what you are doing.
Last edited by wwonderfull on Thu Oct 17, 2024 10:11 am, edited 1 time in total.
User avatar
BaconFries
 
 
Posts: 5640
Joined: Thu Aug 16, 2007 7:32 pm

Re: PHP inside HTML not running

Post by BaconFries »

I will need to test this outside of the web builder app.
You should note that you cannot "Preview" php locally in the software you will need to publish to your host/server before you will see the results. Or you will need to install the likes of xampp to set with on your PC.
lummis
 
 
Posts: 217
Joined: Sun Apr 24, 2011 9:18 am
Location: UK

Re: PHP inside HTML not running

Post by lummis »

Looking at the code, I wonder if you can achieve your objective by using one of the Database/Tables extensions (seehttps://www.wysiwygwebbuilder.com/extensions.html) either paid or unpaid. With some you can insert your own MySQL query and you can rely upon the extension to deal with the connection to the database.
zxspectrum2
 
 
Posts: 8
Joined: Sat Sep 28, 2024 6:28 pm

Re: PHP inside HTML not running

Post by zxspectrum2 »

BaconFries wrote: Thu Oct 17, 2024 10:10 am
I will need to test this outside of the web builder app.
You should note that you cannot "Preview" php locally in the software you will need to publish to your host/server before you will see the results. Or you will need to install the likes of xampp to set with on your PC.
Yes, I know I have to use a web server to run PHP but how cool would it be to be able to preview PHP end result inside WB19?
:-)
zxspectrum2
 
 
Posts: 8
Joined: Sat Sep 28, 2024 6:28 pm

Re: PHP inside HTML not running

Post by zxspectrum2 »

lummis wrote: Thu Oct 17, 2024 11:42 am Looking at the code, I wonder if you can achieve your objective by using one of the Database/Tables extensions (seehttps://www.wysiwygwebbuilder.com/extensions.html) either paid or unpaid. With some you can insert your own MySQL query and you can rely upon the extension to deal with the connection to the database.
I did have a look at them but I couldn't see one that was able to list, and display images/URLs/ etc in list view?
thanks
wwonderfull
 
 
Posts: 1439
Joined: Fri Aug 21, 2020 8:27 am
Contact:

Re: PHP inside HTML not running

Post by wwonderfull »

zxspectrum2 wrote: Thu Oct 17, 2024 2:09 pm I did have a look at them but I couldn't see one that was able to list, and display images/URLs/ etc in list view?
thanks
Do you mean you need something like a dataviewer or a crud where you can see users data and their pictures along with url and other details that sort of thing?
zxspectrum2
 
 
Posts: 8
Joined: Sat Sep 28, 2024 6:28 pm

Re: PHP inside HTML not running

Post by zxspectrum2 »

I found the issue I was having and can now see the data on screen - it was a database name typo!!!!
Thanks to all for your replies

PS It was a list of downloads which included an image on the same line, though that bit still needs work :-)
Post Reply