0

I have a txt file and want to read it. itcontains only one word.

I want to use it as a string for sql table name.

$f = file_get_contents("http://...../...../..../address.txt");



 $sql = "insert into " + $f + "(x,y) values ('$x','$y')";

Unfortunately it doesn't work.. please help me!

Thanks.

basti38
  • 65
  • 6
  • Use `.` instead of `+` for concatenation operation. – Rajdeep Paul Apr 26 '17 at 15:56
  • By the way, you should be sure to verify that it's actually a valid table name, and pass `$x` and `$y` as parameters to a prepared statement rather than concatenating them into the SQL string. – Don't Panic Apr 26 '17 at 15:57
  • Possible duplicate of [How to combine two strings together in PHP?](http://stackoverflow.com/questions/8336858/how-to-combine-two-strings-together-in-php) – Don't Panic Apr 26 '17 at 15:59

2 Answers2

2

Try use '.' instead of using '+' to concatenate. Like this:

$sql = "insert into " . $f . "(x,y) values ('$x','$y')";
Filipe Martins
  • 608
  • 10
  • 23
0

You can't use + in php to combine strings. That is a javascript (other languages too) term

Correction:

$f = file_get_contents("http://...../...../..../address.txt");

$sql = "insert into " . $f . "(x,y) values ('$x','$y')";
Andrew Rayner
  • 1,056
  • 1
  • 6
  • 20