PDO connection if you prefer not to use a prerender service

This is the code before HTML

On your test page please click App inside the App Stucture tree, then in the properties where you have App Root, please make sure that is set to Page and not Body or App Connect will ignore all the stuff in the head.
Let me know if that fixes it please.

If you are using PHP code in the meta tags it doesn’t matter where the app root is set to.
PHP code is rendered on the server side before the page is loaded.

I figured, but i cant see his real code, only that tiny part, so not sure whats going on in there, just figured it could be worth a try

1 Like

it is now configured on Page but nothing has changed

ok well it couldn’t harm to try it out, whats your routing looking like Marzio
Would you mind pasting the entire code for you test page here please

This is the head code

Before facebook even gets it, just opening your URL and looking at the head its missing
Almost all the dynamic content tags are empty

But it is strange
If you see the screenshot I sent you, the content exists

To complete this is the body

Your custom php above the head does not seem to be rendering on the server at all, because i cant see the php in the inspector it is difficult to fully see whats exactly going on, could you please open your page test_fb.php select all in code view, not a screenshot or just a piece and paste the entire code between some backticks here, so i can paste it into a page on my wappler and try replicate the problem

Edit, just alter your password to some placeholder text

At the top of the file are the passwords to access the database.
In order not to make them public, perhaps it is better if I send you the file privately?

No problem at all, send in a pm or just remove the passwords, up to you.

<?php $prod = 'https://www.vacanzemarine.it'.$_SERVER['REQUEST_URL'];

	try {
		$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
		$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
		
		//The SQL statements
		$stmt = $conn->prepare("SELECT * FROM products WHERE IDProd = '$prod'");
		
		$stmt->execute();
		$mySeoTags = $stmt->fetch();
		
	}
	catch(PDOException $e) {
		echo "Connection failed: " . $e->getMessage();
	}
?>

<!doctype html>
<html is="dmx-app">

<head>
	<base href="/test/">
	<script src="../dmxAppConnect/dmxAppConnect.js"></script>
	<meta charset="UTF-8">
	<title>Test FB share</title>
	<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
	<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous" />
	<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
	<link rel="stylesheet" href="../bootstrap/4/css/bootstrap.min.css" />

	<title><?php echo $mySeoTags[title]; ?></title>
	<meta name="description" content="<?php echo $mySeoTags[description]; ?>">
	<meta name="twitter:title" content="<?php echo $mySeoTags[title]; ?>">
	<meta name="twitter:description" content="<?php echo $mySeoTags[description]; ?>">
	<meta name="twitter:image" content="https://www.vacanzemarine.it/public/images/<?php echo $mySeoTags[image]; ?>">
	<meta name="twitter:image:alt" content="https://www.vacanzemarine.it/public/images/<?php echo $mySeoTags[image]; ?>">
	<meta property="og:title" content="<?php echo $mySeoTags[title]; ?>">
	<meta property="og:description" content="<?php echo $mySeoTags[description]; ?>">
	<meta property="og:url" content="https://www.vacanzemarine.it">
	<meta property="og:image" content="https://www.vacanzemarine.it/public/images/<?php echo $mySeoTags[image]; ?>" />
	<meta property="og:image:secure_url" content="https://www.vacanzemarine.it/public/images/<?php echo $mySeoTags[image]; ?>" />
</head>

<body id="test_fb">
	<script src="../bootstrap/4/js/popper.min.js"></script>
	<script src="../bootstrap/4/js/bootstrap.min.js"></script>
</body>

</html>

<?php
mysql_close($conn);
?>

Important
The first line code before db parameter
<?php $prod = 'https://www.vacanzemarine.it'.$_SERVER['REQUEST_URL'];

1 Like

I know this is not the answer you want to hear but i have tested again and mine is working on my server, therefore the only thing i can imagine is that your server is just not returning the data

All i can suggest is test that, in your body of your page try echo out the $stmt like
<?php echo $stmt; ?> and see what it returns please, if nothing try alter the query to SELECT * FROM products without the WHERE part so we can see if the connection is running and returning anything at all.

You found the problem
I get a result if I delete the WHERE condition; of course in this case it returns the first record
But with $stmt it doesn’t produce anything, Whith $mySeoTags is ok

<?php echo $mySeoTags[title]; ?>
<br>
<?php echo $mySeoTags[description]; ?>
<br>
<?php echo $mySeoTags[image]; ?>

Schermata 2020-07-09 alle 22.29.39

I solved it by changing the first line
$ idprod = $ _GET [idprod];
and the WHERE statement
$stmt = $conn->prepare("SELECT * FROM products WHERE IDProd = '$idprod'");

The page now works, but I go to verify Facebook sharing

I integrated with the settings that were missing and now it seems to work.
But still it reports error URL returned a bad HTTP response code.

<title><?php echo $mySeoTags[title]; ?></title> <meta name="description" content="<?php echo $mySeoTags[description]; ?>"> <meta name="twitter:title" content="<?php echo $mySeoTags[title]; ?>"> <meta name="twitter:description" content="<?php echo $mySeoTags[description]; ?>"> <meta name="twitter:image" content="https://www.vacanzemarine.it/public/images/<?php echo $mySeoTags[image]; ?>"> <meta name="twitter:image:alt" content="https://www.vacanzemarine.it/public/images/<?php echo $mySeoTags[image]; ?>"> <meta property="og:type" content="article"> <meta property="og:title" content="<?php echo $mySeoTags[title]; ?>"> <meta property="og:description" content="<?php echo $mySeoTags[description]; ?>"> <meta property="og:url" content="https://www.vacanzemarine.it"> <meta property="og:image" content="https://www.vacanzemarine.it/public/images/<?php echo $mySeoTags[image]; ?>" /> <meta property="og:image:secure_url" content="https://www.vacanzemarine.it/public/images/<?php echo $mySeoTags[image]; ?>" /> <meta property="fb:app_id" content="2336522859986454" />

Try echo out somewhere in the body
<?php echo $_SERVER['REQUEST_URI']; ?>
If that produces anything but 1 or 2 or 3 or 4 then the when part will not work, i am worried yours might echo back something more like /test/test_fb.php?prod=1

Please send a screen of what that produces

The basic idea is this

The PDO $stmt part gets the result of the sql query, if your database column names are blue, pink, green, yellow then the contents of those column names will be placed in an array which in this case we called mySeoTags when you want to call back data from that array, then you have to it by its column name and nothing else.

So <?php echo $mySeoTags[blue]; ?> will give you the data from the blue column that matches the query.

In my case i was using the Wappler built in routing to get around the URLs being full of query parameters, for SEO purposes so it was fine for me to use $_SERVER['REQUEST_URI']; in your case that will not really work, you need the result of the query parameter.

I hope this makes sense, but for the where to work the data has to match, and i think yours is not.