Oops, I'm sorry, recovering from a 102 fever the other day. :)
You don't want duplicate field IDs anywhere, really. The hidden fields
are probably completely unnecessary; what do you use them for?
It's the latter section you really need to correct, however, where each
data field's name is being set to "field_data" all the time. That's not
going to help you push it back into the database. the data won't be
distinguished, and all but one will be discarded. also, in my
suggested corrections, I assume you're passing default values to this
page in the field_data elements.
-P
<?php
if ($datatype=="text" || $datatype=="integer") {
echo "<td><input type=\"text\" name=\"$field_id\"
value=\"$field_data\"></td>";
}
elseif ($datatype=="textarea") {
echo "<td><textarea rows=\"10\" cols=\"100\"
name=\"$field_id\">$field_data</textarea><br></td>";
}
echo "</tr>";
}
?>
Your line :
<input type="hidden" name="field_id" value="<?php echo $field_id;?>" />
Should probably be:
<input type="hidden" name="<?php echo $field_id; ?>" value="<?php echo
$field_id;?>" />
So that each field's name isn't the string "field_id", but rather is
each field's unique ID.
Hi,
How can I send multiple values from a form to be stored in a
database, as
name of the fields is the same?
For example:
<?php
foreach ($field_data as $field) {
$field_name=$field["field_name"];
$field_id=$field["field_id"];
$datatype=$field["datatype_name"];
?>
<input type="hidden" name="field_id" value="<?php echo $field_id;?>" />
<tr>
<td><strong><?php echo $field_name;?><strong></td>
<?php
if ($datatype=="text" || $datatype=="integer") {
echo "<td><input type=\"text\" name=\"field_data\"></td>";
}
elseif ($datatype=="textarea") {
echo "<td><textarea rows=\"10\" cols=\"100\"
name=\"field_data\"></textarea><br></td>";
}
echo "</tr>";
}
?>
This creates a form with field names and text box or textarea box
next to
each field name depending on the datatype. After the user enters the
values in the text or textarea and clicks submit, the values should get
stored in a database. But what is happening is that only the value
entered
in the last field of the form is getting entered into the database.
This code is embedded in an application which is having an inbuilt
structure of taking the values from a form in a hash. Since key is the
same (i.e. field_id) everytime, the value gets overwritten and only the
last value gets stored in db. But I am not able to work out a
solution for
this.
I hope I am able to make my problem clear enough.
Thanks,
Suamya.
-----------------------------------------------------------------------------
DISCLAIMER:- "The information in this e-mail is
confidential, and is intended solely for the addressee or addressees.
If you are not the intended recipient,
please delete the mail and kindly notify the sender of misdelivery.
Any unauthorised use or disclosure of the contents of the mail is not
permitted and may be unlawful."
-----------------------------------------------------------------------------
"Scanned By MailScanner"
------------------------------------------------------------------------
Subject:
Re: [PHP] Fastest way to get table records' number
From:
"Daniel Brown" <[EMAIL PROTECTED]>
Date:
Wed, 19 Mar 2008 09:42:07 -0400
To:
Shelley <[EMAIL PROTECTED]>
To:
Shelley <[EMAIL PROTECTED]>
CC:
[EMAIL PROTECTED], "PHP DB" <php-db@lists.php.net>
On Tue, Mar 18, 2008 at 11:43 PM, Shelley <[EMAIL PROTECTED]> wrote:
Hi all,
What do you think is the FASTEST sql to get the total number of a
table
with millions of records?
That question would be better on the PHP-DB list, so for archive's
sake, I'm CC'ing that list.
$sql = "SELECT COUNT(*) FROM your_table";
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php