Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php script in html

Tags:

html

php

mysql

i am trying to display mysql data in html

table format is

table name:: App

   appid |    app    | version |     date     |      apk file   |
   1        sample     1.0.0      2012-10-12         sample.apk

//mysql query is

   <?php
    $query="SELECT * FROM `App` where appid=1";
    $res=mysql_query($query);
    $row=mysql_fetch_row($res);
    $app=$row[1];
    $vesion=$row[2];
    $date1=date('M j,Y',strtotime($row[3]));
 ?>

//html code is given below

 <html>
     <body>
      <div style="text-align:left"><p>App:<b><? $app.' '.$vesion ?></b></p></div>
      <div style="text-align:left"><p>Date Uploaded: <b><? $date1 ?></b></p></div>
      <ol class="instructions">
         <li>Click <a href="http://localhost/downloads/$row[4]">Here</a> todownload.
 <br></li>

     </ol>
     </body>
     </html>
<?php 

?>

but do not getting mysql data in html file

any one help me for correct solution

like image 714
VSK Avatar asked Jan 15 '23 09:01

VSK


1 Answers

Ok so two things may be happening here.

  1. You need to wrap any PHP code with the opening and closing PHP tags - <?php ?>. This includes single variables like you did with row[4]. You'll also need to echo out the variable -

    <a href="http://localhost/downloads/<?php echo $row[4]; ?>">Here</a>

  2. Make sure you HTML file has the .php file extension. Other wise the server will simply not parse the file as PHP and your code will not be executed as PHP but rather as plain text. You can setup your server to parse PHP even in HTML files - this is done sometimes for security measures as to not let users know what technologies are being used on the server (but I'm not sure if that's what you are going for here).

like image 178
Lix Avatar answered Jan 24 '23 22:01

Lix