Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

new PHP developer, form question.

Status
Not open for further replies.

bdina

Programmer
Jun 17, 2003
47
US
I have a short form for a simple PHP enabled website that I am having problems to get working correctly. My background is mainly C and C++ programing, and have only picked up HTML/PHP in the last week so bear with me. Anyway, what I want to do is simple, I have a table on a page that lists information, and then a single text box that allows input from the user to change the attributes of the data that is displayed in the table. What I want is for the data to be refreshed in the table when a user changes the data. Currently the data does get updated however one must refresh the page manually in order to see the changes. Here is the pseudo code:

<begin PHP>
<database login info>

while(info in database)
grab data from table.

while(array of data)
display data in table, one row at a time.

<end PHP>
<begin HTML>

display form, single text box.

<EOF>

If that pseudo is not enough, I can post more, I just did not want this post to get outta control. Please also when answering not answer with pseudo, I am new to the syntax.

Thanks in advance!
Bryan
 
First of all, let's talk about programming style in PHP. There are two basic coding styles in PHP: one style switches between PHP-interpreted mode and HTML output mode, the other stays in PHP-interpreted mode and uses print or echo statements to output HTML.

I recommend the latter. As programs get more complex, I've found that readability becomes an issue with context-switch mode.

In terms of your problem getting the page updated on a submit, I recommend that you write your script such that if data is submitted, it processes the submission. Then it outputs the page.

The pseudo-code will look something like:
Code:
<begin PHP>
<database login info>

if (data is submitted)
   perform update.

while(info in database)
   grab data from table.

print HTML preamble and start-of-form and start-of-table tags

while(array of data)
   display data in table, one row at a time integrated with form fields.

print end-of-table, end-of-form and HTML postamble.
<end PHP>
<EOF>

Testing for the presence of input entails examining $_POST or $_GET to see whether a field which would be in your form exists in those arrays. Use isset() or array_key_exists() to perform the check.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top