Page 1 of 1

DB entry empty for user registration script

Posted: Tue May 26, 2009 2:48 am
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.';
 
?>

Re: DB entry empty for user registration script

Posted: Tue May 26, 2009 3:13 am
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)