473,386 Members | 1,819 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,386 software developers and data experts.

PHP equivalent of ASP code

Hi all,

Im trying to duplicate this ASP code in PHP.

Basically its a form of 10 records pulled from an MySQL table. The
form lets the user update all 10 records at once if they want to.

Each text box I name using the ID of the database record and the
Database Field. Example: 3|Name (3 is the ID and Name is the
database field)

When the form is submitted this code is run:

for x = 1 to request.form.count()
if request.form.key(x) <> "Submit" then
curFld = request.form.key(x)
aryCats = split(curFld, "|")

ID = aryCats(1)
Field = aryCats(2)
Data = request.form(curFld)

strSQL = "UPDATE " & Table & " Set " & Field & "= '" & Data "'
WHERE ID = " & ID
'response.write strSQL
conn.execute strSQL

end if
next

The code loops thru all the objects on the form. It takes each object
name and splits it into an array using the | in the object name.

Is there anything in PHP that will count the number of objects on a
form and let you loop thu them like this script?

Thanks in advance,

Mark
ma********@ermsolutions.com
Jul 16 '05 #1
7 7803
ma**@ermsolutions.com (Mark) wrote in message
news:<a5**************************@posting.google. com>...

Im trying to duplicate this ASP code in PHP.

for x = 1 to request.form.count()
if request.form.key(x) <> "Submit" then
curFld = request.form.key(x)
aryCats = split(curFld, "|")
ID = aryCats(1)
Field = aryCats(2)
Data = request.form(curFld)
strSQL = "UPDATE " & Table & " Set " & Field & "= '" & Data "'
WHERE ID = " & ID
'response.write strSQL
conn.execute strSQL
end if
next
Well, if I follow your naming conventions, here's what I get:

foreach ($_REQUEST as $curFld => $Data) {
if ($curFld <> 'Submit') {
list ($ID, $Field) = explode('|', $curFld);
$strSQL = "UPDATE $Table SET $Field = '$Data' WHERE ID = $ID";
echo $strSQL;
$result = mysql_query ($strSQL)
or die ("Query failed: $strSQL");
}
}

Obviously, I don't know what database you are using, so I put in
a call to mysql_query(). If you are not using MySQL, you should
replace it with a function call appropriate for your database engine.
Is there anything in PHP that will count the number of objects on a
form and let you loop thu them like this script?


As you can see from the code above, in PHP you don't have to know
the number of elements in array to loop through it; foreach() takes
care of that for you...

Cheers,
NC
Jul 16 '05 #2
Nikolai Chuvakhin wrote on Thursday 04 September 2003 19:01:

Just couple of additional comments:

<snip>
for x = 1 to request.form.count() <snip>
foreach ($_REQUEST as $curFld => $Data) {


<snip>

If I am not mistaken, Request.Form is equivalent of $_POST
Is there anything in PHP that will count the number of objects on a
form and let you loop thu them like this script?


As you can see from the code above, in PHP you don't have to know
the number of elements in array to loop through it; foreach() takes
care of that for you...


It's also worth pointing out that if one was implementing a similar process
in PHP, one would simply use array elements as form element names, such as
ID[0], ID[1], etc., and then there wouldn't be a need to count or go
through all form elements, or implement an ugly hack of separating their
names by | either (which actually restricts how and in what order form
elements are submitted). Maybe of interest to the OP.

--
Business Web Solutions
ActiveLink, LLC
www.active-link.com/intranet/
Jul 16 '05 #3
Thanks for all the input.

Sorry I didnt mention that I can successfully update the records in
MySQL.

Also, the beauty of the asp code is I dont have to know the field
names. If I use array elements wouldnt I need to know the field names
before hand?

Basically I need to write this code and walk away for a couple years.

Ive given the users a tool that lets them update a table (add fields)
and that field would thn appear on the form. Completely dynamic and
out of my hands.

Assume that everything works. Have had this system working in asp for
3 years now. But I really want to move to linux and PHP.

would this also do the trick?
foreach($HTTP_POST_VARS as $key => $value)

Thanks

Mark
Jul 16 '05 #4
On 4 Sep 2003 14:44:23 -0700, ma**@ermsolutions.com (Mark) wrote:
Hi all,

Im trying to duplicate this ASP code in PHP.

Basically its a form of 10 records pulled from an MySQL table. The
form lets the user update all 10 records at once if they want to.

Each text box I name using the ID of the database record and the
Database Field. Example: 3|Name (3 is the ID and Name is the
database field)

When the form is submitted this code is run:

for x = 1 to request.form.count()
if request.form.key(x) <> "Submit" then
curFld = request.form.key(x)
aryCats = split(curFld, "|")

ID = aryCats(1)
Field = aryCats(2)
Data = request.form(curFld)

strSQL = "UPDATE " & Table & " Set " & Field & "= '" & Data "'
WHERE ID = " & ID
'response.write strSQL
conn.execute strSQL

end if
next

The code loops thru all the objects on the form. It takes each object
name and splits it into an array using the | in the object name.

Is there anything in PHP that will count the number of objects on a
form and let you loop thu them like this script?

Thanks in advance,

Mark
ma********@ermsolutions.com


Have you tried ASP2PHP and see what that does?

Jul 16 '05 #5
Zurab Davitiani <ag*@mindless.com> wrote in message
news:<vD******************@newssvr25.news.prodigy. com>...

<snip>
for x = 1 to request.form.count()

<snip>
foreach ($_REQUEST as $curFld => $Data) {

<snip>

If I am not mistaken, Request.Form is equivalent of $_POST


I couldn't remember, so I put in $_REQUEST just in case; it should
work anyway... Also, I've seen some ASP developers do stuff like
this:

<form method="post" action="do_something.asp?id=48">

I don't even want to guess what happens there... :)

Cheers,
NC
Jul 16 '05 #6
"Nikolai Chuvakhin" <nc@iname.com> wrote in message
news:32*************************@posting.google.co m...
<form method="post" action="do_something.asp?id=48">

I don't even want to guess what happens there... :)


There's nothing wrong with that... You have your form elements in $_POST and
the 'id' value set in $_GET.
Jul 16 '05 #7
<ba***@blues.no> wrote in message
news:<T4*********************@news2.telusplanet.ne t>...
"Nikolai Chuvakhin" <nc@iname.com> wrote in message
news:32*************************@posting.google.co m...

<form method="post" action="do_something.asp?id=48">

I don't even want to guess what happens there... :)


There's nothing wrong with that... You have your form elements
in $_POST and the 'id' value set in $_GET.


This is exactly why I used $_REQUEST in my code snippet...

Cheers,
NC
Jul 16 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Hai Nguyen | last post by:
I'm learning C sharp and do not like vb much. I'm creatiing a wepage using panel to test myself. I tried to use these code below, which is written in VB, and to transform them to c sharp but I got...
8
by: Xucyr | last post by:
I can't find any "short" code to make this work without taking 100s of lines (because I have to keep repeating this process several times). But this is what I have so far: int i = 7; do {...
9
by: Alan Silver | last post by:
Hello, I'm converting some old VB6 code to use with ASP.NET and have come unstuck with the Asc() function. This was used in the old VB6 code to convert a character to its ASCII numeric...
48
by: Daniel Crespo | last post by:
Hi! I would like to know how can I do the PHP ternary operator/statement (... ? ... : ...) in Python... I want to something like: a = {'Huge': (quantity>90) ? True : False} Any...
14
by: grid | last post by:
Hi, I have a certain situation where a particular piece of code works on a particular compiler but fails on another proprietary compiler.It seems to have been fixed but I just want to confirm if...
5
by: lcw1964 | last post by:
Greetings again, I will burden the group with yet another tenderfoot question, but since conscientious googling hasn't yield a lucid answer I thought I would risk the shortcut of asking here...
8
by: Jon Paal | last post by:
what is vb equivalent to this C# code ? converters failed to handle this "using (SQLiteTransaction mytransaction = myconnection.BeginTransaction())"
6
by: Jon Paal | last post by:
what is vb equiv. of ++ shown in C# ?
22
by: Kurien Mathew | last post by:
Hello, Any suggestions on a good python equivalent for the following C code: while (loopCondition) { if (condition1) goto next; if (condition2) goto next;
11
by: gnuist006 | last post by:
Is there a Delphi equivalent in the C world or Scheme/LISP world ? Recently, Delphi is in resurgence. In Russia people are using like crazy. For example, Bolega has written a free image...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.