Jump to content

need help with php register script


elements708

Recommended Posts

here is the code i am using to get my register page working, but when i register for a new account, it does not store the account information in my database table, can please tell me what i am doing wrong, thanks everyone

<?php
$host = 'localhost';
$dbuser = 'user';
$dbpass = 'pass';
$dbname = 'user';

$connection = mysql_connect($host, $dbuser, $dbpass);
$db = mysql_select_db($dbname,$connection);

//grab data from form
$username = $_POST['username'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$pass = $_POST['password'];
$pass_conf = $_POST['pass_conf'];
$month = $_POST['month'];
$day = $_POST['day'];
$year = $_POST['year'];
$phonenumber = $_POST['phonenumberl'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$countries = $_POST['countries'];
$postalcode = $_POST['postalcode'];
$ip = $_POST['ip'];

//if else (else if)
if ($username == null || $firstname == null || $lastname == null || $email == null || $pass == null || $pass_conf == null || $month == null || $day == null || $year == null || $phonenumber == null || $address == null || $city == null || $state == null || $countries == null || $postalcode == null ) {
echo "Please fill in all the required  fields.";
}
if ($pass != $pass_conf) {
echo "Passwords do not match.";
} elseif ($connection = mysql_connect ($host,$dbuser,$dbpass)) {
$db = mysql_select_db($dbname,$connection);
$sql = "INSERT INTO 
	'user' 
	(username,password,email,ip) 
	VALUES 
	('$name','$pass','$email','$ip')";
$result = mysql_query($sql);
echo "Thank you for registering at ScoopDNS.com";
}

?>

Link to comment
https://forums.phpfreaks.com/topic/120621-need-help-with-php-register-script/
Share on other sites

Try something like this:

 

<?php
$host = 'localhost';
$dbuser = 'user';
$dbpass = 'pass';
$dbname = 'user';

//grab data from form
$username = $_POST['username'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$pass = $_POST['password'];
$pass_conf = $_POST['pass_conf'];
$month = $_POST['month'];
$day = $_POST['day'];
$year = $_POST['year'];
$phonenumber = $_POST['phonenumberl'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$countries = $_POST['countries'];
$postalcode = $_POST['postalcode'];
$ip = $_POST['ip'];

if ($username == null || $firstname == null || $lastname == null || $email == null || $pass == null || $pass_conf == null || $month == null || $day == null || $year == null || $phonenumber == null || $address == null || $city == null || $state == null || $countries == null || $postalcode == null) {
echo "Please fill in all the required  fields.";
}
else {
if ($pass != $pass_conf) {
	echo "Passwords do not match.";
}
else {
	$username = mysql_real_escape_string($username);
	$pass = mysql_real_escape_string($pass);
	$email = mysql_real_escape_string($email);
	$ip = mysql_real_escape_string($ip);

	$connection = mysql_connect($host, $dbuser, $dbpass) or die(mysql_error());
	mysql_select_db($dbname, $connection) or die(mysql_error());
	$sql = "INSERT INTO user (username, password, email, ip)
		VALUES ('$username','$pass','$email','$ip')";
	$result = mysql_query($sql, $connection) or die(mysql_error());
	echo "Thank you for registering at ScoopDNS.com";
}
}

?>

 

tell us what the error is

password is the name of a mysql function so it is likely getting confused. Either change your field name (recommended) or use `backticks` to escape the special word. eg;

 

$sql = "INSERT INTO user (username, `password`, email, ip) VALUES ('$username','$pass','$email','$ip')";

<?php

$host = 'localhost';

$dbuser = 'user';

$dbpass = 'pass';

$dbname = 'user';

 

//grab data from form

$username = $_POST['username'];

$firstname = $_POST['firstname'];

$lastname = $_POST['lastname'];

$email = $_POST['email'];

$pass = $_POST['password'];

$pass_conf = $_POST['pass_conf'];

$month = $_POST['month'];

$day = $_POST['day'];

$year = $_POST['year'];

$phonenumber = $_POST['phonenumber'];

$address = $_POST['address'];

$city = $_POST['city'];

$state = $_POST['state'];

$countries = $_POST['countries'];

$postalcode = $_POST['postalcode'];

$ip = $_POST['ip'];

 

if ($username == null || $firstname == null || $lastname == null || $email == null || $pass == null || $pass_conf == null || $month == null || $day == null || $year == null || $phonenumber == null || $address == null || $city == null || $state == null || $countries == null || $postalcode == null) {

echo "Please fill in all the required  fields.";

}

else {

if ($pass != $pass_conf) {

echo "Passwords do not match.";

}

else {

$username = mysql_real_escape_string($username);

$pass = mysql_real_escape_string($pass);

$email = mysql_real_escape_string($email);

$ip = mysql_real_escape_string($ip);

 

$connection = mysql_connect($host, $dbuser, $dbpass) or die(mysql_error());

mysql_select_db($dbname, $connection) or die(mysql_error());

$sql = "INSERT INTO user (username, 'password', email, ip)

VALUES ('$username','$pass','$email','$ip')";

$result = mysql_query($sql, $connection) or die(mysql_error());

echo "Thank you for registering at ScoopDNS.com";

}

}

 

?>

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.