如何使用PHP从一个页面导航到另一个页面

如何使用PHP从一个页面导航到另一个页面

问题描述:





在我的作业中,我试图使用php从一个页面导航到另一个页面。这个当用户注册啊想要导航到一个欢迎页面,让用户知道他们现在是一个注册成员,但我遇到的问题是,它将导航到登录页面一分钟而另一次它会破坏虽然在浏览器中你看到它试图导航到welcome.php,但它崩溃了。如果它是某个东西,欢迎.php页面是什么导致它或我正在使用的代码是问题。虽然我已经使用了标题功能并且它仍然无法工作,但是无法分辨哪个是什么?



有人可以告诉我出了什么问题,可能还有一双额外的眼睛会非常感谢。这是两页的代码。



我尝试过:



这里是第一个代码



hi

in my assignment, i am trying to navigate from one page to another using php. the this when a user register ah would like to navigate to a welcome page letting the user know that they are now a register member but the problem i am having is that one minute it would navigate to the login page instead and another time it would break down but in the browser u are seeing like it trying to navigate to the welcome.php but it break down. dont if it is something int the welcome.php page is what causing it or the codes that i am using is the problem. cant tell which is which even though I have used the header function and it still will not work

can someone tell me what is wrong, maybe an extra pair of eyes would be much appreciated. here is the codes for the both pages.

What I have tried:

here is the first codes

<?php
		
		
		header('Location: welcome.php');
		
	
?>


<?php

		$register=$_POST['register_user']; 
		if(isset($register))//check to see if button has been clicked
		{
			
				//capture the variable from the form and store in php variables
			 
			
			$title=$_POST['title'];
			$fullname=$_POST['fullname'];
			$lastname=$_POST['lastname'];
			$screenname=$_POST['screenname'];
			$email=$_POST['email'];
			$gender=$_POST['gender'];
			$address=$_POST['address'];
			$mypwd=$_POST['mypwd'];
			
			//connecting to the server           
			$db_host="localhost";
			$db_user="root";
			$db_pass="";
			//include'db_server.php';
			
			$conn=mysqli_connect($db_host,$db_user,$db_pass) or die (mysqli_connect_error());
			
			//select the database you want to query
			
				mysqli_select_db($conn, 'national_wonders') or die (mysqli_error($conn));
				$sql="SELECT * FROM members WHERE screenname='$screenname'";
				$result= mysqli_query($conn, $sql) or die ("ERROR:" .mysqli_error());
				$rowcount=mysqli_num_rows($result);
				
			if($rowcount >= 1) //checking to see if screenname is already exist
			{
				 "<script type=\"text/javascript\">
					  alert('Screenname already exits!!');
					  window.location=/login.html\";
					   </script>";
			}
			else
			{
				//insert data into table
				
				$sql = "INSERT INTO members
				VALUES('$title', '$fullname', '$lastname', '$screenname', '$email', '$gender', '$address', MD5('$mypwd'))";
			
				if(mysqli_query($conn,$sql))
				{
					session_start();
					$_SESSION['user']=$screenname;
					mysqli_close($conn);
					
						
							
				}
				else
				{
					echo "Error inserting values into database";
				}
				//end of line
				
			}
			
		}
			
?>




here is the codes for the welcome page

<?php
	session_start();
	if(!isset($_SESSION['view']))
	{
		header("location:../php/popupbox.php");
	}

?>

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<head>
		<title> Welcome </title>
		<link rel="stylesheet" type="text/css" href="css/stylesheet.css" />
	</head>
	<body>
		<div id="container">
			
			<div id="header">
				<div  id="banner">
					<img src="images/header.jpg" alt="header" />
				</div>
			</div>
			<div id="navbar">
				<ul>
				
					<li><a  href="../index.html" id="tlinks" class="toplinks">Homepage</a></li>
					<li><a  href="featureNaturalWonders.html" id="thold" class="toplinks">Feature Natural Wonders</a></li>
					<li><a  href="contact.html" id="linkhold" class="toplinks" >Contact Us</a></li>
					<li><a  href="register.html" id="phold" class="toplinks"> Sign Up</a></li>
					<li><a  href="login.html" id="loglinks"class="toplinks"> Login</a></li>
					<li><a  href="aboutus.html" id="panlinks" class="toplinks"> About Us</a></li>
					 
				</ul>	
					<form method="post" id="search"   action="" >						
						<input type="text" name="search" value=""/>
						<input type="submit" value="Search"/>												
					</form>				
									
			</div>	

			


		<div id="contentArea">
			<h1>CONGRATULATIONS!!!!</h1>
		<p>
			You are now a registered member!!
		</p>
				
		<p>
			Please enter your screenname and password to see the information you have submitted. 
		</p>
					
		<form method="post" action="../PHP/data.php">
									
			*Screenname:   <input type="text" name="screenname" /> <br/><br/>
							
			*Password:   <input type="password" name="mypwd" /> <br/><br/>
						
			<input type="submit" value="VIEW" /> 
		</form>
			
			<div id="footerbox">
				
					<div id="footerholder">
						<div id="">
						
							<a href="../index.php">Homepage</a>
							<a href="popupbox.php">Popup box </a>
							<a href="featureNationalWonders.php">Feature National Wonders</a>						
								
								
						</div>
					
					</div>
			</div>
		</div>
		
	</body>
			
</html>

register =
register=


_POST [ 'register_user'];
if(isset(
_POST['register_user']; if(isset(


register))//检查按钮是否被点击
{

//捕获变量从表格和存储在php变量
register))//check to see if button has been clicked { //capture the variable from the form and store in php variables