I am converting all the values from xml to CSV successfully in the 2nd page(Export page). But i want to display a message "data converted successfully" in the first page(seat-matrix ).
I am failing to display the message in seat-matrix.php (1st page). Please help me.
In "Seatmatrix.php" file I have the following code.
<form nam开发者_JAVA技巧e="export" action="export.php">
<input type="submit" name = "export" value="Export" title ='Exports all the above info to excel'>
</form>
In export.php file I have alert function and included header function to redirect to seat-matrix page as show below.
<?php
echo "
<html>
<head>
<SCRIPT LANGUAGE='javascript'>
function Result() {
alert (\"Data exported successfully\");
}
</SCRIPT>
</head>
<body>
";
// export feature code
echo "<SCRIPT LANGUAGE='javascript'>Result();</SCRIPT>\n";
header('location:Seat_matrix.php');
?>
Javascript doesn't get run until the browser gets it. Because of the header redirect it will never get run in the browser.
Your best bet is to set a session variable, then check if it is set in Seat_matrix.php. If it is, add your javascript.
A simpler way would be to post the result back to the original page and have it check. You would need to change your code to something like this:
if (isset($_GET['result']) {
if ($_GET['result'] == "success") {
echo "Data exported successfully.");
}
else {
echo "Error exporting data.";
}
}
<form name="export" action="export.php">
<input type="submit" name = "export" value="Export" title ='Exports all the above info to excel'>
</form>
And in the other code add the result variable to the url:
header('location:Seat_matrix.php?result=success');
Summary:
The first time you call Seat_matrix.php, there is no result variable and it program runs at it does now. Once the second program is executed, it calls back Seat_matrix.php and passess the variable result. The second time Seat_matrix.php is called, it checks if the result variable was passed and shows the message. You will probably have to play a little bit with the location where you want the message.
I hope this helps. Good luck!
Edit
To get rid of the $_GET variable after you write the success message, you could try something like:
if (isset($_GET['result']) {
if ($_GET['result'] == "success") {
echo "Data exported successfully.");
}
else {
echo "Error exporting data.";
}
unset ($_GET);
}
I haven't tested the above method, but I believe it might work.
You can use JavaScript to do the redirect instead:
<SCRIPT type='text/javascript'>
alert ('Data exported successfully');
window.location = 'Seat_matrix.php';
</SCRIPT>
精彩评论