How can I add an Sql Query in the middle of HTML code?

196
December 23, 2016, at 5:04 PM

I want to make a login system, where the user can see all the messages he has received. In my database the insurance_company is the username and that is what I want it to show by. Here is my code. How do I fix it? - Thanks Prem

<?php
  $strSQL = "SELECT * FROM claims WHERE insurance_company = $_SESSION['user']";

  $rs = mysql_query($strSQL);

  while($row = mysql_fetch_array($rs)) {
    echo $row['Claim'] . "<br />";
    }

?>
Answer 1

PHP code can be written anywhere in HTML code. You need to just place your PHP code between tags. As you can see in the example bellow I have used php code between p tags.

<?php
    $strSQL = "SELECT * FROM claims WHERE insurance_company = $_SESSION['user']";
    $rs = mysql_query($strSQL);
    while($row = mysql_fetch_array($rs)) {?>
        <p> <?php echo $row['Claim'] . "<br />"; ?> <p>
    <?php }
?>
Answer 2

If you want it to show insurance_company, you must echo this value in the response array:

echo $row['insurance_company']
READ ALSO
laravel routing issue with domain

laravel routing issue with domain

I am using laravel version 51

219
Is this good practice for prevent user without login to access this page? and about querystring

Is this good practice for prevent user without login to access this page? and about querystring

Assume that I have a page for read cartoon in website and user that does not login cannot read this pageand my cartoon has many title and each title has many episodes

183
How to keep CodIgniter application and config in their own in git repos?

How to keep CodIgniter application and config in their own in git repos?

Can anybody tell me what kind of workflow should I follow to keep my application source and configuration tracked in Git? I want to keep my config separate from my source is because there is one config for development, another for production enviroment...

168