Page 1 of 1

Sending data from html form to php to mysql

Posted: Fri May 02, 2008 2:00 pm
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.

Re: Sending data from html form to php to mysql

Posted: Fri May 02, 2008 2:08 pm
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.

Re: Sending data from html form to php to mysql

Posted: Fri May 02, 2008 2:11 pm
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?

Re: Sending data from html form to php to mysql

Posted: Fri May 02, 2008 2:20 pm
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"> 

Re: Sending data from html form to php to mysql

Posted: Sat May 03, 2008 9:02 pm
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.

Re: Sending data from html form to php to mysql

Posted: Sat May 03, 2008 9:12 pm
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.