26

I have this code (I know that the email is defined)

 <?php
$con=mysqli_connect($host,$user,$pass,$database);
 if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT `note` FROM `glogin_users` WHERE email = '.$email.'");

while($row = mysqli_fetch_array($result))
echo $row
?>

In my MySQL database I have the following setup (Table name is glogin_users) id email note

I've tried extracting the note text from the database and then echo'ing it but it doesn't seem to echo anything.

user2224376
  • 397
  • 1
  • 3
  • 5
  • 2
    Have you checked your error log? What errors do you get? What steps have you taken to troubleshoot this? Have you run the query from the command line? – John Conde Mar 29 '13 at 12:52
  • Can you post the error you are getting? – Barranka Mar 29 '13 at 12:54
  • 1
    You can also use `complex syntax` - curly brackets around the variable `WHERE email = ' {$emai} ' ");` . http://php.net/manual/en/language.types.string.php#language.types.string.parsing.complex – Dexter Nov 01 '18 at 04:16

3 Answers3

41

What you are doing right now is you are adding . on the string and not concatenating. It should be,

$result = mysqli_query($con,"SELECT `note` FROM `glogin_users` WHERE email = '".$email."'");

or simply

$result = mysqli_query($con,"SELECT `note` FROM `glogin_users` WHERE email = '$email'");
John Woo
  • 258,903
  • 69
  • 498
  • 492
4
$result = mysqli_query($con,"SELECT `note` FROM `glogin_users` WHERE email = '".$email."'");
while($row = mysqli_fetch_array($result))
echo $row['note'];
cyborg86pl
  • 2,597
  • 2
  • 26
  • 43
3

You have to do this to echo it:

echo $row['note'];

(The data is coming as an array)

Raheel Hasan
  • 5,753
  • 4
  • 39
  • 70