hi all im attempting to update some script and i have a undefined error in a page see coding for error
$column = "select * ";
$sql .= " from favorites where user_id = '".$_SESSION['userid']."' ";
of which the information a want to echo shows up
so when i put the following in
if(!empty($sql)) {
$sql .= " from favorites where user_id = '".$_SESSION['userid']."' ";
}
the information echoed no longer shows up
here is the full code for this
<?php
include("config/db_connect.php");
include("config/ckh_session.php");
// Add user favorite list
if(isset($_POST['favor_id']))
{
$check_refer = mysqli_query($conn,"select favor_id , user_id from favorites where favor_id = '".$_POST['favor_id']."' and user_id = '".$_SESSION['userid']."'");
if(mysqli_num_rows($check_refer)<1)
{
$sdate = date('d-m-Y h:i:s A');
$insert = mysqli_query($conn,"insert into favorites set user_id = '".$_SESSION['userid']."', favor_id = '".$_POST['favor_id']."', sdate = '".$sdate."' ") or die(mysqli_error($conn));
$last_id = mysqli_insert_id($conn);
}
}
// for pagination code
$start=0;
if(isset($_GET['start'])) $start=$_GET['start'];
$pagesize=10;
if(isset($_GET['pagesize'])) $pagesize=$_GET['pagesize'];
// Fetch favorite user
$column = "select * ";
if(!empty($sql)) {
$sql .= " from favorites where user_id = '".$_SESSION['userid']."' ";
}
//$user_refer = mysqli_query($conn,"select * from favorites where user_id = '".$_SESSION['userid']."' ");
$search_ord = " order by id desc ";
$sql1 = " select count(*) ".$sql;
$sql .= $search_ord;
$sql .= " limit $start, $pagesize ";
$sql = $column.$sql;
$reccnt = getSingleResult($sql1);
$finalsearch = mysqli_query($conn,$sql);
?>