Jump to content

php header code is opening in new tab


Justafriend
Go to solution Solved by mac_gyver,

Recommended Posts

first off i know all 4 headers im using are same its temporary for now  eventually i will have 4 different  confirmation pages

 

The issue im having is all 4  are processing form correctly into the  db but  the confirmation pages are redirecting to a new tab here is the php  code if needed i can supply the html code as well but seeing the header is being pulled from the php file i think thats where it is

 

what i want is that when the html form processes  that it redirects the page to one of the four  confirmation pages instead of in a new tab

 $conn = mysqli_connect($servername, $username, $password, $dbname);
 // Check connection
 if (!$conn) {
     die("Connection failed: " . mysqli_connect_error());
}
 if(isset($_POST['choices']) && !empty($_POST['choices'])){
        if($_POST['choices'] == 'four'){
             $sql = "INSERT INTO ballot (username, useremail, randomnumber, neptune)
 VALUES ('".$_POST["username2"]."','".$_POST["email"]."','".$_POST["randomnumber"]."','".$_POST["neptune"]."')";
$sql1 = "INSERT INTO ballot (username, useremail, randomnumber)
VALUES ('".$_POST["username2"]."','".$_POST["email"]."','".$_POST["randomnumber3"]."')";


if (mysqli_query($conn, $sql)) ;
if (mysqli_query($conn, $sql1)) ;


mysqli_close($conn);
{
{
header("Location: http://justtheway.com/wb/events/pawn/get2ticketconfirm.php") ;

}
}

        }elseif($_POST['choices'] == 'twoorless'){
            $sql = "INSERT INTO ballot (username, useremail, randomnumber, neptune)
 VALUES ('".$_POST["username2"]."','".$_POST["email"]."','".$_POST["randomnumber"]."','".$_POST["neptune"]."')";
if (mysqli_query($conn, $sql)) ; 
      
mysqli_close($conn);
{
{
header("Location: http://justtheway.com/wb/events/pawn/get1ticketconfirm.php") ;

}
}
	   }elseif($_POST['choices'] == 'sixseven'){
                        $sql = "INSERT INTO ballot (username, useremail, randomnumber, neptune)
 VALUES ('".$_POST["username2"]."','".$_POST["email"]."','".$_POST["randomnumber"]."','".$_POST["neptune"]."')";
$sql1 = "INSERT INTO ballot (username, useremail, randomnumber)
VALUES ('".$_POST["username2"]."','".$_POST["email"]."','".$_POST["randomnumber3"]."')";


if (mysqli_query($conn, $sql)) ;
if (mysqli_query($conn, $sql1)) ;
{
{
header("Location: http://justtheway.com/wb/events/pawn/get2ticketconfirm.php") ;
}
}
        }elseif($_POST['choices'] == 'fiveorless'){
                         $sql = "INSERT INTO ballot (username, useremail, randomnumber, neptune)
 VALUES ('".$_POST["username2"]."','".$_POST["email"]."','".$_POST["randomnumber"]."','".$_POST["neptune"]."')";
if (mysqli_query($conn, $sql)) ;
   
mysqli_close($conn);
{
{
header("Location: http://justtheway.com/wb/events/pawn/get1ticketconfirm.php") ;

}
}     } 
}else{
     echo "Please select once choice for submit query!";
}


mysqli_close($conn);
{
{
header("Location: http://justtheway.com/wb/events/pawn/get1ticketconfirm.php") ;

}
}

 ?> 
Link to comment
Share on other sites

  • Solution

the header('location: ...') is only telling the browser to make a http request for a page. if this is causing a new browser tab to open, there must be something somewhere else in the code on the page to cause it. this is not being caused by the header() statement.

 

why do you have so much repetition in your code? this just makes for a lot of extra work for you, especially when you need to fix or change anything in the code. currently, you need to add protection against sql injection for all those queries, which there are actually only two different variations of a single query. by refactoring your code so that the sql query statement only exists once, adding sql protection, or changing anything about the query, would only have to be done in one place.

Link to comment
Share on other sites

there are 4 different types of  entries
there is singles getting 2 ballots

​there is singles getting 1 ballot

there is pards getting 2 ballots

and there is pards getting 1 ballot

 

Eventually each code will be going to its own confirm  submission page as i stated above  my post hence why i have 4  different  queries

 

ok i will have to look through the html code i just thought  that once  the php processes a query it doesnt  use the  code on the page  that sent the info but i do appreciate your help and appreciate the direction

Link to comment
Share on other sites

javascript does not provide any protection for the server-side code. any value that anyone or a bot script wants, can be submitted to the server-side code, without using any of your client-side code (other than to learn the field names to use.) the server-side code must have protection in it.

  • Like 1
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.