By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,069 Members | 1,716 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,069 IT Pros & Developers. It's quick & easy.

Getting the dynamic 'name' with $_REQUEST[] , Pls help

P: n/a
Dear Group,

Please look at the following demo link.

http://www.itsravi.com/demo/new_pms/...addproject.php

I am trying to implement the "more attachment" and "more url" tasks in that
page. The data base design is like this. Keeping a separate table for the
"more file upload" (File uploaded directly to mysql). If the user closes
after simply uploading the files without submitting the whole project
information, or an exception occurs then the db table with extra files and
url is inserted un-necessary. So I thought to put all the uploaded
information in a array. At the end of submitting the full project
information in the db the array values will get stored in the corresponding
url and file table which is the child table which has got the FK key points
to the corresponding project (parent)table.

Following is the code I wrote for inputting the multiple url upload.

<?php

$number_tot = $number; /*if 3 given in the text box then 3 box to get urls*/

print "<form name=more_url_comp action=more_url_comp.php method=post>";

for($i=1 ; $i<= $number_tot ; $i++)

{

print "More Url $i:<input type='text' name='url_comp_'.$i><br>";

$more_url_comp[] = "url_comp_".$i; /*All the url name array*/

$test = $_REQUEST['url_comp_'.$i]; /*This is not wrking*/

}

echo '<input type="submit" name="more_comp_url" value="Upload Now!">';

print "</form>";

I got really stuck with the following. I don't know who to get the

$test = $_REQUEST['url_comp_'.$i]

in a array. Since the variable $i getting appended in the end. If, on the
other hand, I use array in the name of the text box such as text[], then can
I use serialize and unserialize function. If this can be done then there is
no need to use a separate db table to hold the value for url. Or I am
missing some thing very basic.?

I have not started to implement this with multiple file upload to the
mysql directly. I don't know what could be the problem that will arise in
that situation.

Any help will be very help full. Thanks.
Jun 26 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
sathyashrayan kirjoitti:
Dear Group,

Please look at the following demo link.

http://www.itsravi.com/demo/new_pms/...addproject.php

I am trying to implement the "more attachment" and "more url" tasks in that
page. The data base design is like this. Keeping a separate table for the
"more file upload" (File uploaded directly to mysql). If the user closes
after simply uploading the files without submitting the whole project
information, or an exception occurs then the db table with extra files and
url is inserted un-necessary. So I thought to put all the uploaded
information in a array. At the end of submitting the full project
information in the db the array values will get stored in the corresponding
url and file table which is the child table which has got the FK key points
to the corresponding project (parent)table.

Following is the code I wrote for inputting the multiple url upload.

<?php

$number_tot = $number; /*if 3 given in the text box then 3 box to get urls*/

print "<form name=more_url_comp action=more_url_comp.php method=post>";
please change this to
print "<form name='more_url_comp' action='more_url_comp.php'
method='post'>";

Unquoted string literals make Tim Berners-Lee cry.
>
for($i=1 ; $i<= $number_tot ; $i++)

{

print "More Url $i:<input type='text' name='url_comp_'.$i><br>";

$more_url_comp[] = "url_comp_".$i; /*All the url name array*/

$test = $_REQUEST['url_comp_'.$i]; /*This is not wrking*/
What the heck you mean it's not working? You're not using $test for
anything, how is it supposed to work?
>
}

echo '<input type="submit" name="more_comp_url" value="Upload Now!">';

print "</form>";

I got really stuck with the following. I don't know who to get the

$test = $_REQUEST['url_comp_'.$i]

in a array.
In what array? What is it that you exactly want to do with it? How come
you're dealing with $_REQUEST (and by the way, you should always use
either $_GET or $_POST, depending what your form method is, never
$_REQUEST) even before the form is submitted, you're just outputting the
form, what would $_REQUEST contain at that point?
Since the variable $i getting appended in the end. If, on the
other hand, I use array in the name of the text box such as text[], then can
I use serialize and unserialize function. If this can be done then there is
no need to use a separate db table to hold the value for url. Or I am
missing some thing very basic.?
If I understand right, you're talking about having multiple values in
one database field? No, no, and no. Very wrong. Just use the extra table
like you intended. (Why: check out Codd's database normalization rules)
I have not started to implement this with multiple file upload to the
mysql directly. I don't know what could be the problem that will arise in
that situation.

Any help will be very help full. Thanks.
--
Ra*********@gmail.com

"Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze
Jun 26 '07 #2

P: n/a
sathyashrayan kirjoitti:
>
print "More Url $i:<input type='text' name='url_comp_'.$i><br>";
The line above is producing malformed html, it will print:

More Url 1:<input type='text' name='url_comp_'.1><br>
This is just wrong. The browser will take the name as url_comp_ and
wonder what the heck the .1 is doing there but not taking them into account.

I assume you wanted:
More Url 1:<input type='text' name='url_comp_1'><br>

To get that, change the code like this:
print "More Url $i:<input type='text' name='url_comp_$i'><br>";
--
Ra*********@gmail.com

"Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze
Jun 26 '07 #3

P: n/a
Rami Elomaa wrote:
sathyashrayan kirjoitti:
>>
print "More Url $i:<input type='text' name='url_comp_'.$i><br>";

The line above is producing malformed html, it will print:

More Url 1:<input type='text' name='url_comp_'.1><br>
This is just wrong. The browser will take the name as url_comp_ and
wonder what the heck the .1 is doing there but not taking them into
account.

I assume you wanted:
More Url 1:<input type='text' name='url_comp_1'><br>

To get that, change the code like this:
print "More Url $i:<input type='text' name='url_comp_$i'><br>";

Actually, it will print:

More Url 1:<input type='text' name='url_comp_1'><br>"

Which is correct.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jun 27 '07 #4

P: n/a
sathyashrayan wrote:
Dear Group,

Please look at the following demo link.

http://www.itsravi.com/demo/new_pms/...addproject.php

I am trying to implement the "more attachment" and "more url" tasks in that
page. The data base design is like this. Keeping a separate table for the
"more file upload" (File uploaded directly to mysql). If the user closes
after simply uploading the files without submitting the whole project
information, or an exception occurs then the db table with extra files and
url is inserted un-necessary. So I thought to put all the uploaded
information in a array. At the end of submitting the full project
information in the db the array values will get stored in the corresponding
url and file table which is the child table which has got the FK key points
to the corresponding project (parent)table.

Following is the code I wrote for inputting the multiple url upload.

<?php

$number_tot = $number; /*if 3 given in the text box then 3 box to get urls*/

print "<form name=more_url_comp action=more_url_comp.php method=post>";

for($i=1 ; $i<= $number_tot ; $i++)

{

print "More Url $i:<input type='text' name='url_comp_'.$i><br>";

$more_url_comp[] = "url_comp_".$i; /*All the url name array*/

$test = $_REQUEST['url_comp_'.$i]; /*This is not wrking*/

}

echo '<input type="submit" name="more_comp_url" value="Upload Now!">';

print "</form>";

I got really stuck with the following. I don't know who to get the

$test = $_REQUEST['url_comp_'.$i]

in a array. Since the variable $i getting appended in the end. If, on the
other hand, I use array in the name of the text box such as text[], then can
I use serialize and unserialize function. If this can be done then there is
no need to use a separate db table to hold the value for url. Or I am
missing some thing very basic.?

I have not started to implement this with multiple file upload to the
mysql directly. I don't know what could be the problem that will arise in
that situation.

Any help will be very help full. Thanks.

First of all, when setting the url, your current code is generating:

More Url 1:<input type='text' name='url_comp[]'><br>

First of all, IMHO since you're posting the form, you should use
$_POST['xxx'] instead of $_REQUEST['xxx']. Just a little safer; the
former works only with POSTed values; your way works with either $_POST
or $_GET (potential security exposure).

To get it from this array, you can use:

$url_array= array();
foreach ($POST['url_comp'] as $url)
$url_array[] = $url;

Also remember - unless you save these values, i.e. in the $_SESSION,
they will only exist for this one page.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jun 27 '07 #5

P: n/a
Jerry Stuckle kirjoitti:
Rami Elomaa wrote:
>sathyashrayan kirjoitti:
>>>
print "More Url $i:<input type='text' name='url_comp_'.$i><br>";

The line above is producing malformed html, it will print:

More Url 1:<input type='text' name='url_comp_'.1><br>
This is just wrong. The browser will take the name as url_comp_ and
wonder what the heck the .1 is doing there but not taking them into
account.

I assume you wanted:
More Url 1:<input type='text' name='url_comp_1'><br>

To get that, change the code like this:
print "More Url $i:<input type='text' name='url_comp_$i'><br>";


Actually, it will print:

More Url 1:<input type='text' name='url_comp_1'><br>"

Which is correct.
Nope, the script _is_ incorrect and here's an easy way to test it:

Here is my test script:
<?php
$i = 1;
print "More Url $i:<input type='text' name='url_comp_'.$i><br>";
?>

Here is my output:
More Url 1:<input type='text' name='url_comp_'.1><br>

See what I mean?

--
Ra*********@gmail.com

"Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze
Jun 27 '07 #6

P: n/a
Rami Elomaa wrote:
Jerry Stuckle kirjoitti:
>Rami Elomaa wrote:
>>sathyashrayan kirjoitti:

print "More Url $i:<input type='text' name='url_comp_'.$i><br>";
The line above is producing malformed html, it will print:

More Url 1:<input type='text' name='url_comp_'.1><br>
This is just wrong. The browser will take the name as url_comp_ and
wonder what the heck the .1 is doing there but not taking them into
account.

I assume you wanted:
More Url 1:<input type='text' name='url_comp_1'><br>

To get that, change the code like this:
print "More Url $i:<input type='text' name='url_comp_$i'><br>";


Actually, it will print:

More Url 1:<input type='text' name='url_comp_1'><br>"

Which is correct.

Nope, the script _is_ incorrect and here's an easy way to test it:

Here is my test script:
<?php
$i = 1;
print "More Url $i:<input type='text' name='url_comp_'.$i><br>";
?>

Here is my output:
More Url 1:<input type='text' name='url_comp_'.1><br>

See what I mean?
Sorry - you're right. I wasn't thinking about all the quotes.

Teach me to try to update when I'm tired... :-)
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jun 27 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.