PHP forums, MySQL forums, Web Development resources

Home PageHome    PHP ResourcesTopic List    FAQFAQ    SearchSearch    MemberlistMemberlist    UsergroupsUsergroups 
 RegisterRegister
    ProfileProfile    Log in to check your private messagesLog in to check your private messages    Download the RSS Reader RSS Feed Download the RSS Reader RSS for this forum Log inLog in 

PHP Forum :: MySQL Forum :: Java Script Forum



I need help with php_self and forms

 
Post new topic   Reply to topic    WeberForums.com Forum Index -> PHP General
View previous topic :: View next topic  
Author Message
peterv



Joined: 02 Jul 2009
Posts: 2
Location: Leominster, MA

PostPosted: Thu Jul 02, 2009 7:33 pm    Post subject: I need help with php_self and forms Reply with quote

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.
Back to top
View user's profile Send private message Send e-mail
lostboy



Joined: 02 May 2004
Posts: 5915
Location: toronto, canada

PostPosted: Fri Jul 03, 2009 3:52 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Send e-mail AIM Address MSN Messenger
Display posts from previous:   
WeberTrivia Questions WeberTrivia Questions
 Think you are smart? Prove it!. Try your skills with these questions :
 WeberTrivia QuestionsRecursive arrays and multi-dimensional arrays are one and the same. (PHP and MySQL)
 WeberTrivia QuestionsThe \"cache_dir\" tag of the squid configuration has a default of /var/spool/squid. (Linux)

WeberTrivia Questions



Post new topic   Reply to topic    WeberForums.com Forum Index -> PHP General All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
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
You cannot vote in polls in this forum






Powered by phpBB © 2001, 2005 phpBB Group
PHP Forum :: MySQL Forum :: Java Script Forum