Click here to Skip to main content
15,904,346 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This coding works when I run it offline. Then after I put it at cpanel. It fail to add student.

What I have tried:

PHP
<?php
include 'conn.php';

if(isset($_POST['submit'])){
	$username = $_POST['username'];
	$password = $_POST['password'];
	$email    = $_POST['email'];

	
	$query = "INSERT INTO student(username,password,email) VALUES ('$username','$password','$email')";
			  
	$result = mysqli_query($conn,$query);
	
	if($result){
		echo "alert('Success!');
		window.location='managestudent.php'";
	}else{
		echo "alert('Fail !');";
	}
}

?>
Posted
Updated 13-May-18 4:20am
v2
Comments
Richard MacCutchan 13-May-18 9:06am    
We cannot guess what that means; you need to provide more details.
Mohibur Rashid 13-May-18 17:23pm    
What is cpanel?

1 solution

PHP
$query = "INSERT INTO student(username,password,email) VALUES ('$username','$password','$email')";

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[^]
 
Share this answer
 

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