This question already has an answer here:
<?php
session_start();
require_once 'class.user.php';
$user_home = new USER();
if(!$user_home->is_logged_in())
{
$user_home->redirect('index.php');
}
$stmt = $user_home->runQuery("SELECT * FROM tbl_users WHERE userID=:uid");
$stmt->execute(array(":uid"=>$_SESSION['userSession']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$proid = $_REQUEST['profile'];
$stmt0 = $user_home->runQuery("SELECT * FROM tbl_users WHERE userName=:uid");
$stmt0->execute(array(":uid"=>$proid));
$row0 = $stmt0->fetch(PDO::FETCH_ASSOC);
$callid = $row0['userID'];
$stmt4 = $user_home->runQuery("SELECT * FROM follow WHERE followrec=:uid");
$stmt4->execute(array(":uid"=>$row0['userID']));
$row4 = $stmt4->fetch(PDO::FETCH_ASSOC);
$stmt7 = $user_home->runQuery("SELECT * FROM tbl_users WHERE userID=:uid");
$stmt7->execute(array(":uid"=>$_SESSION['userSession']));
$row7 = $stmt7->fetch(PDO::FETCH_ASSOC);
?>
<?php
$host = 'localhost';
$dbname = 'project';
$username = 'root';
$password = '1234';
$charset = 'utf8';
$d1 = $row7['userID'];
$d3 = $row4['followrec'];
$d4 = $row0['userID'];
$d2 = "";
$d5 = "";
try {
$pdo = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
$usid = ($row['userID']);
$sql1 = "SELECT
messages.rec ,messages.send,messages.msg,messages.post_time,tbl_users.userID,tbl_users.Fname,tbl_users.Lname
FROM
messages , tbl_users
WHERE
messages.send=tbl_users.userID
AND messages.send IN ('$d1','$d4')
AND messages.rec IN ('$d1','$d4')
ORDER BY
messages.id";
$q1 = $pdo->prepare($sql1);
$q1->execute([$usid]);
$q1->setFetchMode(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
die("Could not connect to the database $dbname :" . $e->getMessage());
}
?>
<div id="auto_load_div"></div>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
function auto_load(){
$.ajax({
url: "data.php",
cache: false,
success: function(data){
$("#auto_load_div").html(data);
}
});
}
$(document).ready(function(){
auto_load(); //Call auto_load() function when DOM is Ready
});
//Refresh auto_load() function after 10000 milliseconds
setInterval(auto_load,10000);
</script>
</body>
</html>
data.php
<?php while ($row1 = $q1->fetch()): ?>
<?php $a=$row1['rec'];
$d4 = $row0['userID'];
if ($a==$d4)
{
include ("msgrec.php");
}
else
include ("msgsent.php");
?><?php endwhile; ?>
when I include data.php in the first file it runs the code means it fetch the data but whenever I put the code in data.php it gives an error to me
Notice: Undefined variable: q1 in E:wampwwwprojectdocumentationdata.php on line 1
( ! ) Fatal error: Call to a member function fetch() on a non-object in E:wampwwwprojectdocumentationdata.php on line 1
Aucun commentaire:
Enregistrer un commentaire