Click here to Skip to main content
15,907,183 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi it is me again, this is my assignemet been trying to fix this php script for a long time

first to begin, it was issuing an error,

Warning: join(): Invalid arguments passed in C
this is the first error

and the second error was: notice: undefined index in c.
apprently if my html code, i had register a the values when registering but in my php code i had enter instead, so i fix it right

now after i finished fixing it, i tried to register a user and now i am getting a blank page, dont know what is the cause but maybe a third eye can see what I cant. please help
here is what i have tried.

What I have tried:

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['fname'];
			$lastname=$_POST['lname'];
			$username=$_POST['username'];
			$email=$_POST['email'];
			$gender=$_POST['gender'];
			$service= join(", ", $_POST['services']);
			$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($conn));
			
			$rowcount=mysqli_num_rows($result);
			
			//checking to see if username is already exist
			if($rowcount >= 1) 
			{
				 echo "<script type=\"text/javascript\">
					  alert('Username already exits');
					  window.location=\"../xhtml/register_user.html\";
					   </script>";
					   
				
				
			}
			else
			{
				//insert data into table
				
				$sql = "INSERT INTO members
				VALUES('$title', '$firstname', '$lastname', '$username', '$email', '$gender', '$service', '$address', md5('$mypwd'))";
			
				if(mysqli_query($conn,$sql))
				{
					
					echo "<script type=\"text/javascript\">
					  alert('Welcome!! $firstname $lastname, you are now a member of the Caribbean Nature Seekers Institute TT(CNSITT)');
					  window.location=\"../index.html\";
					   </script>";
					
					   
						mysqli_close($conn);	
				}
				else
				{
					echo "Error inserting values into database";
				}
				
				//end of line
				
			}
		}
			
			
	
		
			
?>
Posted
Updated 13-Apr-19 20:59pm

Writing the code does not mean it is right! :laugh:
Think of the development process as writing an email: compiling successfully means that you wrote the email in the right language - English, rather than German for example - not that the email contained the message you wanted to send.

So now you enter the second stage of development (in reality it's the fourth or fifth, but you'll come to the earlier stages later): Testing and Debugging.

Start by looking at what it does do, and how that differs from what you wanted. This is important, because it give you information as to why it's doing it.

Time for you to learn to debug your code - we can't do that for you as it will be data dependant, and we only have a tiny fraction of the whole code.

So start with Google: debugging php - Google search[^] and follow a few links.
This looks interesting: How to Debug in PHP[^]

Think about what each line in the code should do before you execute it, and compare that to what it actually did when you use the "Step over" button to execute each line in turn. Did it do what you expect? If so, move on to the next line.
If not, why not? How does it differ?
Hopefully, that should help you locate which part of that code has a problem, and what the problem is.
This is a skill, and it's one which is well worth developing as it helps you in the real world as well as in development. And like all skills, it only improves by use!
 
Share this answer
 
Comments
divinity02 14-Apr-19 2:24am    
@OriginalGriff

that is the whole code dont know if u want me to post the html code also
PHP
$sql="SELECT * FROM members WHERE username='$username'";

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[^]
 
Share this answer
 
Comments
divinity02 14-Apr-19 12:03pm    
@Patrice T what is wrong with that line
Patrice T 14-Apr-19 12:24pm    
As explained in solution, that line and others are subjected to an attack called 'SQL injection'
divinity02 15-Apr-19 5:33am    
@Patrice T, if that if the line that is causing the problem, how should i go about querying the database, what line of codes should i use, or if you have any suggesting on what I should be using instead of that line of code, please tell me na

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