Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert script to return original web page

Status
Not open for further replies.

arunrr

Programmer
Oct 2, 2009
103
US
Hello...

I had posted the following in correctly in javascript forum...
----------------------------------------------------------
To understand the problem, please visit my website,
On the polling form (which by the way is a separate html, displayed via the <iframe> tag), when the user completes the form and selects "Submit", the DB insert (via load.php) works fine, but the page changes to different target.

How can I make the page return to the original page with a blank form?

the form html file can be viewed at:
Thanks,
Arun
----------------------------------------------------------

To which i received the reply....

<?php

/* ... all current load.php code ... */

header('Location:
?>

Note : you must not output content before the header() call.
----------------------------------------------------------

The following is my script. You can see the header() call in the beginning. This accomplishes what i am looking to do. However, The 2 messages from script do not display. Help is appreciated...

Thanks,
Arun

------------------------------------------------------------
<?php
header('Location: $con = mysql_connect("localhost","bccicom","arunraj1");
$table = survey_001;

if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db(bccicom_BCCI);

$sql="INSERT INTO $table (Email, Country, Choice)
VALUES ('$_POST', '$_POST[Country]', '$_POST[Choice]')";

$query = "SELECT Email FROM $table WHERE Email = '$_POST[Email]'";
$result = mysql_query($query);
if (mysql_num_rows($result) > 0)
{
echo "<script>alert('You have already voted for this opinion poll')</script>";
die ();
}

if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}

echo "<script>alert('Thank you for voting!! Results update periodially!')</script>";

mysql_close($con);

?>
 
Since your code effectively redirect the browser to another page before anything else is done, it would be hard for anything to be displayed, if the rest of the code is not actually getting run.

Now since you can't output anything to screen prior to sending the header() call you are left with several options.


1. Use Javascript to alter the window.location after having displayed the messages.

2. Send a the messages in the url of the header call, and retrieve them there by a number of methods,

3. Have the database processing occur in the same page as the form, and then display the messages there, thus avoiding the need to use the header call.




----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Hi

arunrr said:
However, The 2 messages from script do not display.
Would be helpful to know from the beginning that you want to display anything and only after that return to the poll page...

Personally I would go with Phil's 3. suggestion.

But while we are in the PHP forum, you could change the [tt]header()[/tt] call :
Code:
[COLOR=darkgoldenrod]header[/color][teal]([/teal][green][i]'Refresh: 5; url=http://www.bcci.com/poll.html'[/i][/green][teal]);[/teal]

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top