Click here to Skip to main content
15,909,440 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have been trying to validate my register form using javascript but i figured by using the: alert('it works") just to see if the js is working of the form but i am getting this error

Notice: undefined index: in gender in c;

which has something to do with the php code. to my js is non functional until that error is fix, tried everything that I can think of and even went searching the net and tried all that I can see but to no avail

can someone help and also it is not inserting into the database, can something tell me what is wrong and why it is not inserting into the database

maybe a third eye will help me what this is not inserting into the database, I am getting all kinds of errors that I cannot see, it give me wrong result when i run it

when i mean wrong result, I mean when a user is registered it, a popup box will popup and tell u welcome to the webpage and then it should redirect the user to the login page an it is not doing that, it instead telling the users that the username already exist ( which I dont have within the code itself) and it either take u back to the index page or back to the register page which not supposed to do

What I have tried:

this is what i have

PHP
<pre><?php

		//$register=$_POST['register_user']; 
		if(isset($_POST['Register']))
		{
			
			//capture the variable from the form and store in php variables
			$title=$_POST['title'];
			$firstname=$_POST['firstname'];
			$lastname=$_POST['lastname'];
			$username=$_POST['username'];
			$email=$_POST['email'];
			if(isset($_POST['register']))
			{
				if(isset($_POST['gender'])) 
				{
					$gender = $_POST['gender'];
				}
			}
			else
			{
				$gender = "";
			}
			$address=$_POST['address'];
			$mypwd=$_POST['mypwd'];
			
			include'db_server.php';
			
			//Query the database
			$sql="SELECT * FROM members WHERE username='$username'";
			
			$result= mysqli_query($conn, $sql) or die ("ERROR:" .mysqli_error());
			
			$rowcount=mysqli_num_rows($result);
			
			//checking to see if username is already exist
			if($rowcount >= 1) 
			{
				echo "<script type=\"text/javascript\">
					  alert('Welcome!! Firstname Lastname, you are now a member of the Caribbean Nature Seekers Institute TT(CNSITT)');
					  window.location=\"../login_user.html\";
					   </script>";
					   
				 
			}
			else
			{
				//insert data into table
				
				$sql = "INSERT INTO members
				VALUES('$title', '$firstname','$lastname', '$username', '$email', '$gender', '$address', md5('$mypwd'))";
			
				if(mysqli_query($conn,$sql))
				{
					session_start();
					$_SESSION['user']=$username;					
					header("location:login_user.html");
					mysqli_close($conn);
						
				}
				else
				{
					echo "Error inserting values into database";
				}
				//end of line
				
			}
		}	
		
			
?>


m
Posted
Updated 7-Apr-19 17:19pm

1 solution

PHP
$sql = "INSERT INTO members VALUES('$title', '$firstname','$lastname', '$username', '$email', '$gender', '$address', md5('$mypwd'))";

Not a solution to your question, but another problem you have.
Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input a name like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability, and the crash is the least of the problems, a malicious user input and it is promoted to SQL commands with all credentials.
SQL injection - Wikipedia[^]
SQL Injection[^]
SQL Injection Attacks by Example[^]
PHP: SQL Injection - Manual[^]
SQL Injection Prevention Cheat Sheet - OWASP[^]
How can I explain SQL injection without technical jargon? - Information Security Stack Exchange[^]
Quote:
Notice: undefined index: in gender in c;

Give exact error message, position of error should be indicated.
If not indicated, use the debugger, it will show you that position.
[Update]
Do you know that if 'gender' is not set, $gender is not either.
PHP
if(isset($_POST['register']))
{
	if(isset($_POST['gender'])) 
	{
		$gender = $_POST['gender'];
	}
}
else
{
	$gender = "";
}
 
Share this answer
 
v2

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