Click here to Skip to main content
16,017,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a very simple PHP program I am working on just to do some refreshing and I cannot get any echos to show up and also the data is not being inserted into the database. Can someone please tell me my error? Also for php debugging do I just add “error_reporting(-1);” in the PHP code?

Here is what I have for simple data.

HTML
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>login test</title>
		
	</head>
	<body>
		<form action="signup.php" method="POST">
			<input type="text" name="first" id="first" placeholder="first name" /><br>
			<input type="text" name="user" id="user" placeholder="user name" /><br>
			<input type="password" name="pass" id="pass" placeholder="password" /><br>
			<button type="submit">Sign up</button>
		</form>
	</body>
</html>

Conn.php
<?php
		
	$conn = mysqli_connect("localhost", "root", "", "test");
	
	if(!$conn) {
		die("Connection failed: " . mysqli_connect_error());
	}

Signup.php
<?php

	include 'conn.php';
	
	$first = $_POST['first'];
	$user = $_POST['user'];
	$pass = $_POST['pass'];
	
	echo $first;
	echo $user;
	echo $pass;
	
	$sql = "INSERT INTO user (first, user, pass) 
			VALUES ('$first', '$user', '$pass')";
			
	$result = mysqli_query($conn, $sql);
	
	header("Location: register.php");


What I have tried:

php error handling
echoing the data from the textboxes to the screen and the screen stays blank
i am not sure why my echoing is not working.
Posted
Updated 24-Feb-17 18:16pm

1 solution

Quote:
i am not sure why my echoing is not working
that is because it has been redirected to register.php due to
header("Location: register.php");
If you really want to see the echo messages, then comment it out temporarily:
//header("Location: register.php");
Quote:
and also the data is not being inserted into the database
Barring another other errors, one obvious mistake is that you are using a reserved word for mysql[^], i.e. user as table name. Most of the reserved words are forbidden by standard SQL as column or table name. To get around it, surround it with a pair of back ticks, i.e.
`user`

Last but not least, you should adopt PHP Prepared Statements[^] to minimize the risk of SQL injection.
 
Share this answer
 
v3

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