PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
dream2rule
Forum Contributor
Posts: 109 Joined: Wed Jun 13, 2007 5:07 am
Post
by dream2rule » Thu Aug 09, 2007 4:08 am
Code: Select all
$form= "<form action='' method='post' name='create_table_form' id='create_table_form' >";
$form.="<table border='0' cellpadding='0' cellspacing='0' width='95%'><tr><td><br>";
$form.="<table border='0' cellpadding='0' cellspacing='0' width='100%'>";
$form.="<tr><td> Database Name:</td>
<td><input type='text' name='db_name' size='20' value='$create_db_name' disabled='disabled'></td></tr>";
$form.="<tr><td><br> Table Name:</td>
<td><br><input type='text' name='table_name' size='20' value='$create_table_name' disabled='disabled'></td></tr>";
for($i=0; $i < $table_num_field; $i++)
{
$form.="<tr><font face='verdana' size='1'>";
$form.="<td><br> Field: <input type='text' name='fld_name[$i]' size='10'></td>";
$types = array("varchar","tinyint","text","smallint","mediumint","int","bigint","float","double","decimal",
"char","tinyblob","tinytext","blob","mediumblob","mediumtext","longblob","longtext","binary","varbinary");
$form.="<td><br> Type: <select name='fld_type[$i]'>";
for($j=0; $j < count($types); $j++)
{
$form.="<option value='$types[$j]'>$types[$j]</option>";
}
$form.="</select></td>";
$form.="<td><br> Size: <input type='text' name='fld_size[$i]' size='5'></td>";
$form.="<td><br> Null: <select name='fld_null[$i]'>";
$form.="<option value='not null'>Not Null</option><option value='null'>Null</option>";
$form.="</select></td>";
$form.="<td><br><input type='checkbox' name='fld_extra' value='auto' size='10'> Auto-increment</td>";
$form.="<td><br><input type='radio' name='fld_keys' value='primary' size='10'> Primary</td>";
$form.="<td><br><input type='radio' name='fld_keys' value='unique' size='10'> Unique</td>";
$form.="</font></tr>";
}
$form.="<tr><td><br> <input type='submit' name='create_table' value='Create Table'></td></tr>";
$form.="</table>";
$form.="</td></tr></table></form>";
echo($form);
In the above code, I want to retrieve all the posted values. Can anyone help.. I am stuck and $_POST[] does not seem to work..
Thanks and Regards,
Dream2rule
aceconcepts
DevNet Resident
Posts: 1424 Joined: Mon Feb 06, 2006 11:26 am
Location: London
Post
by aceconcepts » Thu Aug 09, 2007 5:07 am
How are you "getting" your "posted" values?
And I take it you are submitting the form to the same page that resides due to your "action" declaration?
s.dot
Tranquility In Moderation
Posts: 5001 Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana
Post
by s.dot » Thu Aug 09, 2007 5:13 am
Put print_r($_POST); at the beginning of the page and submit the form.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
dream2rule
Forum Contributor
Posts: 109 Joined: Wed Jun 13, 2007 5:07 am
Post
by dream2rule » Thu Aug 09, 2007 5:14 am
yes i am posting all the values to the same page and i am trying to use for loops to retrieve data from form but in vain
dream2rule
Forum Contributor
Posts: 109 Joined: Wed Jun 13, 2007 5:07 am
Post
by dream2rule » Thu Aug 09, 2007 5:17 am
scottayy wrote: Put print_r($_POST); at the beginning of the page and submit the form.
I get this when i put print_r($_POST); at the beginning of the form
Code: Select all
Array ( [fld_name] => name [fld_type] => varchar [fld_size] => 25 [fld_null] => not null [fld_extra] => auto [fld_keys] => primary [create_table_submit] => Create Table )
dream2rule
Forum Contributor
Posts: 109 Joined: Wed Jun 13, 2007 5:07 am
Post
by dream2rule » Thu Aug 09, 2007 5:24 am
I am getting only the last field name, not the complete array of field names!
aceconcepts
DevNet Resident
Posts: 1424 Joined: Mon Feb 06, 2006 11:26 am
Location: London
Post
by aceconcepts » Thu Aug 09, 2007 5:33 am
How are you dealing with the array you submit?
dream2rule
Forum Contributor
Posts: 109 Joined: Wed Jun 13, 2007 5:07 am
Post
by dream2rule » Thu Aug 09, 2007 5:37 am
If i loop it up its giving me errors,
Code: Select all
$fld_name = $_POST['fld_name'];
$fld_type = $_POST['fld_type'];
$fld_size = $_POST['fld_size'];
$fld_null = $_POST['fld_null'];
$fld_extra = $_POST['fld_extra'];
$fld_keys = $_POST['fld_keys'];
if(!empty($fld_extra))
echo $fld_extra;
if(!empty($fld_keys))
echo $fld_keys;
echo("$fld_name"." "."$fld_type"." "."$fld_size"." "."$fld_null");
aceconcepts
DevNet Resident
Posts: 1424 Joined: Mon Feb 06, 2006 11:26 am
Location: London
Post
by aceconcepts » Thu Aug 09, 2007 5:47 am
declare a variable that will store the array submitted from the form:
Then, to loop the array values use:
Code: Select all
foreach($varArray as $tmpArray)
{
//do something
}
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Thu Aug 09, 2007 5:52 am
dream2rule wrote: I get this when i put print_r($_POST); at the beginning of the form
Code: Select all
Array ( [fld_name] => name [fld_type] => varchar [fld_size] => 25 [fld_null] => not null [fld_extra] => auto [fld_keys] => primary [create_table_submit] => Create Table )That doesn't match the code you've posted.
dream2rule
Forum Contributor
Posts: 109 Joined: Wed Jun 13, 2007 5:07 am
Post
by dream2rule » Thu Aug 09, 2007 6:00 am
volka wrote: dream2rule wrote: I get this when i put print_r($_POST); at the beginning of the form
Code: Select all
Array ( [fld_name] => name [fld_type] => varchar [fld_size] => 25 [fld_null] => not null [fld_extra] => auto [fld_keys] => primary [create_table_submit] => Create Table )That doesn't match the code you've posted.
Code: Select all
$form.="<td><br> Size: <input type='text' name='fld_size[$i]' size='5'></td>";
$form.="<td><br> Null: <select name='fld_null[$i]'>";
$form.="<option value='not null'>Not Null</option><option value='null'>Null</option>";
$form.="</select></td>";
$form.="<td><br><input type='checkbox' name='fld_extra' value='auto' size='10'> Auto-increment</td>";
$form.="<td><br><input type='radio' name='fld_keys' value='primary' size='10'> Primary</td>";
$form.="<td><br><input type='radio' name='fld_keys' value='unique' size='10'> Unique</td>";
I did.. it does match... how do i loop it up? Because there's an array within an array...
dream2rule
Forum Contributor
Posts: 109 Joined: Wed Jun 13, 2007 5:07 am
Post
by dream2rule » Thu Aug 09, 2007 6:07 am
aceconcepts wrote: declare a variable that will store the array submitted from the form:
Then, to loop the array values use:
Code: Select all
foreach($varArray as $tmpArray)
{
//do something
}
This way i would have to create an array for each field i.e, an array for storing field names then the field types etc...
Any simpler wa to this??
aceconcepts
DevNet Resident
Posts: 1424 Joined: Mon Feb 06, 2006 11:26 am
Location: London
Post
by aceconcepts » Thu Aug 09, 2007 6:19 am
Dont declare an "array" variable to store your posted array.
Just use the foreach loop with you posted values.
Code: Select all
foreach($_POST['form_field'] as $tmpArray)
{
//do something
}
Maybe this will work as you have already declared the "value" as an array.
dream2rule
Forum Contributor
Posts: 109 Joined: Wed Jun 13, 2007 5:07 am
Post
by dream2rule » Thu Aug 09, 2007 6:56 am
it doesn't seem to work..
aceconcepts
DevNet Resident
Posts: 1424 Joined: Mon Feb 06, 2006 11:26 am
Location: London
Post
by aceconcepts » Thu Aug 09, 2007 7:50 am
Try removing the "php value" from within the "[" brackets of "fld_type".
So the select element will look like this: