2 votes

Nesting variables inside strings doesn't work for me

Here my code:

$sql = mysqli("localhost","root","","usuarios");
$limite = $_POST['cantidad'];
for ($i=0; $i<$limite; $i++) { 
    $sql->query("INSERT INTO usuarios(nombre,apellido,usuario,clave) VALUES ('$_REQUEST[nombre$i]','$_REQUEST[apellido$i]','$_REQUEST[usuario$i]','$_REQUEST[clave$i]') ") or die($mysql->error);
echo "Valores agregados correctamente";

I get the following error:

Parse error: syntax error, unexpected '$ i' (T_VARIABLE), expecting ']' in AJAX / process.php on line 5


HolaDevs is an online community of programmers and software lovers.
You can check other people responses or create a new question if you don't find a solution

Powered by: