J M
J M

Reputation: 37

SQL SELECT using a session variable

Require("dbconnect.php");//works is used on other another page


echo $Customer_id;//Displays correctly 

Can anyone help?

Upvotes: 1

Views: 445

Answers (2)

Rahul
Rahul

Reputation: 5854

First Check that use session variable is getting the data or not. If the Customer id is of varchar then you are missing single inverted comma in where clause.

session_start();
$Customer_id = $_SESSION['id'];

Require("dbconnect.php");//works is used on other another page
$sql = "SELECT Job_id FROM Job";
$sql.= " WHERE Job_Customer_id = '$Customer_id'";
$stmt = $dbh->query($sql);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$Job_id = $row['Job_id'];

echo $Customer_id;//Displays correctly 
echo $Job_id;//Curently dose not display anything 

Upvotes: 1

Albzi
Albzi

Reputation: 15619

Change the $sql.= line to this:

$sql.= " WHERE Job_Customer_id = '$Customer_id'"

with the ' around $Customer_id.

Upvotes: 1

Related Questions