Reputation: 87
if (isset($_GET['success']) && empty ($_GET['success'])) {
echo 'Thank you for registering your service with us!';
} else {
//if no errors register user
if (empty($_POST) === false && empty($errors) === true) {
$daysavailable='';
foreach ($_POST['DaysAvailable'] as $value)
{
$daysavailable .=$value." ";
}
//$test = "Monday, Tuesday";
$register_info= array (
'MemberID' => $_POST['MemberID'],
'OddJobName' => $_POST['OddJobName'],
'Description' => $_POST['Description'],
'DaysAvailable' => $daysavailable,
);
register_job($register_info);
if(success){
echo"<script type=\"text/javascript\">".
"alert('success');".
"</script>";
exit ();
} else if (empty($errors) === false){
//otherwise output errors
echo output_errors($errors);
}
}
Looking at previous posts I changed my code to add:
if(success){ //ADDED CODE
echo"<script type=\"text/javascript\">".
"alert('success');".
"</script>";
Full code:
if (isset($_GET['success']) && empty ($_GET['success'])) {
echo 'Thank you for registering your service with us!';
} else {
//if no errors register user
if (empty($_POST) === false && empty($errors) === true) {
$daysavailable='';
foreach ($_POST['DaysAvailable'] as $value)
{
$daysavailable .=$value." ";
}
$register_info= array (
'MemberID' => $_POST['MemberID'],
'OddJobName' => $_POST['OddJobName'],
'Description' => $_POST['Description'],
'DaysAvailable' => $daysavailable,
);
register_job($register_info);
if(success){ //ADDED CODE
echo"<script type=\"text/javascript\">".
"alert('success');".
"</script>";
exit ();
} else if (empty($errors) === false){
//otherwise output errors
echo output_errors($errors);
}
}
Now I get a pop up, but on the same page and 'success' is an undefined consent.
What I want to happen is that when the user registers successfully they are redirected to index.php and when this page opens I need a pop up to display telling the user they have registered successfully.
I'm not great with PHP (thats probably clear from the above) so any help would be appreciated!
Upvotes: 0
Views: 2775
Reputation: 938
In your registration page do
if ($success) {
header('Location: index.php?success=true');
}
In your index.php
if ($_GET['success']) {
echo"<script type=\"text/javascript\">".
"alert('success');".
"</script>";
}
Upvotes: 2