Start tag em seen in table - php

I am coding php and seen this error while I trying to do a HTM5 validator. But the things is there is no in my whole file. Any suggestions what is wrong here?
Error Line 27, Column 4: Start tag em seen in table.
<em><br />
Edit note : I rarely want to add this code here due to the fact that's it is long and have nothing to do with the error (like I said above, there is no tag in the html)
<section>
<table>
<?php
include("./settings.php");
$conn = #mysqli_connect($host, $user, $pwd, $sql_db);
if (!$conn) {
echo "<p>Databse connection error</p>";
} else {
$eoinumber = trim($_POST["num"]);
$lname = trim($_POST["lname"]);
$query = "SELECT * FROM eoi WHERE EOInumber = $eoinumber AND lname = '$lname'";
$result = mysqli_query($conn,$query);
if (!$result) {
echo "<p>There is something wrong with the $query</p>";
} else {
$temp = mysqli_num_rows($result);
if ($temp == 0) {?>
<p>0 enquiry found. Please check again your EOInumber and last name</p>
<?php } else {
?>
<thead>
<tr>
<th>EOI number</th>
<th>Job ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Date of Birth</th>
<th>Gender</th>
<th>Street</th>
<th>Town</th>
<th>State</th>
<th>Postcode</th>
<th>Mail</th>
<th>Telephone</th>
<th>Skills</th>
<th>Other Skills</th>
</tr>
</thead>
<?php
while ($row = mysqli_fetch_assoc($result)) {
echo "<tbody>";
echo "<tr>";
echo "<td>",$row["EOInumber"],"</td>";
echo "<td>",$row["job_num"],"</td>";
echo "<td>",$row["fname"],"</td>";
echo "<td>",$row["lname"],"</td>";
echo "<td>",$row["bday"],"</td>";
echo "<td>",$row["gender"],"</td>";
echo "<td>",$row["street"],"</td>";
echo "<td>",$row["town"],"</td>";
echo "<td>",$row["state"],"</td>";
echo "<td>",$row["postcode"],"</td>";
echo "<td>",$row["mail"],"</td>";
echo "<td>",$row["tele"],"</td>";
echo "<td>",$row["skill"],"</td>";
echo "<td>",$row["other"],"</td>";
echo "</tr>";
echo "</tbody>";
// echo "<p>Sucess</p>";
}
?>
</table>

Regardless of the presence or otherwise of the <em> tag, you are going to run into problems because you are opening the table tag and then potentially putting a <p> or other elements directly inside it, which is illegal (you can put <thead>, <tbody>, <caption>, <tr>, <tfoot> elements inside a <table>). It would be better if you opened the table after checking whether the queries had run successfully or not, i.e.:
<section>
<?php
include("./settings.php");
$conn = #mysqli_connect($host, $user, $pwd, $sql_db);
if (!$conn) {
echo "<p>Databse connection error</p>";
} else {
$eoinumber = trim($_POST["num"]);
$lname = trim($_POST["lname"]);
$query = "SELECT * FROM eoi WHERE EOInumber = $eoinumber AND lname = '$lname'";
$result = mysqli_query($conn,$query);
if (!$result) {
echo "<p>There is something wrong with the $query</p>";
} else {
$temp = mysqli_num_rows($result);
if ($temp == 0) {
echo "<p>0 enquiry found. Please check again your EOInumber and last name</p>";
} else {
echo "<table>";
... echo the table header...
while ($row = mysqli_fetch_assoc($result)) {
... echo table results...
}
echo "</table>";
}
}
?>

You missed a few }
So this should work:
<section>
<table>
<?php
include("./settings.php");
$conn = #mysqli_connect($host, $user, $pwd, $sql_db);
if (!$conn) {
echo "<p>Databse connection error</p>";
exit;
}
$eoinumber = trim($_POST["num"]);
$lname = trim($_POST["lname"]);
$query = "SELECT * FROM eoi WHERE EOInumber = $eoinumber AND lname = '$lname'";
$result = mysqli_query($conn,$query);
if (!$result) {
echo "<p>There is something wrong with the $query</p>";
exit;
} else {
$temp = mysqli_num_rows($result);
}
if ($temp == 0) { ?>
<p>0 enquiry found. Please check again your EOInumber and last name</p>
<?php } else { ?>
<thead>
<tr>
<th>EOI number</th>
<th>Job ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Date of Birth</th>
<th>Gender</th>
<th>Street</th>
<th>Town</th>
<th>State</th>
<th>Postcode</th>
<th>Mail</th>
<th>Telephone</th>
<th>Skills</th>
<th>Other Skills</th>
</tr>
</thead>
<?php
while ($row = mysqli_fetch_assoc($result)) {
echo "<tbody>";
echo "<tr>";
echo "<td>",$row["EOInumber"],"</td>";
echo "<td>",$row["job_num"],"</td>";
echo "<td>",$row["fname"],"</td>";
echo "<td>",$row["lname"],"</td>";
echo "<td>",$row["bday"],"</td>";
echo "<td>",$row["gender"],"</td>";
echo "<td>",$row["street"],"</td>";
echo "<td>",$row["town"],"</td>";
echo "<td>",$row["state"],"</td>";
echo "<td>",$row["postcode"],"</td>";
echo "<td>",$row["mail"],"</td>";
echo "<td>",$row["tele"],"</td>";
echo "<td>",$row["skill"],"</td>";
echo "<td>",$row["other"],"</td>";
echo "</tr>";
echo "</tbody>";
// echo "<p>Sucess</p>";
}
}
?>
</table>
<!--...-->

Related

Search Results display

i have a website project, where customers will need to search and the results will display, so i have done all that, but the problem is when a search results comes up,if there's more than 1 row,it dublicate the results on the same row,here are the code.
<h1 style="font-family:calibri;color:#13CC0D;text-align:center;">BODABODA SEARCH RESULTS</h1>
<table cellpadding="1" cellspacing="1" id="resultTable">
<thead>
<tr>
<th style="border-left: 1px solid #C1DAD7"> Region</th>
<th> District </th>
<th> Ward </th>
<th> Street</th>
<th> Driver Name </th>
<th>Identification Type</th>
<th>Identification Number</th>
<th>Motorcycle Type</th>
<th>Motorcycle Reg No</th>
<th>Phone Number</th>
</tr>
</thead>
<?php
$conn = mysqli_connect('localhost', 'efalococ_calcia', '*ad4#zNQ=nfN') or die('can not connect to the server'.mysqli_error);
mysqli_select_db($conn, 'efalococ_safirii');
if(isset($_POST['search'])){
$query = $_POST['region'];
$query1 = $_POST['district'];
$query2 = $_POST['ward'];
$query3 = $_POST['street'];
$results = mysqli_query($conn,"SELECT * FROM bodaboda WHERE (`region` LIKE '%".$query."%') && (`district` LIKE '%".$query1."%') && (`ward` LIKE '%".$query2."%') && (`street` LIKE '%".$query3."%')") or die(mysql_error());
if(mysqli_num_rows($results) >0){
while($row = mysqli_fetch_array($results)){
echo "<td>".$row['Region']."</td>" ;
echo "<td>".$row['District']."</td>";
echo "<td>".$row['Ward']."</td>";
echo "<td>".$row['Street']."</td>";
echo "<td>".$row['DriverName']."</td>";
echo "<td>".$row['IdentificationType']."</td>";
echo "<td>".$row['IdentificationNumber']."</td>";
echo "<td>".$row['MotorcycleType']."</td>";
echo "<td>".$row['MotorcycleRegNo']."</td>";
echo "<td>".$row['PhoneNumber']."</td>";
}
}else{
echo '<span style="color:red;font-family:cursive;font-size:14px;">No results found, Please Modify your search </span> Click here'.mysqli_error($conn);
}
}
?>
</table>
And the results shows like this!
Can you please help on that? any idea?
You just need to use the <tr> for every row.
The tag defines a row in an HTML table.
Learn more about HTML tr tag
while($row = mysqli_fetch_array($results)) {
echo "<tr>";
echo "<td>".$row['Region']."</td>" ;
echo "<td>".$row['District']."</td>";
echo "<td>".$row['Ward']."</td>";
echo "<td>".$row['Street']."</td>";
echo "<td>".$row['DriverName']."</td>";
echo "<td>".$row['IdentificationType']."</td>";
echo "<td>".$row['IdentificationNumber']."</td>";
echo "<td>".$row['MotorcycleType']."</td>";
echo "<td>".$row['MotorcycleRegNo']."</td>";
echo "<td>".$row['PhoneNumber']."</td>";
echo "</tr>";
}

Displaying data in tables depending on group

I have a question in relation to displaying PHP tables that should be straight forward but I cannot get my head around it at the moment so any help would be appreciated, basically what I want to do is display a team of players in a table, but display multiple tables of users with their team name display above it.
What I currently have : http://puu.sh/ilUJp/4a6ae5e47b.png
What I am looking to achieve : http://puu.sh/ilUJ8/7756033517.png
<div class="col-lg-6">
<h3>Team Name Goes Here </h3>
<?php
echo "<table class='table table-striped'>";
echo " <thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>
</thead>
";
while($row = mysqli_fetch_array($result)) {
$teamName = $row['teamName'];
$fName = $row['firstName'];
$surName = $row['surName'];
echo "
<tbody>
<tr>
<td>$teamName</td>
<td>$fName</td>
<td>$surName</td>
</tr>
</tbody>
";
}
echo "</table>";
?>
</div>
with my query :
$sql = "SELECT t.teamID,t.teamName,u.firstName,u.surName From users as u INNER JOIN team as t where u.teamID = t.teamID ";
I know the idea I need to do but cannot get it done, so any help would be appreciated.
Try this code
<?php $teemid=array();
while($row = mysqli_fetch_array($result)) {
if(!in_array($row['teamID'],$teemid)){
array_push($teemid,$row['teamID']);
if(!empty($teemid)){ ?>
</tbody>
</table>
</div>
<?php }
?>
<div class="col-lg-6">
<h3><?php echo $row['teamName']; ?></h3>
<table class='table table-striped'>
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<?php } ?>
<tr>
<td><?php echo $row['teamName']; ?></td>
<td><?php echo $row['firstName']; ?></td>
<td><?php echo $row['surName']; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
SQL Query Change as below
$sql = "SELECT t.teamID,t.teamName,u.firstName,u.surName From users as u INNER JOIN team as t where u.teamID = t.teamID ORDER BY u.teamID";
You can do this logic
$teams = "get all teams sql query";
while ($row = mysqli_fetch_array($teams)) {
$teamid = $row['teamid'];
$teamname = $row['teamname'];
$teammemberquery = "select all member in the where team = $teamid sql query";
echo "<table>";
while ($r = mysqli_fetch_array($teammemberquery)) {
$teamName = $r['teamName'];
$fName = $r['firstName'];
$surName = $r['surName'];
echo "
<tbody>
<tr>
<td>$teamName</td>
<td>$fName</td>
<td>$surName</td>
</tr>
</tbody>
";
}
echo "</table>";
}
Try as below (Please replace table column name as yours and mysql to mysqli):
<?php
$link = mysql_connect('localhost', 'root', 'root');
$db_selected = mysql_select_db('test', $link);
$sql = "SELECT t.team_id,t.team,u.fname,u.lname,u.email From users as u INNER JOIN team as t where u.team_id = t.team_id order by t.team_id ";
$result = mysql_query($sql);
?>
<html><head><title>team</title></head><body><div class="col-lg-6">
<?php
echo "<table>";
$teamName = "";
$i=0;
while($row = mysql_fetch_array($result))
{
if($teamName == "" || $teamName != $row['team'])
{
if($i!=0)
echo "</table>";
echo "<tr><td colspan='3'><h3>".$row['team']."</h3></td></tr>";
$teamName = $row['team'];
$i=0;
}
$fName = $row['fname'];
$surName = $row['lname'];
$email = $row['email'];
if($i==0)
{
echo "<table class='table table-striped'><tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>";
}
echo "<tr>
<td>$fName</td>
<td>$surName</td>
<td>$email</td>
</tr>";
$i++;
}
echo "</table>";
?>
</div></body></html>

Don't display if no records exist in mysql

I have this form to search names in mysql database
<form action="search.php" method="GET">
<input type="text" placeholder="Search" name="name">
<input type="submit" value="Search">
this is the search.php
<?php
name = $_GET['name'];
require_once("connect.php");
$records = $connect->query("SELECT * FROM Userlists WHERE Name = '$name'");
echo
"<table>
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Description</th>
</tr>
</thead>
<tbody>";
if (mysqli_num_rows($records)== 0){
echo "No data available for that name specified";
}
else {
while($row=mysqli_fetch_array($records)) {
$name = $row['Name'];
$email = $row['Email'];
$desc = $row['Desc'];
echo
"<tr>
<td>".$name."</td>
<td>".$email."</td>
<td>".$desc."</td>
</tr>";
}
}
echo
"</tbody>
</table>";
?>
so there is no problems when I search for a name that exists in database it displays correctly, but the problem comes when I search for a name that doesn't exist in database.. I want it to display only
"No data available for that name specified" for the output but I will also see empty table in the output like this ------------> IMAGE..
so how can I get rid of the empty table for the output?
Just pu the if outside the table....
<?php
name = $_GET['name'];
require_once("connect.php");
$records = $connect->query("SELECT * FROM Userlists WHERE Name = '$name'");
if (mysqli_num_rows($records)== 0){
echo "No data available for that name specified";
} else {
echo
"<table>
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Desc</th>
</tr>
</thead>
<tbody>";
while($row=mysqli_fetch_array($records)) {
$name = $row['Name'];
$email = $row['Email'];
$desc = $row['Desc'];
echo
"<tr>
<td>".$name."</td>
<td>".$email."</td>
<td>".$desc."</td>
</tr>";
}
echo
"</tbody>
</table>";
}
?>
change your if clause as below and remember to add exit() or die() function,this will end your php if there is no any data in database, and if there is any it will then start creating table for once and repeatedly fill up the table rows for given rows of data on database.
if (mysqli_num_rows($records)== 0){
echo "No data available for that name specified";
exit();
} else {
echo
"<table>
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Desc</th>
</tr>
</thead>
<tbody>";
while($row=mysqli_fetch_array($records)) {
$name = $row['Name'];
$email = $row['Email'];
$desc = $row['Desc'];
echo
"<tr>
<td>".$name."</td>
<td>".$email."</td>
<td>".$desc."</td>
</tr>";
}
echo
"</tbody>
</table>";
}
Move your echo
"<table>
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Desc</th>
</tr>
</thead>
<tbody>";
into the the if statement. This way it will only display the table when data is available!
$name = $_GET['name'];
require_once("connect.php");
$records = $connect->query("SELECT * FROM Userlists WHERE Name = '$name'");
if (mysqli_num_rows($records)== 0){
echo "No data available for that name specified";
}
else {
echo
"<table>
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Desc</th>
</tr>
</thead>
<tbody>";
while ($row = mysqli_fetch_array($records)) {
$name = $row['Name'];
$email = $row['Email'];
$desc = $row['Desc'];
echo
"<tr>
<td>" . $name . "</td>
<td>" . $email . "</td>
<td>" . $desc . "</td>
</tr>";
}
echo "</tbody></table>";
}
Try this one. But don't forget to escape $_GET['name'] like htmlspecialchars and real_escape_string

how to give style to the SQL table when checkbox selected?

SO i have form which consist of "Event Name" "Event Description" "Event Date" and checkbox "is important". When i check checkbox value "yes" its important, it sends to the sql value = "1" to table "is_important". Everything is all right, but i give the bootstrap style "bg-danger" for that "is_important" = 1 table and it doesnt show up. What's the problem?
You can see in the code:
<?php
if (isset($_POST['important'])) {
$error = array();
$success = array();
$eventTime = time();
$important = $_POST['important'];
$eventName = trim(mysql_real_escape_string($_POST['EventName']));
$eventDesc = htmlentities(trim(mysql_real_escape_string($_POST['EventDesc'])), ENT_QUOTES);
if (!isset($eventName) || empty($eventName)) {
$error['eventName'] = "Prasome ivesti ivykio varda";
} else if (strlen($eventName) > 32 || strlen($eventName) < 3) {
$error['eventName'] = "Ivykio pavadinimas turi buti tarp 3 ir 32 simboliu";
}
if (!isset($eventDesc) || empty($eventDesc)) {
$error['eventDesc'] = "Prasome ivesti ivykio aprasyma";
}
if (empty($error)) {
$sql = "INSERT INTO notes_list (title, description, timestamp,is_important) VALUES ('$eventName', '$eventDesc','$eventTime','$important')";
$result = mysqli_query($con, $sql);
$success[] = "SEKME !";
} else {
}
}
?>
<table class="table table-striped">
<thead>
<tr>
<th>Event name</th>
<th>Event description</th>
<th>Event date</th>
</tr>
</thead>
<tbody>
<?php
$query = "SELECT * FROM notes_list ORDER BY id DESC LIMIT 10";
$result2 = mysqli_query($con, $query);
print_r($_POST);
if ($result2) {
while ($note = mysqli_fetch_assoc($result2)) {
?>
<tr<?php echo (($note['is_important'] == 1) ? "class='bg-danger'" : ""); ?>>
<td><?php echo $note['title']; ?></td>
<td><?php echo $note['description'] ?></td>
<td><?php echo date('l M jS', $note['timestamp']); ?></td>
</tr>
<?php
}
mysqli_free_result($result2);
}
/* close connection */
mysqli_close($con);
?>
</tbody>
</table>
Full Example in this picture:
https://www.dropbox.com/s/h650h2spy2487dm/chechbox.jpg?dl=0
This:
<tr<?php echo (($note['is_important'] == 1) ? "class='bg-danger'" : ""); ?>>
would render this:
<trclass='bg-danger'>
in case is_important is 1. You need a space there, before the class.

DataTable plugin not working with dynamically generated php table (arrows wouldn't show up too)

I created a table from using php and added the plugin (used demo_table.css). The arrows wouldn't show on the result page and it doesn;t apply any css.
Here is my php code:
$result = mysqli_query($link, $sql);
$num_rows = mysqli_num_rows($result);
echo '<table cellpadding = "0" cellspacing="0" border="0" id="datatables" class="display">';
echo '<thead>';
echo '<tr>';
echo '<th>SNo.</th>
<th>Username</th>
<th>Trip ID</th>
<th>Destination</th>
<th >Leave Date</th>
<th>Return Date</th>
<th>Total</th>
<th>Submit Date</th>
<th >Status</th>
<th >Reason</th>
<th >Update</th>';
echo '</tr>';
echo '</thead>';
echo '<tbody>';
} else {
echo('not valid user');
}
if (!$result) {
die(mysqli_error($link));
}
if ($num_rows<=0){
echo('not valid user');
}
elseif ($num_rows>0){
$i=1;
while($row = mysqli_fetch_assoc($result)) {
$grandtotal = $row['flight_estimate'] + $row['registration_fee'] + $row['total_cost'];
$status = $row['status'];
if(($status == 'Approved') || ($status == 'Denied')){
$newcolumn = '<td></td>';
}
else{
$newcolumn = '<td>Approve/Deny</td>';
}
echo '<tr>';
echo '<td>'. $i++ .'</td><td>'.$row['username'].'</td><td>'.$row['trip_id'].'</td><td>'.$row['destination'].'</td><td>'.date('d/m/Y',strtotime($row['leave_date'])).'</td><td >'.date('d/m/Y',strtotime($row['return_date'])).'</td><td >'. round($grandtotal,2).'</td><td >'.date('d/m/Y',strtotime($row['updateddate'])).'</td><td >'.$row['status'].'</td><td >'.$row['reason'].'</td>'.$newcolumn;
}
echo '</tr>';
echo '</tbody>';
echo '</table>';
}
?>
Is there anything that I'm missing? All it does is center all the column values. But when I click on header nothing happens.
You need to set 'bJQueryUI' to true when you init dataTable
$("#datatables").dataTable({ 'bJQueryUI' : true });
It would help if you posted your js script as that is where your problem is.

Categories