-1
$sql=''select Name from users where Username='$username' and 

Password='$password'";
Mark Baker
  • 199,760
  • 28
  • 325
  • 373
Angie
  • 1
  • 1
  • remove the last double quote from the statement – shahsani Oct 15 '17 at 18:01
  • 1
    Don't confuse two single quotes with one double quote; [learn about the differences](http://php.net/manual/en/language.types.string.php) – Mark Baker Oct 15 '17 at 18:03
  • $sql=''select Name from users where Username='$username' and Password='$password' "; i tried this also – Angie Oct 15 '17 at 18:03
  • https://www.youtube.com/watch?v=PRYTjl8xspA i tried to implement this video exactly how it is . but encountered the above error. cud there be an error with xampp server? – Angie Oct 15 '17 at 18:17
  • because only values are getting inserted into db . but it is not being retrieved or fetched from db for performing login validation. – Angie Oct 15 '17 at 18:19
  • Your query should be parameterized. – chris85 Oct 15 '17 at 18:48

1 Answers1

1

You have some double-quote and single-quote mixup in your code. Always match them in correct order as you use them.

You query can be corrected as:

$sql = "select Name from users where Username='$username' and Password='$password' ";

I have put an extra space before the last double quote, just to clarify the use of single and double quote in that place.

shahsani
  • 481
  • 6
  • 13
  • Right, but did you see [this comment](https://stackoverflow.com/questions/46758252/parse-error-syntax-error-unexpected-select-t-string#comment80461784_46758252) the OP left? *"$sql=''select Name from users where Username='$username' and Password='$password' "; i tried this also "*. – Funk Forty Niner Oct 15 '17 at 18:07
  • @Fred-ii- The code in that comment is syntactically wrong as the quotes before `select` are "two single quotes', not a single double-quote. Thats why its giving error to the user. – shahsani Oct 15 '17 at 18:10
  • Yeah, I see that in my editor now. Their comment appeared as containing an opening double quote, which was a bit hard to read in there. That comment and the post itself are the same. – Funk Forty Niner Oct 15 '17 at 18:18
  • Yes, I checked that comment code in an editor too, thats why posted an explanatory answer, which wasn't possible for me to mention in a comment. :-) – shahsani Oct 15 '17 at 18:20