It is currently Tue Feb 07, 2012 8:06 am

All times are UTC + 2 hours [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: I need help with php_self and forms
PostPosted: Thu Jul 02, 2009 8:33 pm 
Offline

Joined: Thu Jul 02, 2009 8:26 pm
Posts: 2
Location: Leominster, MA
I have created a combo php/html form that accepts user input. I want to send the fields the user inputs to a MySQL database. I have something set up that works, but the "action" in the form section points to another php script file. I've read that if the PHP_SELF variable is used in the "action" field of the form you can check to see if the form has been submitted, and that the form will be redisplayed after submission. What I haven't seen, or been able to figure out, is how does the data get passed to MySQL? I'm using a separate script. I'm very new to this, so any help or suggestions, or even examples would be greatly appreciated.
Peter V.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 03, 2009 4:52 pm 
Offline

Joined: Sun May 02, 2004 11:34 pm
Posts: 6498
Location: toronto, canada
PHP_SELF passes the data back to the same page, where you could have functions that show the form, functions that process the from and functions that do something with the data (like email and save to a database)

Code:
<?php

if(isset($_POST['submit']))
{
  processForm();
}else{
  showForm();
}

function processForm()
{
  //clean and validate data here
  //all data gets put into $arrayData



  //call function to save t db
  saveData($arrayData);

  //call to email the data
  function emailData($arrayData);
 
}

function showForm($data='')
{
  //show form
  //$data is the array that holds the values of the form for redisplay
}

function emailData($data)
{
  //create email message
}

function saveData($data)
{
  //really this should be in an include file that holds a variety of DB
  //functions like saveData, getData, deleteData, updateData
  //more of a DB class of some kind
}

_________________
Lostboy

Cat, the other other white meat

Please read Posting Etiquette before posting

You can always try Google


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 2 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron