select request in php with errors

i'm trying to select data from mysql database with code in php but always i have errors.`

<?php
$dbhost = "localhost";
$dbuser = "";
$dbpass = "";
$db = "test";
$connect = mysql_connect($dbhost, $dbuser, $dbpass, $db)
or die ("connexion impossible");
mysql_select_db($db) or die ("selection de la base échoué");
$username = $_POST['username'];
$password = $_POST['password'];
query = mysql_query("SELECT * FROM table2 WHERE username= '$username' AND     password='.$password'");
$num = mysql_num_rows($query);
if($num == 1) {
while($list = mysql_fetch_assoc($query)){
$output = $list;
echo json_encode($output);
}
mysql_close();
}
?>

errors:

Notice: Undefined variable: username in C:\wamp\www\projet\connect.php on line 11
Notice: Undefined variable: password in C:\wamp\www\projet\connect.php on line 11

Answers


Replace the line

query = mysql_query("SELECT * FROM table2 WHERE username= '$username' AND     password='.$password'");

with

$query = mysql_query("SELECT * FROM table2 WHERE username= '".$username."' AND     password='".$password."'");

You have missed the $ before variable query, and with some string concatenation problems

And please use PDO instead of deprecated mysql_*


there is extra dot before $password in mysql query and query should be $query as $query is variable.

query = mysql_query("SELECT * FROM table2 WHERE username= '$username' AND     password='.$password'");

should be

$query = mysql_query("SELECT * FROM table2 WHERE username= '$username' AND     password='$password'");

Need Your Help

sizewithattributes not returning correct size

ios objective-c cocoa-touch uilabel sizewithfont

I am tring to calculate the height of text labels in uitableview cells. After seeing that sizewithfont was deprecated with ios 7, I implemented sizewithattributes but the return values were way sma...

How to add Product using module in prestashop

prestashop

I'm using prestashop 1.5.1. In that I'm creating one module in which customer can post their product to store. I unable to find how to add product with help of module. can any one know solution for...