WebSite X5Help Center

 
Errol W.
Errol W.
User

Php coding  en

Автор: Errol W.
Просмотрено 1100, Подписчики 1, Размещенный 0  

I am using this code:

<php?
$database = "databasename"
$servername = "localhost";
$username = "username";
$password = "password";

// Create connection
$conn = new mysqli($database, $servername, $username, $password);

// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";

SELECT `value` FROM `cartinvoice_addresses` WHERE `field_id` = "Name" ;
?>

If you this link dbViewer - Delta Dream (dreamfoundationmobileal.org)

Part of code is display and nothing from database.

Please help.

Размещено
16 Ответы - 8 Полезно
Andreas S.
Andreas S.
Moderator

Is PHP included and enabled in your hoster package?
If yes, which PHP version is running on your server?

Читать больше
Размещено От Andreas S.
Franz-Josef H.
Franz-Josef H.
Moderator

In the first line you forgot the semicolon, I think. Correctly it should read like

$database = "databasename";

Читать больше
Размещено От Franz-Josef H.
Errol W.
Errol W.
User
Автор

PHP version 7.3.27

Читать больше
Размещено От Errol W.
Axel  
Axel  
User
Лучший пользователь месяца FR

Don't forget to generate your page with PHP extension... By default it is HTML

Читать больше
Размещено От Axel  
Franz-Josef H.
Franz-Josef H.
Moderator

the given page is with php extension...

Читать больше
Размещено От Franz-Josef H.
Errol W.
Errol W.
User
Автор

The php extention is used.

Читать больше
Размещено От Errol W.
Franz-Josef H.
Franz-Josef H.
Moderator

Did you check the missing semikolon behind the $database definition?

Читать больше
Размещено От Franz-Josef H.
Errol W.
Errol W.
User
Автор

I fixed that, but made no difference.

Читать больше
Размещено От Errol W.
Errol W.
Errol W.
User
Автор

So I got rid of the connection part of the code. Now, page comes up blank.

<php?
$database = "databasename"
$servername = "localhost";
$username = "username";
$password = "password";

SELECT `value` FROM `cartinvoice_addresses` WHERE `field_id` = "Name" ;
?>

dbViewer - Delta Dream (dreamfoundationmobileal.org)

Читать больше
Размещено От Errol W.
Franz-Josef H.
Franz-Josef H.
Moderator

you defined the server name with localhost. Is that correct? It is usual that the database is on your web space with your web host or provider.

Читать больше
Размещено От Franz-Josef H.
Errol W.
Errol W.
User
Автор

I started out using the database viewer built in to X5. When setting that up, it was using localhost. I assumed I could do the same.

Читать больше
Размещено От Errol W.
Axel  
Axel  
User
Лучший пользователь месяца FR

Try to put the IP of your database web hosting and not the DB name wichi is not propaged into the DNS for a remote connection. Works ONLY when you try directly from the provider.

You cannot used the IP of your DB from locally testing. this one is not reachable from external ... Only localhost in this case.

Читать больше
Размещено От Axel  
Errol W.
Errol W.
User
Автор

I put in the ip address for the server name. It still comes up with a blank page.

Читать больше
Размещено От Errol W.
Axel  
Axel  
User
Лучший пользователь месяца FR

Into your original post the SELECT is wrong

SELECT `value` FROM `cartinvoice_addresses` WHERE `field_id` = "Name" ;

good one is:

SELECT `value` FROM `cart_invoice_addresses` WHERE `field_id` = "Name" ;

Читать больше
Размещено От Axel  
Axel  
Axel  
User
Лучший пользователь месяца FR

I suggest to you to test your code into a standalone PHP file without WSX5

You have many errors into your code

// Create connection - wrong syntax
$conn = new mysqli($database, $servername, $username, $password);

// First line is wrong syntax
<php?

// SELECT syntax seems wrong
SELECT `value` FROM `cartinvoice_addresses` WHERE `field_id` = "Name" ;

$result = $conn->query("SELECT 'value' .......

When your code is OK into standalone file, use it into WSX5

Enjoy!
Axel

Читать больше
Размещено От Axel  
Axel  
Axel  
User
Лучший пользователь месяца FR

This code is working locally without WSX5 into a PHP extension file.

<!DOCTYPE html>

<?php

$dbname = "afs_demo";
$servername = "localhost";
$username = "root";
$password = "password";

// Create connection
$mysqli = new mysqli($servername, $username, $password, $dbname);
$mysqli -> set_charset("utf8");

// Check connection
if ($mysqli->connect_error) {
die("Connection failed: " . $mysqli->connect_error);
}
echo "Connected successfully";


$sql = "SELECT value FROM cart_invoice_addresses WHERE field_id = 'Name'" ;

// $result = $mysqli->query($sql);
$result = mysqli_query($mysqli, $sql);


// while ($row = $result->fetch_assoc()) {
while ($row = mysqli_fetch_assoc($result)) {
echo '<br>';
echo $row['value'];
}

$mysqli->close();

?>

the displaying is:

Enjoy!
Axel

Читать больше
Размещено От Axel