473,385 Members | 2,243 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,385 software developers and data experts.

Call a local function or a separate PHP file?

Hello,

I want to write some code such that it'll update (ie insert, delete, etc)
some data to/from a mySQL database whenever a user hit an HTML form button
(ie Submit). Now what I find annoying is that this form can only, from my
understanding, execute a separate PHP file with the <form
action=removerow.php> code. Or can I call a function?

The reason being I find that the form will only pass a single variable to
this "removerow.php" whereas I have a few data that I want to pass onto a
function for execution. For example, if I want to display a table of
multiple rows of data queried from a database, with a check box next to each
row for the user to select for deleting from the database, I need to use an
array variable to store the list of rows that need to be removed and pass
this variable to "removerow.php". So I don't know how or if I can pass
other information stored in other variables as well to "removerow.php". Can
someone please clarify?

Also what I'm not sure if it is true or not. But it appears that whenever
PHP begins executing a different PHP file, all global variables that exist
from the previous PHP file are lost! Is this true? For example, all my
other variables information are lost when "removerow.php" executes.

Can I have it such that "removerow.php" don't need to be called and the PHP
script can call instead a local function to execute the job?

Thanks
Jul 17 '05 #1
2 11437
Titus Cheung wrote:
Can I have it such that "removerow.php" don't need to be called and the PHP
script can call instead a local function to execute the job?


No. PHP is an interpretor that executes as the web server (usually
Apache) is being asked for the page. Once the page has been given to the
user, PHP has done its job. To run more script, another page has to be
called for, and so on. That is server-side scripting.

You're thinking of client-side scripting (such as - spit, curse -
JavaScript). That is executed by the web browser (which is why it will
work for some users, and throw object errors for most others).

However, you're obviously new to server-side scripting, and you haven't
learned the tricks of the trade. Here are the basics.

A form calls another PHP page using the action='php-page.php' attribute
in the form tag. If you are going to do something 'unique' with the data
that you pass to php-page.php, such as update a database, which you will
only want to happen once for that data, then you should set method to
POST. So this gives you something like this:

<form action='php-page.php' method='post'>

If the data is just used to do something common, such as call a list of
results that people are going to want to be able to see over and over
again, then use method='get'. The GET method puts the data into the URL
itself, so the URL can be cached. POST does not allow caching, and the
data is passed as part of the HTTP request.

You also state that only one variable can be sent to a PHP page in a
form. This is not true at all. You can send as much as you like (in a
POST method; GET has limits on how much can fit because it goes into the
URL).

An example form with multiple variables would be:

<form action='php-page.php' method='post'>
<input type='text' name='userInput' maxlength='20' />
<input type='checkbox' name='checkboxArray[]' value='box1' />
<input type='checkbox' name='checkboxArray[]' value='box2' />
<input type='checkbox' name='checkboxArray[]' value='box3' />
<input type='hidden' name='globalVar' value='".$globalVariable."' />
<input type='submit' value='Click Here to Submit' />
</form>

The text type allows a user to put text into a text field; the checkbox
type allows multiple items to be selected and stored in the
checkBoxArray[] variable (notice that each checkbox element of the same
group must have the same name, and must end with [] square brackets);
the hidden type allows you to add unseen variables to a form so that
they don't interfere with the user, but they will be passed to the page
mentioned in action.

Hopefully this answers the questions you have raised in your posting.
However, there is much more to forms if you need more. Try www.w3c.org,
the home of WWW standards, for more form elements. www.htmlgoodies.com
is also very good. And, of course, the PHP manual.
--
Bob
London, UK
echo Mail fefsensmrrjyaheeoceoq\! | tr "jefroq\!" "@obe.uk"
Jul 17 '05 #2
"Titus Cheung" <ti***@ieee.org> wrote in message news:<WUbCb.671953$9l5.307287@pd7tw2no>...
Hello,

I want to write some code such that it'll update (ie insert, delete, etc)
some data to/from a mySQL database whenever a user hit an HTML form button
(ie Submit). Now what I find annoying is that this form can only, from my
understanding, execute a separate PHP file with the <form
action=removerow.php> code. Or can I call a function?

<snip> Also what I'm not sure if it is true or not. But it appears that whenever
PHP begins executing a different PHP file, all global variables that exist
from the previous PHP file are lost! Is this true? For example, all my
other variables information are lost when "removerow.php" executes.


This is correct. You can deal with this problem by using sessions.
Check out http://www.php.net/manual/en/ref.session.php

Tony Marston
http://www.tonymarston.net/
Jul 17 '05 #3

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

Similar topics

11
by: alex | last post by:
Hi, I am looking for a way to populate an HTML table from an external local text file which looks like this: DATE/TIME LAT. LON. DEPTH. ML....
5
by: Sue | last post by:
After finishing up my first quarter JavaScript on 12/12/03, I decided to improve character checking on my project. In my project I only had to do very basic validation. Therefore, I only had one...
1
by: sunil s via DotNetMonster.com | last post by:
Hi, I've got a native C++ app which calls a 3rd parth .NET DLL using the LoadLibrary/GetProcAddress functions. This works fine when the DLL is located in the app directory, but if I move it out...
4
by: Peter Ammon | last post by:
I would like to share a variable between two functions defined in two separate source files; no other functions will need the global variable so I'd prefer to not give it file scope. Thus, I want...
24
by: Jazper | last post by:
hi i have this problem. i made a class deverted by CRootItem with implementation of IDisposable-Interface. i made a test-funktion to test my Dispose-Method.... but when set a breakpoint in my...
6
by: Brad | last post by:
I have a win2003 server workstation with multiple webs, each web has it's own ip address. In VS2005, if I select to open an existing web site, select Local IIS, the dialog correctly displays a...
2
by: MyCrystalGift | last post by:
Hi, I have an old C++ GUI Application CPPAPP.exe that calls a C DLL library RULE.DLL through a C++ class wrapper LoadRule.CPP. Now I need to call the C DLL RULE.DLL from C# GUI application...
11
by: cj | last post by:
Perhaps someone knows how to do this. When I open a new ASP.NET web service application in VS 2008, it opens with a simple Hello World web service already written. I want to see this work. ...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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.