PHP script in html

I am trying to display mysql data in html

table format

table name :: App

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

// mysql query

  <?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 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 not getting mysql data in html file

will someone help me in the right decision

+4
source share
3 answers

It’s good that two things can happen here.

  • You need to collapse any PHP code with opening and closing PHP tags - <?php ?> . This includes single variables, for example, with row[4] . You will also need to drop the variable -

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

  • Make sure the HTML file has a .php file extension. Another reasonable server will simply not parse the file as PHP, and your code will not execute as PHP, but rather as plain text. You can configure the server to parse PHP even in HTML files - sometimes this is done for security measures so that users don’t know what technologies are used on the server (but I'm not sure if this is what you are going to do here)

+4
source

You can print the value of variables like this:

 <div style="text-align:left"><p>App:<b><? echo $app . ' ' . $vesion ?></b></p></div> 
+4
source

Yes. You missed echo And try the following:

 <?php $query="SELECT * FROM `App` where appid=1"; $res=mysql_query($query); $row=mysql_fetch_array($res); $app=$row['app']; $vesion=$row['version']; ?> <a href="http://localhost/downloads/<?=$row['apk file']?>">Here</a> 

Use var_dump to check what you get from the database.

+1
source

Source: https://habr.com/ru/post/1437913/


All Articles