Im becomming quite a regular on here...
I am trying to dynamicly print out a table in PHP depending on what results are found with a MYSQL Statement.
See the below code, I am getting the below error
[Fri Jun 09 18:51:32.478737 2017] [fcgid:warn] [pid 63368] [client 5.69.190.95:64631] mod_fcgid: stderr: PHP Parse error: syntax error, unexpected 'showhistory' (T_STRING), expecting ',' or ';' in /home/tools/public_html/searchhistory.php on line 84, referer: http://tools.cidetech.co.uk/history.php
It seems to have a problem with just the "form" building inside of the loop I have no problems up until this line -
echo " <td><form method="POST" action="showhistory.php">
<input type="hidden" name="id_director" value=".$row["id"]"
</form></td> ";
I cant seem to figure out where I am going wrong, this would work fine in just pure HTML, however it needs to be inside of the mysql/php part as i need to pass the row id through inside of the button.
To be specific it is this part of the code I am struggling with
for ($i = 0; $i < count($idArray); $i++)
{
$sql="SELECT * FROM history WHERE id LIKE '%{$idArray[$i]}%'";
$result=$con->query($sql);
while($row=$result->fetch_assoc())
{
echo "<tr>";
echo "<td><pre>".$row["id"]."</pre></td>";
echo "<td><pre>".$row["date"]."</pre></td>";
echo "<td><pre>".$row["domain"]."</pre></td>";
echo " <td><form method="POST" action="showhistory.php">
<input type="hidden" name="id_director" value=".$row["id"]"
</form></td> ";
}
}
echo "</table>";
mysqli_close($conn);
?>
The full code can be seen here
<DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="stylesheet.css">
<meta http-equiv="content-type" content="text/html; charset=windows-1250">
<meta name="generator" content="PSPad editor, www.pspad.com">
<title>CWCS Domain Checker Tool</title>
</head>
<body>
<div class="header">
<a href="index.php">
<img src="cwcs-logo.png">
</a>
</div>
<hr/>
<div class="searchform">
<form action="searchhistory.php" method="post">
<label for="domain"> <input class="submit" type="text" name="domain" /> </label>
<input class="submitbutton" type="submit" name="search" value="Search for Domain" />
</form>
</div>
<?php
#define connection info/variables needed
$servername = "localhost";
$username = "";
$password = "";
$dbname = "domainhistory";
$domain = $_POST['domain'];
$idArray = array();
#creates mysql connection
$con=new mysqli($servername,$username,$password,$dbname);
if($con->connect_error)
{
echo 'Connection Faild: '.$con->connect_error;
}
else
{
$sql="SELECT * FROM history WHERE domain LIKE '%{$domain}%'";
$result=$con->query($sql);
#Pushes the ID of the mysql row into an array
while($row=$result->fetch_assoc())
{
array_push($idArray,$row["id"]);
}
}
mysqli_close($conn);
?>
<!---prints out the ID's stored in the array -->
<?php
$servername = "localhost";
$username = "";
$password = "";
$dbname = "domainhistory";
$con=new mysqli($servername,$username,$password,$dbname);
if($con->connect_error)
{
echo 'Connection Faild: '.$con->connect_error;
}
else
{
}
echo "<table>";
echo "<tr>";
echo "<th> ID </th>";
echo "<th> Domain</th>";
echo "<th> Date </th>";
echo "</tr>";
## - loops through the ID array, and then prints out the data relating to that ID.
for ($i = 0; $i < count($idArray); $i++)
{
$sql="SELECT * FROM history WHERE id LIKE '%{$idArray[$i]}%'";
$result=$con->query($sql);
while($row=$result->fetch_assoc())
{
echo "<tr>";
echo "<td><pre>".$row["id"]."</pre></td>";
echo "<td><pre>".$row["date"]."</pre></td>";
echo "<td><pre>".$row["domain"]."</pre></td>";
echo " <td><form method="POST" action="showhistory.php">
<input type="hidden" name="id_director" value=".$row["id"]"
</form></td> ";
}
}
echo "</table>";
mysqli_close($conn);
?>
</body>
</html>