Sending data from html form to php to mysql

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wooflepoof
Forum Newbie
Posts: 3
Joined: Fri May 02, 2008 1:55 pm

Sending data from html form to php to mysql

Post by wooflepoof »

ok my code looks like this an i want to find the best way to go about adding a submit function that sends the data to i guess an array to be checked and then added to the database? can anyone point me in the right direction? thanks. Also, im super new to php and html and coding in general but this all doesn't have to be too dumbed down.


<div class="reg_form">
<div class="regFormn">Middle Name:</div>
<div class="regFormf"><input type="text" id="chef_namem" name="chef_namem" class="regInput" value=""/>
</div>
</div>


<div class="reg_form">
<div class="regFormn">Last Name:</div>
<div class="regFormf"><input type="text" id="chef_namel" name="chef_namel" class="regInput" value=""/>
</div>
</div>

OH its all Xhtml strict and this is for a registration page, i've read plenty books on the subject and theyve only helped so much. I'm running xampp with all default configurations so you know where i should put all the seperate files and stuff i need.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Sending data from html form to php to mysql

Post by Christopher »

PHP will put the data from the submitted form into the superglobal array $_POST (see the manual for a list of these variables). Remember to filter, validate and escape properly before saving to a database.
(#10850)
wooflepoof
Forum Newbie
Posts: 3
Joined: Fri May 02, 2008 1:55 pm

Re: Sending data from html form to php to mysql

Post by wooflepoof »

how do i implement that into the script or do i make a separate one that takes the submitted data or do i put the html into a php script with echo or something and do it from therE?
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Sending data from html form to php to mysql

Post by aceconcepts »

Place some PHP before your form:

The php code below

Code: Select all

 
<?
if(isset($_POST['submit_button']))
{
   //validate form fields
}
?>
 
should go above

Code: Select all

 <form name="form1" method="post">   <input type="text" id="chef_namem" name="chef_namem" class="regInput" value="" />   <input type="submit" name="submit_button" value="Submit" /></form> 
The form submits the fields to itself, thats why an "action" hasn't been specified e.g.

Code: Select all

 <form name="form1" method="post" action="some_other_script.php"> 
wooflepoof
Forum Newbie
Posts: 3
Joined: Fri May 02, 2008 1:55 pm

Re: Sending data from html form to php to mysql

Post by wooflepoof »

Thanks, I'll try it and see how it gos. Also, can anyone explain exactly how this all works? like what happens to the data and how the PHP retrieves it and stuff in detail? It would definitely l make it easier to code if i had a more thorough understanding of how this works beyond "stick this text here", like understanding what the clutch, engine and gearbox are actually doing makes it so much easier to learn stick.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Sending data from html form to php to mysql

Post by aceconcepts »

You're probably going to be hard pushed to find someone who'll explain everything in detail.

You probably want to buy a book and read up on PHP beginner.

Personally, I post code so that a person can play around with it and see how it works for themselves - usually with some brief descriptors.
Post Reply