Display url in div?

Here’s the problem.

I got two php pages.
Both pages got two divs, one left, one right.
The left div contains urls. It’s bascially a list of urls that points to text in the database.
The right div is used for displaying content.

When you click an url in the left div on the first page, it’s supposed to fetch some text from the database and display it in the right div in the second page.
I figured out how do do this many years ago (Maybe I’m getting to old (64 this year)), but when I upgraded my CMS I also had to upgrade the PHP-version and all code hell broke ut.

This is how far I’ve got. This code is on the index page and connects to the database, and it selects some information from the database and converts it into urls.

$host = "localhost";<br>
$username = "xxxxxxxxxx";<br>
$password = "xxxxxxxxxx";<br>
$dbname = 'xxxxxxxxx';<br>

$conn = mysqli_connect($servername, $username, $password, $dbname);<br>
// Check connection<br>
if (!$conn) {<br>
  die("Connection failed: " . mysqli_connect_error());<br>
	echo "ok";<br>
$sql = "SELECT id, title, author, source, text FROM yyyyyyyy";<br>
$result = mysqli_query($conn, $sql);<br>
while($row = mysqli_fetch_array($result))<br>
echo("<a href=\"read.php?id=" . $row[0] . "\">" . $row[1] . "</a>  " . $row[2] . "<br />");

The urls looks fine, but when I click an url on the index page it gives me a white read.php page.
What am I doing wrong?
All input is appreciated!

Did you make changes to accommodate the change, and that caused the problems, or are the problems a result of the new version, before making changes?

That suggests that the code you show here “works”, if the URLs are as they should be.
But the problem is in the read.php file, if it is that which is not displaying properly.

I take it all those <br> tags are from some kind of copy/paste issue into the forum, not actually present in the code?

1 Like

I used Drupal 7 and upgraded to version 9. That meant I had to upgrade PHP from 5 to seven. msql_connect had to be replaced by msqli_connect. That’s basically it.
Yes, I think you are correct. The problem is the second php file. But I cannot figure out what to put in it.

Yes. I just wanted to make it readable.

When you post code on the forums, you need to format it so it will display correctly.

You can highlight your code, then use the </> button in the editor window, or you can place three backticks ``` (top left key on US/UK keyboards) on a line above your code, and three on a line below your code. I find this approach easier, but unfortunately some European and other keyboards don’t have that character.

(I formatted the code above for you.)

Thank you, this is my first post in this forum so I am not sure how to do things.

1 Like

Note that migrating from mysql to mysqli can be more than just adding the “i” into the functions.
Some (equivalent) functions are named a bit differently, so that is something to watch out for.
Though if the URLs are being built correctly, it seems those DB functions are working.

We will need to see the code you have so far for that.
As a guess from your URL, it is a case of selecting a row by its ID.
Moving from mysql a big difference in how you will do that now, is the use of prepared statements, a more modern and secure way of doing things.

Thank you for taking time.
Now the mystery deepens.
The second file is a copy of the first file. No wonder it does not do anything, I guess. The only thing it got is the list of urls in the left div. And that list should be there.
I cleared the browser cache and updated both pages and now I am not getting a white page, instead Drupal sends me straight to the sites home page (index.php).
So I guess that means that what I have done so far is creating the url list, nothing more?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.