Adding Multiple Textbox Entry To A Mysql Database
I have created a form, with 5 textbox fields and I want to add those five entries in the database. I want to use the textbox 'array', that way I can use a for-each when saving to t
Solution 1:
HTML
<inputtype="text" value="whateva" name="text[]" />
<inputtype="text" value="whateva" name="text[]" />
<inputtype="text" value="whateva" name="text[]" />
PHP
if (!empty($_POST['text'])) {
foreach ($_POST['text'] AS$value) {
// add to the database$sql = 'INSERT INTO tableName SET fieldName = "' . mysql_real_escape_string($value) . '"';
}
}
Solution 2:
Yes, HTML supports arrays. just name your textareas like this:
<textarea name="field[]"></textarea> /* Notice square brackets */
For this example, in PHP, your $_GET or $_POST will have array key with name 'field' and values from these textareas.
Solution 3:
If 'Submit' is the name of the submit button. yeah that will work.
but few suggestions:
correct it as:
< input type="text" value="whateva" name= "" />
Use validation for the text submitted by user
IMPORTANT: "GET A BOOK ON PHP" and learn it. Seriously, if you learn this way, you wont become a good programmer. You are learning it the hardway. Book is must for you.
Post a Comment for "Adding Multiple Textbox Entry To A Mysql Database"