-1

enter image description here

What is the right syntax for code above?

$_POST[firstname{$i}],  $_POST[firstname+$i], $_POST[firstname.$i]

I searched over and over again but I couldn't find any answer yet : /

How am I suppose to put the $i after those names?

user1844933
  • 3,296
  • 2
  • 25
  • 42
mistysnake
  • 113
  • 1
  • 2
  • 8

4 Answers4

1

The correct syntax:

"... values ( ".$_POST['firstname'.$i]." ) ..."
Alireza Fallah
  • 4,609
  • 3
  • 31
  • 57
0

try this

 $firstname =  $_POST['firstname'.$i];

and user $firstname variable in your query

Satish Sharma
  • 9,547
  • 6
  • 29
  • 51
0

You cannot use array subscripts in a string like that. You'd have to write "{$_POST['firstname'.$i]}" (you were also missing the quotes around the first part of the array subscript, such as 'firstname').

If you plan on doing that though, you will open your application to hackers (read here on how to prevent sql injections in php).

Community
  • 1
  • 1
knittl
  • 246,190
  • 53
  • 318
  • 364
0
  • "hi dear mistysnake u can use 'Peter''".$i."' peter is the static value and u can insert value and your problem is the u can put the $_GET"
jignesh
  • 11
  • 6