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!
Hello; was wondering exactly the in's and outs of inputing data from a from into mysql table, I developed the input page in html and presume that I need an insert function; do I put it on the same form or on another form such as check.php.
Here is the input texts I have put.
in generall i say it is a good idea to separate the steps into files. I hadn't do this in the past, and it is not very good, when you want to do a review or make some changes...
It is a good beginning to check the formulardata in the same skript, and when the data is valid give it to a second skript that do the further processing with the data.
first point to the same file (with $PHP_SELF or $_SERVER['PHP_SELF']):
<?php
if(!empty($_POST['whatever'])){
//process the form here
}
require_once 'theform.php';
This way it's easier to prefill in the form values with the ones they just submitted. If there are 10 fields to fill in, and only one of them is invalid (eg they forgot to fill in their last name) then rather than have them fill it all up again you can prefill the values they previously entered.
<?php
if(1 == $_POST['sent'])
{
//do the second step
}elseif(2 == $_POST['sent'])
{
//do the third step
}else
{
//this is the first (and the fourth if you mad a loop, sometimes very useful)
}
?>
I normally separate my PHP scripts from my HTML form, but whatever you do before you can insert data into Mysql you need to be able open the for use the fopen() function and call the fields in your form using $_POST ['Fieldname']
eoinmick wrote:Do not really understand whet either of you are saying or where exactly to code it...Sorry only new to php.
By "uploading" the variables with the Submit button to the same page, you save the user the hassle of re-entering the values if one is unvlaid or something.
<?php
//set up the checkers to make sure the values are all there:
if(!empty($_POST['username'])){
//this page here does all the inserting and whatnot with MySQL:
include('next_page.php');
}
?>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
<input type="text" name="username">
<input type="submit">
</form>
Now, I haven't done it like this before, but I guess it works from what the others have said.