-2

Please look at this snippet

<?php
$dbhost = 'localhost:3036';
$dbuser = 'luis';
$dbpass = 'ashok1234';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
  die('Could not connect: ' . mysql_error());
}
mysql_select_db('lowcost1_mydatabase');

$sql = 'SELECT Sales_Author, Sales_Date, Sales_Channel, Sales_Title, Sales_Unit, Sales_Royalty, Sales_Currency    
    FROM Sales_tbl
    WHERE Sales_Email= \'&email\' ORDER BY Sales_Date ASC;

$conn2 = mysql_query( $sql, $conn );

if(!$conn2 )
{
  die('Could not fetch: ' . mysql_error());
}

I have checked and rechecked my single quotes in the statement above, I continue to get unexpected T_String error in the last die statement. I would greatly appreciate if someone can direct me in the right direction? Thanks!

Shri Suresh
  • 463
  • 1
  • 5
  • 20
av104
  • 1
  • Re-check your quotes in a proper editor, which highlights it like the formatting here on SO, and you'll easily see it. – Qirel Dec 13 '16 at 06:52

2 Answers2

1

Check updated code

$sql = "SELECT Sales_Author, Sales_Date, Sales_Channel, Sales_Title, Sales_Unit, Sales_Royalty, Sales_Currency    
    FROM Sales_tbl
    WHERE Sales_Email= '" . $email . "' ORDER BY Sales_Date ASC";

$conn2 = mysql_query( $sql, $conn );

if(!$conn2 )
{
  die('Could not fetch: ' . mysql_error());
}
Shri Suresh
  • 463
  • 1
  • 5
  • 20
  • Suresh, thanks so much for your help. Can you tell me or cite the reference as to why you had to enclose $email variable within '" . delimiters? Also, do you have to have double quotes instead of single quotes to enclose the SELECT statement? – av104 Dec 13 '16 at 07:31
  • You can't use variable inside single quotes. If you are using double quote, you can have variable inside. Whereas in single quotes, it's considered as simple string. So it's good practice to use like above. – Shri Suresh Dec 13 '16 at 16:04
0

You may use this code.

$sql = "SELECT Sales_Author, Sales_Date, 
           Sales_Channel, Sales_Title, Sales_Unit, Sales_Royalty, 
Sales_Currency    
     FROM Sales_tbl
    WHERE Sales_Email= '&email' ORDER BY Sales_Date ASC";

And , perhaps &email ---> $email?

Star_Man
  • 1,091
  • 1
  • 13
  • 30