I used the network developer tool to see if the id is sent to the other page. Which it successfully did. And I can see the other page echo the result but it doesn't show in the modal in the other page even though I have the results.php included in the modal div. Anybody know why this is happening?
itempage.php code:
<div id="globalmodal" class="modal">
<div class="modal-content">
<?php include ("getdata.php");?>
</div>
</div>
results.php code:
if (!empty($_POST["data"])) {
$server = '';
$dbname = '';
$dsn = "mysql:host=".$server.";dbname=".$dbname;
$username = '';
$password = '';
$newdata = $_POST["data"];
$db = new PDO($dsn, $username, $password);
$db -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$statement = $db->prepare("SELECT * FROM `eeee` WHERE `id LIKE '%$newdata%' GROUP BY `id`");
$statement->execute();
$row = $statement->fetch(PDO::FETCH_ASSOC);
if($row['id']) {
$pTitle = $row['title'];
echo '<h4>'.$pTitle.'</h4>';
echo "Yes it was received!";
}
}
In the itempage.php the getdata.php is included in the div for the modal. But the modal doesn't show the results in the getdata.php page even though the getdata.php has the right title from the database. But the echo doesn't show in the modal pop up.
There is a small typographical error in the SQL query:
$statement = $db->prepare("SELECT * FROM `eeee` WHERE `id LIKE '%$newdata%' GROUP BY `id`");
It has a missing ``` (it is opened but not closed) for the id used in the like
. That causes a SQL error, and the condition that displays the result will never be executed (as $row['id']
will not exist).
As a quick solution, just close it properly like this:
$statement = $db->prepare("SELECT * FROM `eeee` WHERE `id` LIKE '%$newdata%' GROUP BY `id`");
So I fixed it, I had to leave url for $.ajax blank.