This site requires JavaScript, please enable it in your browser!
Greenfoot back
divinity
divinity wrote ...

2019/3/23

how can i fix this error

divinity divinity

2019/3/23

#
i am doing this assignment i have this error. this is a webpage and right now am using php. when i ran the register a page i get this error Error inserting values into database i have search hi and low within the code to find the error and for the of me cyh find it. may another pair of eyes will help please and can u tell me what is wrong, where is the error and how it can be fix because something is blocking it. here is my code.
<?php

		
		ini_set('display_errors', 1); 
		ini_set('display_startup_errors', 1); 
		error_reporting(E_ALL);
		
		
		error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
		
		
		if(isset($_POST['register_user']))
		{
			//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
			
			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)
			{
				echo"<script type=\"text/javascript\">
					alert('Username already exits!!');
					window.location=\"../php/welcome.php\";
					</script>";
			}
			else
			{
				//insert data into table
				
				$sql = "INSERT INTO members
				VALUES('$title', '$fullname', '$lastname', '$screenname', '$address', '$email', '$gender',  'md5('$mypwd))";
			
				if(mysqli_query($conn,$sql))
				{
					echo"<script type=\"text/javascript\">
					alert(Welcome);
					window.location=\"login.php\";
					</script>";
				}
				else
				{
					echo "Error inserting values into database";
				}
				
			}
			
		}	
			
?>	
		
Super_Hippo Super_Hippo

2019/3/23

#
I don't know anything about PHP (there is probably a better location to ask this question than here anyway), but why are you using Strings instead of the variables in line 51? The "echo" lines seem odd… you have echo, then no space, " and the last thing is > and not ".
danpost danpost

2019/3/24

#
Line 51 does appear to be troublesome. You have the extraneous characters. 'md5(, near the end of the line.
You need to login to post a reply.