PDO connection if you prefer not to use a prerender service

I have tried but have no results

What URL did you try on

<?php echo $_SERVER['REQUEST_URL']; ?>

Sorry I had edited it, the last L should be an I like
<?php echo $_SERVER['REQUEST_URI']; ?>

Now with this code the result is
Schermata 2020-07-10 alle 01.10.19

Ok so it makes sense why it does not work because your mysql is asking in the where part if 2 is equal to 2, but in your case it is not, in your case 2 = /test/test_fb.php?idprod=2 which is not correct.

By changing you first line you have fixed that with swapping this code <?php $prod = 'https://www.vacanzemarine.it'.$_SERVER['REQUEST_URL']; to $idprod = $ _GET [idprod]; and the SELECT query to WHERE IDProd = '$idprod' so now 2 does equal 2

So now you have overcome the first problem, the next issue is working out why facebook is unhappy, when i inspect your page id do see one issue
There are 2 instances of the meta title

However when i test in facebook it does look ok

The only error left is that 500 response code, which i think is just an incorrect path to either bootstrap.css in the head or popper.min.js/bootstrap.min.js in your body. Check the paths are correct and the files are uploaded to the remote testing server and it should go away.

1 Like

We have come to a good point thanks to you
Tomorrow morning I will try to understand where this facebook error is generated
Then I’ll have to bring it all back to the real site, hoping not to encounter any conflict with Wappler’s settings
Tomorrow I’ll let you know, because now it’s almost 2 in the morning
Thanks for the help

Hello Paul
I fixed everything, both for the test page and especially for the page of the site that needed the correct functioning of the FB sharing
At the end of the connection code I created the variables for all the meta tags and then after checking their operation, I inserted them in the various contents.
Also for og: url I created a variable with the complete address of the page, including the variable condition …? Idprod = …
And now everything works without any errors or reports from the Facebook Debugger
Thank you very much for your valuable help which has allowed me to overcome this obstacle

1 Like

Question, how would I display particular column content defined by another column integer? For example, my page_content table looks like:

page_id page_location page_data
1 1 Welcome to our Website
1 2 Some page paragraph text here…
1 3 …/img/src/dog.jpg
2 1 About Us

In my SQL statement I use a WHERE clause to select the page_id in the first column. So far so good.

try {
		$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
		$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

		$stmt = $conn->prepare("SELECT * FROM page_content WHERE page_id = '1'");
		
		$stmt->execute();
		$myPageTags = $stmt->fetchAll();
	}
	catch(PDOException $e) {
		echo "Connection failed: " . $e->getMessage();
	}

As I’ve changed to a fetchAll statement, columns are returned as an array and I can choose to display a particular column (page_data) by its index:

<h1><?php echo $myPageTags[0][page_data] ?></h1>

or

<img src="<?php echo $myPageTags[2][page_data] ?>" >

Again this works fine, however, I'd much rather be able to select the column (page_data) by the integer in the page_location column. So in my head it would be something like:
<?php if($myPageTags[page_location] == '2') { echo '$myPageTags[page_data]'; } ?>"

But obviously this is the wrong syntax. Could anyone point me in the right direction?

I think you need to loop through the array using foreach. Then within the loop you can do the conditional part. Something like…

foreach($myPageTags as $tags) {
  if($tags['page_location'] == 2){
echo $tags['page_data'];
 }
}
1 Like

Perfect, thanks Ben. I thought I might have to loop through the records, works perfectly.

Do you know if this would cause an overhead if this condition was repeated say 20 times on a page?

Everything has an overhead but this should be very little (assuming you weren’t looping through hundreds/thousands of records in each of the places)

1 Like

Question:
How do I put the url query params here?
When I put the a static number. It works. But table is filtered based on the url (id). So, I need to have the id from the query parameter there.

Thank you