-1

I keep getting a T_Variable exception when running this PHP code hosted on an online database. Am not really the expert at PHP, but maybe one of you can spot the error.

thanks,

Here is the code:

$wind = "deep34"; //error thrown here. When I delete this variable. //Error jumps to $name
$name = "6";  

$sql = "select *from students where deviceid = '$name' and alpha = '$wind';";
i_o
  • 777
  • 9
  • 25
  • Please try this :- $sql = "select *from students where deviceid = '".$name."' and alpha = '".$wind."'"; – Manish Jesani Feb 01 '17 at 04:32
  • Still the same error @ManishJesani – i_o Feb 01 '17 at 04:35
  • 1
    `$sql = "select * from students where deviceid = $name and alpha = $wind";` this is correction in query but you have some `;` missing before `$wind = "deep34";` – Alive to die - Anant Feb 01 '17 at 04:35
  • 4
    What is the code/lines **before** `$wind = "deep34";`? Most likely missing a closing `;` or quote on the line before. Typically when the `Error jumps` when you delete the line the error is on, it usually means the error is above that line. – Sean Feb 01 '17 at 04:36
  • As [Sean](http://stackoverflow.com/questions/41971933/t-variable-error-thrown-in-simple-php-code#comment71122191_41971933) said, the error occurs before the line because its expecting you to "finish" the previous code. Also, *'$wind'**->;<-**"* is optional, better leave it out. – Xorifelse Feb 01 '17 at 04:45
  • why would $wind be optional? Also, I've noticed that if I copy and past the database credentials such as password , database name and so on.. from other files hosted on the online database, the error disappears. It has happened before with other scripts I've tested. @Xorifelse – i_o Feb 01 '17 at 04:47
  • Am I marking `$wind` as optional? Or is it the symbol between `->` and `<-`. I'm confused. – Xorifelse Feb 01 '17 at 04:49

1 Answers1

0

Dont use semicolon at the end of the statement

$sql = "select * from students where deviceid = '$name' and alpha = '$wind'"; 
Nishant Nair
  • 1,999
  • 1
  • 13
  • 18
  • its got to be the connection and the credentials.. its something weird that happens.. When I copy and paste the credentials to the database from some other file, which I forgot the name.. the error disappears.. I don't know why – i_o Feb 01 '17 at 04:54
  • Oh..! any ways you caught the error that's good. – Nishant Nair Feb 01 '17 at 04:57
  • Yes..It was that. All I did was manually re-type the credentials to the database and it worked. Wasted an hour or so in this. haha – i_o Feb 01 '17 at 05:15