Jump to content

Redirecting Problem.


Shiny_Charizard

Recommended Posts

Is there any way I can redirect the user to another page by using the the header() function and still connecting to my MySQL Database?

If I try redirecting the user after connecting to my database the page gives me an error.

Can any one please help me?

 

 

 

Here is the code:

<?php
#Include Top File
require_once('top.php');

#Include Connect File
require_once('connect.php');

#Display Page Heading 
echo "<center><b>Battle</b></center>
<br />
<br />";

#If The User Has Submitted The Form
if($_POST[submit])
{
#If The Opponent ID Field Is Not Empty 
if(!empty($_POST[opponent]))
{
	#Update The Mysql Table
	mysql_query("UPDATE members SET In_Battle?='Yes',opponent_id='$_POST[opponent]' WHERE user_id='$_SESSION[user_id]'");

	#Redirects The User To The Battle File
	header("Location: battle.php");


	/*echo "<script type='text/javascript'>
        window.location.href = 'battle.php' ;
	</script>";*/

}
#If The Opponent ID Field Is Empty
else
{
	#Display Message
	echo "Please choose a user to battle!
	<br />
	<br />";
}
}

#If The User Is Logged In
if(!empty($username))
{
#Display The Form
echo "<form action='' method='POST' />
<br /> 
<font size='1'>Type the <u>ID</u> of the user you want to battle not the username.</font>
<br />
<br />
<b>Opponet's ID</b>
<br />
<br />
<table rules='rows'><tr><td class='headings'>
<input type='text' name='opponent' />
</td></tr></table>
<br />
<br />
<table rules='rows'><tr><td class='headings'>
<input type='submit' name='submit' value='Battle'  />
</td></tr></table>
</form>";
}
#If The User Is Not Logged In
else
{
#Display Message
echo "<center>
Sorry, you must be logged in to view this page.
<br />
<a href='login.php'>Login?</a>
</center>";
}

echo "<br />
<br />
</td>";

#Include The Bottom File
require_once('bottom.php');
?>

 

Link to comment
Share on other sites

Do the mysql query, just don't output any html.

 

Put this:

#Display Page Heading

echo "<center><b>Battle</b></center>

<br />

<br />";

 

In this else: (Just before the following)

#Display Message

echo "Please choose a user to battle!

<br />

<br />";

 

Same output, but it should work. (Assuming top.php doesn't output any code!)

Link to comment
Share on other sites

<script>

setTimeout("location='index.php'", 3000); // Execute the statement location='index.php' after 3000 miliseconds (3 seconds)

</script>

try this out hope so it will work for u after your processing u can have  this java script to take the user to required page

Link to comment
Share on other sites

I agree fully. That's not a good solution.

 

Change your code to this:

 

#If The User Has Submitted The Form
if($_POST[submit])
{
#If The Opponent ID Field Is Not Empty 
if(!empty($_POST[opponent]))
{
	#Update The Mysql Table
	mysql_query("UPDATE members SET In_Battle?='Yes',opponent_id='$_POST[opponent]' WHERE user_id='$_SESSION[user_id]'");

	#Redirects The User To The Battle File
	header("Location: battle.php");

}
#If The Opponent ID Field Is Empty
else
{
	#Display Page Heading 
	echo "<center><b>Battle</b></center>
	<br />
	<br />";

	#Display Message
	echo "Please choose a user to battle!
	<br />
	<br />";
}
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.