Jump to content

Simple PHP Form


Styles2304

Recommended Posts

I'm working on an update method for my Church's website and I was wanting to do something where certain individuals could login to a "control panel" and be able to add certain information such as events or a little blurb about something.

 

I already have the login and control panel the way I want them and I'm guessing for them to be able add "events" (paragraphs of information) to a list, I would need to append a document with an array of the information they fill out on the form.

 

My real problem is that I don't know how to actually process the entered information on the page itself. I know it should probably be like foreach array do this . . . but I'm not quite sure how to go about telling php to spit out html so that the page looks presentable.

 

Does that make sense? If I'm not clear at all, please, just say something and I'll try to say it again as clearly as possible.

Link to comment
Share on other sites

Yes, but doing this flatfile (as you are suggesting with appending a document) is like jabbing yourself with a rusty knife, instead look into mysql which is very good for events.  (Let me know if you need help I have an event script I can share with you, but you have to understand mysql/php to use it.)

Link to comment
Share on other sites

You will need to learn how to store data properly, retrieve data and how to build a table structure.

 

MySQL is quite a bit different and sometimes hard for people to grasp the concept. Your main focus will be on SELECT statements, INSERT statements and UPDATE statements.

 

You will also need to look into PHP While loops for retrieving data along with arrays. Along with mysql_connect; mysql_query; mysql_fetch_array; via PHP.net.

 

But the key is to keep everything in Third Normal Form (3NF) google will have a bunch of articles/pages on that.

 

Table structure and setup is important to keep a site running fast, clean and efficient.

 

 

On another note it can be done with files, like stated above it is a pain in the ass to work with them because you have to open read them parse them append them and re-write them all in while that is happening no one else can work with that file. Which is why MySQL is preferred. Especially given that it is 1,000x faster than a file database could ever be, with searching sorting selecting etc.

Link to comment
Share on other sites

Ok! So I've learned some php . . . enough to actually create/modify/maintain a database as well as how to do that through php. The only thing I'm confused on now is how to setup the loop statement so that for every block of information, it spits it out in a table.

 

Basically, I'm not quite sure how to get the MySQL data into an array. Can someone give me an example?

 

Also! Can you explain it line by line just so I know we're on the same page. If not, no worries, I should be able to figure it out.

Link to comment
Share on other sites

  • 2 weeks later...

Very simply:

 

$my_query = mysql_query("SELECT * FROM churchinfo;");

while($info = mysql_fetch_array($my_query))
{
     print "$info[name]<br>";
     print "$info[email]<br>";
     print "$info[age]<br><br>";
}

 

The first line sends a query to the database, to select all info from a table called "churchinfo". This is stored in $my_query. Right now, $my_query is kind of like a two-dimensional array, holding rows of arrays with your information.

To get the information for each row, use a while loop and mysql_fetch_array();

 

So if your database table is something like this:

 

Name             Email                     Age

John              john@blah.com       24
Mary             mary@blah.com       35
Bob               bob@blah.com        27

 

Your output from the while loop will look like this:

 

John              
john@blah.com       
24

Mary             
mary@blah.com       
35

Bob               
bob@blah.com        
27

 

Hope that explains something. >.< Someone out there can probably do a better job.

Link to comment
Share on other sites

Ok, well that certainly makes sense . . . However, I'm wanting to spit out each chunk of information in it's own table . . . so can I just throw in the standard html for tables in the while statement?

 

Also, I thought you had to use a for statment and $i to do a loop or something. Is that not right?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.