473,412 Members | 4,966 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

Retrieving the posted values from a form in PHP

[PHP]

<form action='' method='post' name='create_table_form' id='create_table_form' >
<table border='0' cellpadding='0' cellspacing='0' width='95%'><tr><td><br />
<table border='0' cellpadding='0' cellspacing='0' width='100%'>
<tr><td>&nbsp;Database Name:</td>
<td><input type='text' name='db_name' size='20' value=<?php echo $db_name; ?>></td></tr>
<tr><td><br>&nbsp;Table Name:</td>
<td><br><input type='text' name='table_name' size='20' value=<?php echo $table_name; ?>>
</td></tr>
<?php
for($i=0; $i < $num_fields; $i++)
{
?>
<tr><font face='verdana' size='1'>
<td><br>&nbsp;Field: <input type='text' name='fld_name[$i]' size='10'>
<?php
$types = array("varchar","tinyint","text","smallint","mediu mint","int","bigint","float","double","decimal",
"char","tinyblob","tinytext","blob","mediumblob"," mediumtext","longblob","longtext","binary","varbin ary");
?>
<td><br>&nbsp;Type: <select name='fld_type[$i]'>
<?php
for($j=0; $j < count($types); $j++)
{
?>
<option value=<?php echo $types[$j]; ?>><?php echo $types[$j]; ?></option>
<?php } ?>
</select></td>
<td><br>&nbsp;Size: <input type='text' name='fld_size[$i]' size='5'></td>
<td><br>&nbsp;Null: <select name='fld_null[$i]'>
<option value='not null'>Not Null</option>
<option value='null'>Null</option>
</select></td>
<td><br><input type='checkbox' name='fld_extra' value='auto_increment' size='10'> Auto-increment</td>
<td><br><input type='radio' name='fld_keys' value='primary key' size='10'> Primary</td>
<td><br><input type='radio' name='fld_keys' value='unique key' size='10'> Unique</td>
</font></tr>
<?php } ?>
<tr><td><br>&nbsp;<input type='submit' name='create_table_submit' value='Create Table'></td>
<td><input type="hidden" name="num_flds" value="<?php echo $num_fields;?>" /></td>
</tr>
</table>
</td></tr></table>
</form>
[/PHP]

How do i retrieve $fld_name[$i] etc fields from the above form?

Any help would be appreciated. Thanks!
Aug 10 '07 #1
6 1983
nathj
938 Expert 512MB
Hi,

Try something like:
[php]

$_POST[$fld_name][$i]
[/php]

As $_POST is just an array, if you load an array into it you can access using the syntax above, I think. give it a try and see where you get to.

Cheers
nathj

Ps merging HTML and PHP as you do makes it really hard to read. I'd do it all in PHP with loats of echo or print().
Aug 10 '07 #2
When i retrieve it something like

$fld_name = $_POST['fld_name'][$i]

i get the characters of the last fld_name!!

This is not taking me anywhere.

I would just like to show what i have got after retrieving the posted values.

[PHP]

if(isset($_POST['create_table_submit']))
{

$table_fields = "";
for($i=0; $i < $num_flds; $i++)
{
$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'];
/*$tmp = $fld_name[$i]."&nbsp;".$fld_type[$i]."(".$fld_size[$i].")"."&nbsp;".$fld_null[$i]."&nbsp;".
$fld_extra."&nbsp;".$fld_keys;
echo $tmp."<br>";*/
$fld_data = $fld_name."&nbsp;".$fld_type."("."$fld_size".")"." &nbsp;".$fld_null."&nbsp;".$fld_extra."&nbsp;".$fl d_keys;
$table_fields = $table_fields .$fld_data .", ";
}
echo $table_fields;
}

[/PHP]

I am only getting one single row as a result while my aim to retrieve all the data entered in the form.

Any Help?
Aug 10 '07 #3
nathj
938 Expert 512MB
Hi,

After you have defined $fld_name try print_r($fld_name); . This will print everything to the screen as I think $fld_name is an array and this function will display the contents of the array.

From there you will be able to see the best way to manipulate it - either for() or foreach()

Cheers
nathj
Aug 10 '07 #4
Hi,

After you have defined $fld_name try print_r($fld_name); . This will print everything to the screen as I think $fld_name is an array and this function will display the contents of the array.

From there you will be able to see the best way to manipulate it - either for() or foreach()

Cheers
nathj
if i give "dream2rule" in the $fld_name, then after post and printing it, i get just "dr"

I need to get complete "dream2rule" :( :(
Aug 10 '07 #5
nathj
938 Expert 512MB
Ok, I've had a closer look at the code. There won't be a $_POST['fld_name'] element. There will be a $POST['fld_name1'] element.

The form has a number of text boxes that are called fld_namex. When you read this data out of te $_POST array you need to read it out using the proper input name:

[php]
<?php

for($i=0; $i<=$numfields; $i++)
{
$lcKey = 'fld_name' . $i ;
echo $_POST[$lcKey] ;
}
?>
[/php]

This should print all the fld_name input boxes that have been submitted. This code is a bit slack and would need tightening up for production purposes, but essentially I think it should work
Aug 10 '07 #6
tried the same but it is not printing the fld_name at all..
nothing is getting displayed :( :(
Aug 10 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Chico | last post by:
Hi, I have the following code in my form: Response.Write("<form name='Testing'>"); Response.Write("<INPUT type=hidden id='Testing_txtbox' name='Testing_txtbox' value='a simple test'>");...
0
by: Mark | last post by:
Hi, I am playing around with creating custom server controls for use within a ASP.NET page. I am creating a contact form and have the following question I am capturing the form postback data...
13
by: RHPT | last post by:
I am wanting to capture the XML posted by an InfoPath form with .NET, but I cannot figure out how to capture the XML stream sent back by the InfoPath form. With Classic ASP, I could just create an...
1
by: Joe | last post by:
Hello All, I have a user control which is composed of a label and a dropdownlist. In my code I add the user control to a placeholder on the webform. Now I want to be able to retrieve the...
5
by: aniket_sp | last post by:
i am using a data adapter and a dataset for filling and retrieving data into .mdb database. following is the code..... for the form load event Dim dc(0) As DataColumn Try If...
3
by: Dotnet Gruven | last post by:
I've built a WebForm with a Table added dynamically in Page_Load when IsPostBack is false. The table includes a couple of TextBoxes, RadioButtonLists and CheckboxLists. On postback, those...
1
by: Captain Dondo | last post by:
I am not really experienced in Javascript so bear with me.... I am working with an embedded platform; no mouse, no keyboard. Just up, down, left, right keys and +/- keys for...
10
by: Girish | last post by:
Hi Everyone, I am passing a form to a php script for further processing. I am able to retrieve the last value set for that given form variable using $variable=$_REQUEST;
4
by: namanhvu | last post by:
Hi everyone, I am trying to create a form for authorised users to upload photos to an image gallery. I'm attempting to perform simple validation of the fields by ensuring the fields aren't empty...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.