DB entry empty for user registration script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jmcc
Forum Newbie
Posts: 5
Joined: Wed May 20, 2009 5:47 am

DB entry empty for user registration script

Post by jmcc »

When I submit my registration form there is a blank entry in my Database.

I use two diff pages for the registration.

Registration Form:----- registration.php

Code: Select all

 
<?php
 
session_start();
 
$username  = $_POST['username'];
$password  = $_POST['password'];
$email   = $_POST['email'];
 
$_SESSION['username_pos'] = $username;
$_SESSION['password_pos'] = $password;
$_SESSION['email_pos'] = $email;
 
 
?>


DB entry script:----- register.php

Code: Select all

 
<?php
 
require_once("connection.php"); // database connection
 
session_start();
 
$username_pos = $_SESSION['username_pos'];
$password_pos = $_SESSION['password_pos'];
$email_pos    = $_SESSION['email_pos'];
 
$insert ="INSERT INTO `users` (user_name, user_password, user_email) VALUES ('".$_POST[$username_pos]."', 
 
'".$_POST[$password_pos]."', '".$_POST[$email_pos]."')";
 
$insert2 = mysql_query($insert);
 
if(!$insert2) die(mysql_error());
echo 'Registration Successful, Welcome ' , $username_pos , '!!! You can now login to your new account.';
 
?>
Last edited by Benjamin on Tue May 26, 2009 10:52 am, edited 1 time in total.
Reason: Added [code=php] tags.
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: DB entry empty for user registration script

Post by susrisha »

Here are a few things :
1) The insert statement needs the variables of the session and not of the post.

Code: Select all

 
$insert ="INSERT INTO `users` (user_name, user_password, user_email) VALUES ('".$_POST[$username_pos]."', 
 
'".$_POST[$password_pos]."', '".$_POST[$email_pos]."')";
//you might want to change this to 
$insert ="INSERT INTO `users` (user_name, user_password, user_email) VALUES ('".$username_pos ."', 
 
'".$password_pos."', '".$email_pos."')";
 
 
2) If your registration form is in Registration.php, then you wont need that code to insert them into the session variable. You can directly call the post variables in the dbscript(register.php)
Last edited by Benjamin on Tue May 26, 2009 10:53 am, edited 1 time in total.
Reason: Changed code type from text to php.
Post Reply