when i run this code i get duplictae header $search=$_POST["search"]; $result = mysql_query("SELECT * FROM contacts WHERE firstname LIKE '%$search%' OR lastname LIKE '%$search%' OR email LIKE '%$search%' OR phone LIKE '%$search%'"); echo "<table>"; while($row=mysql_fetch_array($result)) { $firstname=$row["firstname"]; $lastname=$row["lastname"]; $email=$row["email"]; $phone=$row["phone"]; echo "<tr>FIRSTNAME<td>" . $firstname . "</td>LASTNAME<td>" . $lastname . "</td>EMAIL<td>" . $email . "</td>PHONE<td>" . $phone . "</td></tr>"; } ?> </p> <p> </p> </body> </html> FIRSTNAMELASTNAMEEMAILPHONEFIRSTNAMELASTNAMEEMAILPHONEFIRSTNAMELASTNAMEEMAILPHONEFIRSTNAMELASTNAMEEMAILPHONE collins smith 5555
I need to see the page on how it looks, then I can identify your problem But I think it is because you are not ending the table add this "</table>" below the loop
You cannot have text inside <table> and outside the <td> tags. Check the HTML specs for tables, your resulting markup is invalid.
You are generating completely invalid html, try this template: <table> <thead> <tr> <th>First Name</th> <th>Last name</th> <th>Email</th> <th>Phone</th> </tr> </thead> <tbody> [loop] <tr> <td><?= htmlspecialchars($firstname) ?></td> <td><?= htmlspecialchars($lastname) ?></td> <td><?= htmlspecialchars($email) ?></td> <td><?= htmlspecialchars($phone) ?></td> </tr> [end loop] </tbody> </table> Code (markup): Also, please note that I added in escaping of output using the htmlspecialchars() function. This prevents stray characters in your file names like < and > from breaking your HTML.
This should work <?php $search = $_POST["search"]; $result = mysql_query("SELECT * FROM contacts WHERE firstname LIKE '%$search%' OR lastname LIKE '%$search%' OR email LIKE '%$search%' OR phone LIKE '%$search%'"); echo "<table>"; // This is the table header echo "<tr><td>Firstname</td><td>Lastname</td><td>Email</td><td>Phone</td></tr>"; while($row=mysql_fetch_array($result)) { $firstname=$row["firstname"]; $lastname=$row["lastname"]; $email=$row["email"]; $phone=$row["phone"]; echo "<tr><td>" . $firstname . "</td><td>" . $lastname . "</td><td>" . $email . "</td><td>" . $phone . "</td></tr>"; } echo "</table>"; ?> </p> <p> </p> </body> </html> PHP: