Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP MySQL Query Where x = $variable [closed]

Tags:

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.

like image 608
user2224376 Avatar asked Mar 29 '13 12:03

user2224376


People also ask

How do you store SQL query result in a variable in php?

Use the following syntax : $result= mysql_query(".. your query.."); Note that this variable can also store multiple rows depending on your query. Also note that statements other than "select" will return the no of rows affected.

How use php variable inside MySQL query?

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 ?>

How can I get single data from MySQL in php?

Here it is using mysqli: session_start(); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); $link = new mysqli('localhost', 'username', 'password', 'db_name'); $link->set_charset('utf8mb4'); // always set the charset $name = $_GET["username"]; $stmt = $link->prepare("SELECT id FROM Users WHERE username=?

What is $row in php?

Return Value: Returns an array of strings that corresponds to the fetched row. NULL if there are no more rows in result set. PHP Version: 5+


1 Answers

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'"); 
like image 57
John Woo Avatar answered Oct 14 '22 09:10

John Woo