Katushai
Katushai

Reputation: 1520

MySQL returning blank rows that contain HTML

I'm working on a website and it has a table in MySQL that contains HTML for a couple of the rows. Every time I try to pull the data from the table, it returns "" for the rows containing HTML. The other rows, the ones without HTML, return the correct data. I escaped all double and single quotes, and the entire row is on a single line (no line breaks). I've been trying to solve the problem for a while now, and I can't figure it out. Any ideas?

<?php

$con = mysqli_connect('localhost', 'exampleuser', 'examplepass', 'exampledb');
if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$query = "SELECT * FROM Publications;";
$result = mysqli_query($con, $query);

while ($row = mysqli_fetch_row($result)) {
    echo "\n<br>\"" . $row['Publications'] . "\"\n<br>";
}

?>

The HTML I'm putting in is very long so ill just paste the first section. Remember, no line breaks in the HTML. I just put them in so its easier to read.

<p class="MsoTitle"><span style="font-size: 12pt;">Publications</span><span style="font-
size: 12pt; font-weight: normal;"></span></p><p class="MsoNormal"><strong>
<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></strong></p><p class="MsoNormal" 
style="margin-left: 0.25in; text-indent: -0.25in;">1. <strong><span style="font-weight: 
normal;">C. V. Krishnan and M. Garnett, Electrochemical Behavior of the Super Antioxidant, 
&alpha;-</span></strong></p><p class="MsoNormal" style="margin-left: 0.25in; text-indent: 
-0.25in;"><strong><span style="font-weight: 

And this is what's returned:

""

Upvotes: 1

Views: 133

Answers (1)

Funk Forty Niner
Funk Forty Niner

Reputation: 74217

As per comments exchanged between you and I. (to close the question)

Notice: Undefined index: Publications in /home/garnett/public_html/test.php on line 14

This stems from your column being named publications and not Publications.

$row['Publications'] and $row['publications'] are two different animals altogether.

The column name is case-sensitive, and that is why you are not getting any data outputted.

Using error reporting at the top of your files, will reveal potential errors, if any are ever found in your code, as you have from a suggestive comment.

error_reporting(E_ALL);
ini_set('display_errors', 1);

Edit:

As noted by E-Rock in a comment:

"mysqli_fetch_row() returns an enumerated array of row data. You want mysqli_fetch_assoc() if you're expecting an associative array". Thanks E-Rock.

Upvotes: 1

Related Questions