Jump to content

display a success message after form is submitted


$php_mysql$

Recommended Posts

how can i disply this message withing the form echo "data submitted successfully!";

 

currently after validation check when data is entered the message show on top of my page not within the form

 


function insertDATA($postData) {		

if(!ifEmailExists($postData['email'])){
$sql = " INSERT INTO tbl SET
		email = '".$postData['email']."',
		name	= '".$postData['name']."',
		phone	= '".$postData['phone']."'
		";
                      echo "data submitted successfully!";//this line withing the form
		executeSql($sql);
}		

function insertDATA($postData) {		

if(!ifEmailExists($postData['email'])){
$sql = " INSERT INTO tbl SET
		email = '".$postData['email']."',
		name	= '".$postData['name']."',
		phone	= '".$postData['phone']."'
		";
                      echo "data submitted successfully!";//this line withing the form
		$res = executeSql($sql);
if($res) {
echo "<img src='path/to/image.jpg'></img.";
} else {
die(mysql_error());
}

}		

 

I don't know if that will work, since you never told us how executeSql works, and you'll have to have the link for the image in the img tag.

 

how can i put html inside a variable?

//make sure there are NO space in your html or you wil lget a unexpected T_SL error
$example= <<<EOF <html><body></body></html> EOF;
echo $example;

 

 

you will need to do IF or ELSE statements to determine what gets outputted where.

 

 

 

 

 

 

 

 

 

 

Not 100% sure if I am understanding what exactly you want but if I am this would work......

 

function insertDATA($postData) {		

if(!ifEmailExists($postData['email'])){
$sql = " INSERT INTO tbl SET
		email = '".$postData['email']."',
		name	= '".$postData['name']."',
		phone	= '".$postData['phone']."'
		";

                      return header(sprintf("Location: %s", 'yourpage.php?success=yes'));
                      //echo "data submitted successfully!";//this line withing the form
		executeSql($sql);
}

 

When the query is sucessful the use will be redirected back to the original page with the message.

 


// yourpage.php


    if(!empty($_GET['success'])){

      if($_GET['success'] == 'yes'){

     $Success = 'data submitted successfully';

}

}

//Then place this where ever you want the message to appear.

if(isset($Success)){

echo $Success;

}

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.