Jump to content

Code works but not embedded in .html file


FreakingOUT
Go to solution Solved by FreakingOUT,

Recommended Posts

PHP = 5.5.14

MySQL = 5.2.17

 

This simple .php script works as a standalone OK:

<?php

require '<snip partial URL>mysqli.php';

// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$result = mysqli_query($con,"SELECT `callsign`, `qth`, `submitted` FROM `lqplogs` ORDER BY `callsign`");

echo "<table>
<tr>
<th><u>CALLSIGN</u></th><th><u>QTH</u></th><th><u>LOG SUBMITTED</u></th>
</tr>";


while($row = mysqli_fetch_array($result)) {
  echo "<tr>";
  echo "<td>" . $row['callsign'] . "</td>";
  echo "<td>" . $row['qth'] . "</td>";
  echo "<td>" . $row['submitted'] . "</td>";
  echo "</tr>";
}

echo "</table>";

mysqli_close($con);
?>

A separate .html page with other info works by itself OK too, but when I try to embed the PHP script (with PHP start & end tags, of course)  *between* these HTML tags:

 

<table>

<tr>

<td>

 

... Full PHP Script Embedded here...

 

</td>

</tr>

</table>

 

I get this mess:

"; while($row = mysqli_fetch_array($result)) { echo ""; echo ""; echo ""; echo ""; echo ""; } echo "
CALLSIGN	QTH	LOG SUBMITTED
" . $row['callsign'] . "	" . $row['qth'] . "	" . $row['submitted'] . "
"; mysqli_close($con); ?> 

Any thoughts as to why are appreciated.

 

Thanks!

 

- FreakingOUT

 

 

Link to comment
Share on other sites

P.S.

 

I also tried embedding the PHP script WITHOUT the other <table> structure in the .html file, and get this:

CALLSIGNQTHLOG SUBMITTED "; while($row = mysqli_fetch_array($result)) { echo ""; echo "" . $row['callsign'] . ""; echo "" . $row['qth'] . ""; echo "" . $row['submitted'] . ""; echo ""; } echo ""; mysqli_close($con); ?> 

Ugh ;-(

 

- FreakingOUT

Link to comment
Share on other sites

  • Solution

.html is not parsed by PHP. You have to name your file with a .php for it to work.

 

Yes, I checked the page source and then thought *maybe* I needed to put the (require '<snip partial URL>mysqli.php';) statement at the front starting with the PHP tags and ending the page with the PHP tags.

 

It worked!  I had mistakenly assumed that the PHP code (encapsulated in the PHP tags) inside the HTML would work.  Another "Senior Moment", as now recall having done things this way in the past.  My  bad ;-(

 

Thanks for the reminder as well.

 

- FreakingOUT

Link to comment
Share on other sites

also, the require statement for your database connection mysqli.php file ISN'T a URL, that's a file system path. URLs (that are used by browsers to request pages on a web server) are not the same thing as file system paths (that are used by php on the server to read files.)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.