-5
$sql="SELECT * FROM user WHERE id = '".$q."'";

And what do these periods around the variable do? I'm new to php, so forgive my ignorance.

vital
  • 21
  • 1
  • 2

6 Answers6

4

It's called string concatenation. $q is a variable.

<?php
$q = 1;
$sql="SELECT * FROM user WHERE id = '".$q."'";
// now $sql is SELECT * FROM user WHERE id = '1'
?>

See the manual

Kermit
  • 33,827
  • 13
  • 85
  • 121
0

It's hard to tell what $q really means, but the dots are used for string concatenation.

Shamim Hafiz - MSFT
  • 21,454
  • 43
  • 116
  • 176
0

$q is (should be) some variable previously defined.

The periods are operators. They concatenate the different parts of the expression: "SELECT * FROM user WHERE id = '", $q and "'".

For example if $q is now 1, the resulting string would be:

SELECT * FROM user WHERE id = '1'
bwoebi
  • 23,637
  • 5
  • 58
  • 79
0

$q is just a variable defined at some point in the code.

The periods are used to concatenate (join) the variable onto the string though in this case they aren't required due to the use of double quotes.

James Coyle
  • 9,922
  • 1
  • 40
  • 48
0

The dots (periods) concatenate strings. The variable $q is whatever it is assigned somewhere in your code.

0

$q can be anything depending on the context. If you are using a system it's likely $q is actually a $_GET['q']. The periods are for concatenating strings. In other languages this usually looks like "this is " + value + " :D" while in PHP this looks like "this is " . value . " :D"