-1

I had generated few textboxes in a loop n named them differntly.. but the retrieving of data from those boxes is not working.. Please help me..

code for creating those textboxes

$i=0;  
while($data=mysql_fetch_array( $sql ))
   { 
       echo "<tr><td>".$data['idno']." </td><td>".$data['name'] . " </td><td>
       <input type='text' name='obtmarks".$i."'></td></tr>";  $i++; 
   }

I have to retrieve that data n place it another table

code for retrieving the data

$i=0;


while($data=mysql_fetch_array( $sql1 )) 
 { 

    $as=mysql_query("INSERT INTO marks values('".$data['idno']."','".$data['name']."','".mysql_real_escape_string($_POST['obtmarks".$i."'])."')");
 $i++;  }

Please help me.. thank u in advance..

Nandu
  • 231
  • 1
  • 2
  • 10
  • clentfort is right, you should look at this http://stackoverflow.com/questions/3446216/difference-between-single-quote-and-double-quote-string-in-php – Joe T Sep 19 '12 at 18:13

3 Answers3

3

In your mysql_real_escape_string you have $_POST['obtmarks".$i."'], it should be $_POST['obtmarks'.$i]. Also you should stop using the deprecated mysql_ methods. They are deprecated and will be removed in the future

clentfort
  • 2,454
  • 17
  • 19
  • You should accept this answer then as the right one. [Here is explained how it works and what it is good for](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) You specially should accept answers to motivate other people to answer your questions. – clentfort Sep 19 '12 at 19:27
0

$_POST['obtmarks'.$i."'] u put a " instead of a '

Teena Thomas
  • 5,139
  • 1
  • 13
  • 17
0

You should consider using array notation in your name attributes (AS in name="foo[]" or name="foo[0]" or even name="foo[bar]" etc) for arrays of form data, then you can simply iterate the array $_POST['foo']

EJTH
  • 46
  • 2