elements708 Posted August 20, 2008 Share Posted August 20, 2008 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 More sharing options...
genericnumber1 Posted August 21, 2008 Share Posted August 21, 2008 $result = mysql_query($sql) or die(mysql_error()); that should help Link to comment https://forums.phpfreaks.com/topic/120621-need-help-with-php-register-script/#findComment-621550 Share on other sites More sharing options...
genericnumber1 Posted August 21, 2008 Share Posted August 21, 2008 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 Link to comment https://forums.phpfreaks.com/topic/120621-need-help-with-php-register-script/#findComment-621576 Share on other sites More sharing options...
trq Posted August 21, 2008 Share Posted August 21, 2008 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')"; Link to comment https://forums.phpfreaks.com/topic/120621-need-help-with-php-register-script/#findComment-621580 Share on other sites More sharing options...
elements708 Posted August 21, 2008 Author Share Posted August 21, 2008 <?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"; } } ?> Link to comment https://forums.phpfreaks.com/topic/120621-need-help-with-php-register-script/#findComment-621586 Share on other sites More sharing options...
trq Posted August 21, 2008 Share Posted August 21, 2008 `Backticks` are not 'single quotes' if your last reply meens you still have a problem. Its usually best to describe the issue. Link to comment https://forums.phpfreaks.com/topic/120621-need-help-with-php-register-script/#findComment-621651 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.