Syntax PHP error ""

1
// retrieve selected results from database and display them on page
$sql = 'SELECT * FROM publicaciones LIMIT ' . $this_page_first_result . ',' . $results_per_page;
$result = mysqli_query($conexion, $sql);


while ($row = mysqli_fetch_assoc($result)) {

    $sqlP = "SELECT * FROM coleccionPublicaciones WHERE id_publicacion='.$row["id_publicacion"].' LIMIT 1";
    $resultP = mysqli_query($conexion, $sqlP);

I have this code where on the line: $sqlP = "SELECT * FROM coleccionPublicaciones WHERE id_publicacion='.$row["id_publicacion"].' LIMIT 1";

I get the following error:

  

Parse error: syntax error, unexpected '"', expecting identifier   (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in ...

The fact is that I do not see any errors in quotes or anything. I hope someone can help me, greetings.

    
asked by MadCode 04.07.2018 в 11:12
source

2 answers

1

If you use $ row ["publication_id"] and the operator. To concatenate the string, you must put the same type of quotation marks as at the beginning of the selection and use other quotes or escape them for the quotation marks of the field.

You can change the select like this

$sqlP = "SELECT * FROM coleccionPublicaciones WHERE id_publicacion='".$row["id_publicacion"]." ' LIMIT 1";

But it is not recommended that you do database queries like this. Or not at least when in the consultation you enter data entered by the user because they could make you sql injection.

    
answered by 04.07.2018 в 11:17
0

External quotes (in php) must be different from those in the Mysql statement (internal in the query)

$sql = "SELECT * FROM publicaciones LIMIT '".$this_page_first_result."','". $results_per_page."' ";

$sqlP = "SELECT * FROM coleccionPublicaciones WHERE id_publicacion='".$row["id_publicacion"]."' LIMIT 1";
    
answered by 04.07.2018 в 11:16