PDA

View Full Version : Beginners PHP Video 9


songboy
02-17-2009, 05:58 PM
Could someone explain why the entries in the form fields disappear as the entries appear in the data table. I'm using the tutorial as a starter model for my own website login and when I try it out, the entered data stays in the fields.
(PS I'm sending the post data to another program just to try things out.)

davidj
02-17-2009, 07:46 PM
post your code

songboy
02-17-2009, 09:05 PM
<?php
//call into play the connection program//
include("connection.php");

//the input data you get from the user eg his email address, is turned into boxed data (or variables)//
$first_name = $_POST['first_name'];
$second_name = $_POST['second_name'];
$email_address = $_POST['email_address'];
$confirm_email_address = $_POST['confirm_email_address'];
$password = $_POST['password'];
$submit = $_POST['submit'];

//If the form fields are filled, put the response data into the database//
if($first_name && $second_name && $email_address && $password && $submit)
{
$query = sprintf("INSERT into new_visitor_login (first_name, second_name, email_address, password)
values ('$first_name', '$second_name', '$email_address', '$password')");
mysqli_query($cxn,$query) or die (mysqli_error($cxn));
}
//If any of the fields are empty and the submit is pressed echo a message//
elseif ($submit)
{
echo "All fields need to be completed.";
}
?>
This is my code. It's a separate file ie it's not returning to the same page. The form action is pointed to the code above. It all works fine except:
1. on submit the form page goes (I have worked out that I will need to
include the page back again), the echoed message appears on the
new, blank page
2. the test entries stay in the form fields (they are there when you call
the page back - your fields empty on submit),
3. the data appears in SQL Manager (brilliant !) but you have to press the
refresh tick for it to appear (maybe that's normal)
Thanks - songboy

davidj
02-17-2009, 11:45 PM
1. dont understand this

2. if your using the browser back button then the data will redisplay

3.remember that your select statment has to come after the update