tags:

views:

47

answers:

3
<input type="radio" name="ques1" value="op4">Jingles<br>

just a part of the code..... when i am checking this... iam doing this as

$selected=$_POST['ques1'];

now when i am doing this with for loop....

for($i=0;$i<...;$i++)
$selected=$_POST['ques'.{$i+1}];

NEW SYSNTAX ADDED...............................

$sql='UPDATE Reg_Stud SET Result=$perc WHERE RegID="$_SESSION['id']"';

//Whats wrong with this one???

....//whts the correct syntax??

+3  A: 
$selected=$_POST['ques'.($i+1)];

or, if you want to use string interpolation,

for ($i = 1; $i <= ...; $i ++) {
  ...
  $selected = $_POST["ques$i"];
  // or $selected = $_POST["ques{$i}"];
  ...
}

That {...} is a special syntax to insert a complex variable (but not an expression like $i+1) inside a string. Outside of the string, it is just used for grouping statements.

KennyTM
Thnx...it worked
Vinod K
in this question tht value dint matter hence i just ignored it and wrote {....}...
Vinod K
+2  A: 
$selected=$_POST['ques'.($i+1)];
Emil Vikström
+4  A: 

The correct syntax would be $select = $_POST['ques' . $i + 1];, however, you can use arrays :

<input type="radio" name="ques[]" value="op4">Jingles<br>

Which you can then use in PHP like this :

echo $_POST['ques'][0]

It is way easier to manage variables this way! Note that this is particularly useful for check boxes, if you use radio button, it might be a better idea to remove the [] part, then PHP will automaticly retrieve the value that was chosen (if any)

Vincent Savard
thnx..i will definitely try it out....
Vinod K