[php] php & mysql query not echoing in html with tags?

<?php require 'db.php'; ?>  <?php if (isset($_POST['search'])) { $limit = $_POST['limit']; $country = $_POST['country']; $state = $_POST['state']; $city = $_POST['city']; $data = mysqli_query($link,"SELECT * FROM proxies WHERE country = '{$country}' AND state = '{$state}' AND city = '{$city}' LIMIT {$limit}"); while( $assoc = mysqli_fetch_assoc($data)){ $proxy = $assoc['proxy']; echo '<<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Sock5Proxies</title> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <link href="./style.css" rel="stylesheet" type="text/css" /> <link href="./buttons.css" rel="stylesheet" type="text/css" /> </head> <center> <h1>Sock5Proxies</h1> </center> <body> <div id="wrapper">     <div id="header">         <ul id="nav">            <li class="active"><a href="index.html"><span></span>Home</a></li>             <li><a href="leads.html"><span></span>Leads</a></li>             <li><a href="payout.php"><span></span>Pay out</a></li>             <li><a href="contact.html"><span></span>Contact</a></li>             <li><a href="logout.php"><span></span>Logout</a></li>         </ul>     </div>     <div id="content">         <div id="center">             <table cellpadding="0" cellspacing="0" style="width:690px">                 <thead>                     <tr>                         <th width="75" class="first">Proxy</th>                         <th width="50" class="last">Status</th>                     </tr>                 </thead>                 <tbody>                     <tr class="rowB">                         <td class="first"> <?php echo $proxy ?> </td>                         <td class="last">Check</td>                     </tr>                 </tbody>             </table>         </div>     </div>     </center>     </center>     <div id="footer"></div>     <span id="about">Version 1.0</span> </div>  </body> </html>'; } } ?> <html> <form action="" method="POST"> <input type="text" name="limit" placeholder="10"/><br> <input type="text" name="country" placeholder="Country"/><br> <input type="text" name="state" placeholder="State"/><br> <input type="text" name="city" placeholder="City"/><br> <input type="submit" name="search" value="Search" /><br> </form> </html> 

I'm receiving no errors now on line 47, this is supposed to be printing out my query, it works without the html & styling, before you ask yes the theme does work, as of style.css.

This question is related to php

The answer is


Change <?php echo $proxy ?> to ' . $proxy . '.

You use <?php when you're outputting HTML by leaving PHP mode with ?>. When you using echo, you have to use concatenation, or wrap your string in double quotes and use interpolation.


<td class="first"> <?php echo $proxy ?> </td> is inside a literal string that you are echoing. End the string, or concatenate it correctly:

<td class="first">' . $proxy . '</td>


I can spot a few different problems with this. However, in the interest of time, try this chunk of code instead:

<?php require 'db.php'; ?>  <?php if (isset($_POST['search'])) {     $limit = $_POST['limit'];     $country = $_POST['country'];     $state = $_POST['state'];     $city = $_POST['city'];     $data = mysqli_query(         $link,         "SELECT * FROM proxies WHERE country = '{$country}' AND state = '{$state}' AND city = '{$city}' LIMIT {$limit}"     );     while ($assoc = mysqli_fetch_assoc($data)) {         $proxy = $assoc['proxy'];         ?>             <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"                 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">             <html xmlns="http://www.w3.org/1999/xhtml">                 <head>                     <title>Sock5Proxies</title>                     <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />                     <link href="./style.css" rel="stylesheet" type="text/css" />                     <link href="./buttons.css" rel="stylesheet" type="text/css" />                 </head>                 <body>                     <center>                         <h1>Sock5Proxies</h1>                     </center>                     <div id="wrapper">                         <div id="header">                             <ul id="nav">                                 <li class="active"><a href="index.html"><span></span>Home</a></li>                                 <li><a href="leads.html"><span></span>Leads</a></li>                                 <li><a href="payout.php"><span></span>Pay out</a></li>                                 <li><a href="contact.html"><span></span>Contact</a></li>                                 <li><a href="logout.php"><span></span>Logout</a></li>                             </ul>                         </div>                         <div id="content">                             <div id="center">                                 <table cellpadding="0" cellspacing="0" style="width:690px">                                     <thead>                                     <tr>                                         <th width="75" class="first">Proxy</th>                                         <th width="50" class="last">Status</th>                                     </tr>                                     </thead>                                     <tbody>                                     <tr class="rowB">                                         <td class="first"> <?php echo $proxy ?> </td>                                         <td class="last">Check</td>                                     </tr>                                     </tbody>                                 </table>                             </div>                         </div>                         <div id="footer"></div>                         <span id="about">Version 1.0</span>                     </div>                 </body>             </html>         <?php     } } ?> <html> <form action="" method="POST">     <input type="text" name="limit" placeholder="10" /><br>     <input type="text" name="country" placeholder="Country" /><br>     <input type="text" name="state" placeholder="State" /><br>     <input type="text" name="city" placeholder="City" /><br>     <input type="submit" name="search" value="Search" /><br> </form> </html> 

You need to append your variables to the echoed string. For example:

echo 'This is a string '.$PHPvariable.' and this is more string';