0

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..

2 Answers 2

1

Assuming you print the textboxes in a form, and post the form back to the retrieval code:

You need to get the variable value from the post array:

$i=0;

while($data=mysql_fetch_array( $sql1 )) 
{ 
    var value = $_POST['obtmarks'.$i];

    // insert into database

    $i++;  
}

(Be careful to use the exact same label, in your example you use obmarks and obtmarks.)

WARNING Don't store the value in your database without checking it!! Use prepared statements!!

Sign up to request clarification or add additional context in comments.

2 Comments

can u please guide me abt those prepared statements for this code.
You should read this guide. Variables bound using prepared statements are escaped automatically by the server, preventing SQL Injection attacks.
1

What about this:

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

this is assuming you are passing your data through a form submit.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.