Hi there,
Newbie at this, so here goes:
I am attempting to build a page that updates multiple records. The page uses
as its input, a series of dynamically generated text boxes from the previous
page (through POST variables)
The text boxes on the previous page are named as follows:
txt_1
txt_2
txt_3
etc....
txt_ans1
txt_ans2
txt_ans3
etc...
with a hidden field next to each box to identify the primary key as follows:
txt_hidden_1
txt_hidden_2
txt_hidden_3
etc...
They are dynamically generated as they are read from the database, hence the
common naming conventions.
My form handling page (which the form POST action points to) is designed to
cycle through each of these values and update the recordset WHERE
id=txt_hidden_$ counter. If this is unclear (probally is) then look at the
code below:
$number_of_reco rds = $_POST[txt_num_rows]; //get the value from the hidden
field which contains the total number of records
//create the sql statement. This should look like UPDATE.... WHERE
id=somevariable
//the counter will increment for each so we need to have the counter
incremented for each time the query is run
//need to loop through all the records and apply the SQL query
for ( $marker=1; $marker<=$numbe r_of_records; $marker++) {
$sql = "UPDATE faq SET faq_quest='$_PO ST[txt_$marker]',
faq_ans='$_POST[txt_ans$marker]' WHERE faq_id = '$_POST[txt_ans$marker]'";
//code here to actually RUN the SQL query
}
As you can probally guess from the fact that I am typing this massive post,
the above code does not work. I keep getting errors when I attempt to use
the $marker variable from within the SQL query, to cycle through all the
POST variables and update all the records. I think its to do with the single
quotes ', which tell the compiler not to process variables, but rather take
everything literally, so-to-speak.
I guess, my question is: how can I re-write the above snippet to allow me to
do what I wish to achieve.
Many, many thanks to anyone who takes the time to read this and reply.
Comment