Click here to Skip to main content
15,891,976 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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>
Posted
Comments
Richard Deeming 26-Mar-19 15:20pm    
Problem 1:
Your code is vulnerable to SQL Injection. NEVER use string concatenation / interpolation to build a SQL query. ALWAYS use a parameterized query.

Everything you wanted to know about SQL injection (but were afraid to ask) | Troy Hunt[^]
How can I explain SQL injection without technical jargon? | Information Security Stack Exchange[^]
PHP: SQL Injection - Manual[^]
divinity02 27-Mar-19 6:37am    
thanks a lot, wow didnt think of that many thanks much appreciated
Richard Deeming 26-Mar-19 15:22pm    
Problem 2:
Good news - you're not storing your passwords in plain text.

Bad news - you're using MD5, which is totally insecure. And to make matters worse, you're not salting the password.

Secure Password Authentication Explained Simply[^]
Salted Password Hashing - Doing it Right[^]

PHP has built-in functions to help you do the right thing with passwords:

PHP: password_hash[^]
PHP: password_verify[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900