Struggling to create a basic CMS using PHP and MySQL, unable to successfully display the data

My latest project involves creating a basic CMS for a website. This is my first time working with MySQL and one of my early experiences with PHP, so I see it as a learning opportunity. Despite consulting numerous resources, the code I've written only results in displaying an empty <h1></h1> tag. I've double-checked all aspects of my database and table setup, ensuring that the column names are correct. At this stage, I'm not attempting to add anything to the database; I simply want to be able to read from it. Even a simple proof-of-concept seems out of reach at the moment.

For hosting, I've opted for 000webhost.

<?php
$mysql_host = "****";
$mysql_database = "****";
$mysql_user = "sql_blog";
$mysql_password = "*****";

$link = mysql_connect($mysql_host, $mysql_user, $mysql_password);

if (!mysql_select_db($mysql_database, $link)) {
echo 'Database error';
exit;
}

$sql_statement = ('SELECT * FROM Blog_Entries');
$result = mysql_query($sql_statement);
while ($curr_row = mysql_fetch_assoc($result)) {
  echo '<h1>' . $result['Title'] . '</h1>';
}
mysql_free_result($result);
?>

I borrowed most of this code from , and everything appears to be in order...

Answer №1

There is a mistake in your while loop.

 echo '<h1>' . $data['Title'] . '</h1>';

The correct way is

 echo '<h1>' . $current_row['Title'] . '</h1>';

Make sure to use the actual row when iterating through rows, not just the resultset pointer.

Answer №2

while ($curr_row = mysql_fetch_assoc($result)) {
  echo '<h1>' . $curr_row['Title'] . '</h1>';
}

Adjusting the code to:

while ($curr_row = mysql_fetch_assoc($result)) {
  echo '<h1>' . $curr_row['Title'] . '</h1>';
}

Answer №3

In order to make the necessary adjustment, you must

echo '<h1>' . $result['Title'] . '</h1>';

change it to

echo '<h1>' . $curr_row['Title'] . '</h1>';

The variable $result represents the entire result set retrieved by your query, while $curr_row specifically refers to the individual row extracted from that result set.

Answer №4

Modify

echo '<h1>' . $result['Title'] . '</h1>';

into

echo '<h1>' . $curr_row['Title'] . '</h1>';

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Laravel has encountered a delay in processing

After following the instructions in the official Laravel documentation, I successfully installed Laravel on my local machine using both Laravel Installer and composer. However, when I try to access the site from Chrome, I am greeted with an error message s ...

Retrieve the current user's local machine name on a wireless network using PHP

Attempting to obtain the user's machine name using: gethostbyaddr($_SERVER['REMOTE_ADDR']); However, only receiving the host name which is identical for all users in my wireless network. After conducting research online, some suggest it ...

Updating webpage links based on $_get parameters

Currently, I am using $_GET['base'] to determine the homepage that a user visits on my website. This results in either localhost/?base=administrator or localhost/?base=guest I am also using this method to control which page the user is currentl ...

gather remarks published by a Facebook Page

Is there a way to retrieve the comments made by a Facebook page, such as this one? The code provided only fetches general information. What format should the URL be to retrieve the comments specifically? $Page_ID = 'https://www.facebook.com/nauhote ...

Identify when an ajax request is completed in order to trigger a subsequent ajax request

Within my project, I am faced with a challenge involving select option groups that dynamically load ajax data based on previous selections. The issue arises when I attempt to replicate this functionality for another select option group. Here is the scenar ...

Retrieve data from MySQL by joining tables, applying specific conditions in the WHERE

I've encountered an issue where my queries, which used to perform well, are now slowing down as the tables they are querying continue to grow. The two tables I'm working with are: # Accounts table CREATE TABLE `account` ( `id` int(11) unsigne ...

Preventing line breaks (endline) from PHP variable when passing to JavaScript

Check out my code snippet below: <td onclick="openFile('<?php echo htmlentities ($row['name'])?>',' <?php echo htmlentities ($row['content'])?>')"> <a href="#nf" dat ...

Preventing Proxy Access on Webpages

Is there a way to detect proxies besides using User Agent or Google Analytics? Can we identify people using proxy bots to visit our site through JavaScript? I attempted to extract data from Google Analytics with gAPI, but making over 50,000 requests per d ...

I would like to display an error message in close proximity to my form

The controller function is shown below. In the addinvoices function, a checking function is called. If the condition is true, the page will be redirected to a view page; otherwise, it will stay on the same page and show an error message. $this->loa ...

After establishing the connection between Ajax and PHP with a relationship table, the inserted data is not being displayed

I am new to using Ajax and Php and have a question about inserting data into a Mysql table using Bootstrap Modal, Ajax, and Php. Currently, I have a table named "tbl_employee" and a page called "index.php." In the "index.php" page, there is a Bootstrap m ...

Displaying the product quantity counter in the shopping cart immediately after adding the item

My website has a shopping cart quantity counter that doesn't update immediately when a product is added. Instead, it requires a page reload or navigation to another page for the change to be reflected. I would like the quantity counter to show the pro ...

"Discover the trick to adding and updating text in a URL using jQuery without needing to refresh the page

I successfully implemented pagination in WordPress using Jquery/Ajax/wp_pagenavi(). It works well as it only refreshes a specific div to load new content instead of reloading the entire page. However, I am looking to enhance this feature by updating a port ...

Performing cross-origin GET request

I need help with a scenario involving a link and some JavaScript code. The setup is as follows: <a id="link" href="https://yahoo.com" target="blank">Link</a> Here is the script I'm using: var security = function() { var link ...

Efficiently overseeing the organization and administration of diverse visual content and

I am currently in the process of developing a massive web application. In this platform, users will have the capability to upload both images and music files onto my server. I am utilizing the PHP language with the Codeigniter framework, all managed throug ...

"Challenges Arising in Deciphering a Basic JSON Array

After countless attempts, I am still struggling to solve this issue. My PHP code is functioning properly, as it returns the expected data when "Grove Bow" is selected from the dropdown menu: [{"wtype":"Grove Bow","was":"1.55","wcc":"5","wbdmin":"12","wbdm ...

Issue with saving file name in database when uploading files using ajax

Whenever I try to use $filename in the code below, I am unable to successfully store anything in the database. I attempted using the basename function but unfortunately, it did not resolve the issue. $filename = $_FILES['file']['nam ...

The fatal error encountered was completely unexpected: an Uncaught UnexpectedValueException was thrown due to the server returning an unprecedented value. The anticipated response was "HTTP/1.1 101", but instead, an

I am completely new to using socketIO and elephantIO. Currently, I'm attempting to emit data from a PHP file called "emit_test.php" to a node server. Here's the code snippet I've been working with: ini_set("display_errors",5); include ("v ...

I am looking to show images based on the number chosen from the dropdown menu in CodeIgniter

When a number is selected from the dropdown menu, I want to display images accordingly. The options in the dropdown are 9, 12, and 18. Here is the code snippet for my view page: <form action="<?php echo base_url();?>roxcontrol/numberdisplay" id=" ...

The PDO MySQL error HY093 was thrown due to an incorrect number of parameters being passed

Encountering an HY093 (Parameter count mismatch) SQLSTATE error on a query that seems to have the correct number of parameters. Here is a complete PHP script to reproduce the issue. (Remember to update the database credentials.) The SELECT statement conta ...

The fetch function in React Native seems to be malfunctioning

I am attempting to retrieve data from a PHP API, here is the code for the API: <?php if(!empty($_POST)){ $array = ["name" => "vasu" ,"json" => "created at 2021"]; print_r(json_encode($array)); ...