Jump to content

Registration form problem, DB entry empty. Think variable passing prob.


Recommended Posts

Please help regarding blank DB entry.

 

I use files to send registration. registration.php is the form and register.php is the post to DB script.

 

Registration form ---- registration.php

[<?php]

 

session_start();

 

$username  = $_POST['username'];

$password  = $_POST['password'];

$email = $_POST['email'];

 

$_SESSION['username_pos'] = $username;

$_SESSION['password_pos'] = $password;

$_SESSION['email_pos'] = $email;

 

 

[?>]

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

</head>

 

<body>

<form id="form1" name="form1" method="post" action="<?php $_SERVER['PHP_SELF'];?>">

  <table width="50%" border="0" align="center">

    <tr>

      <td>Username</td>

      <td><label>

        <input type="text" name="username" id="username" />

      </label></td>

    </tr>

    <tr>

      <td>Password</td>

      <td><label>

        <input type="text" name="password" id="password" />

      </label></td>

    </tr>

 

    <tr>

      <td>Email</td>

      <td><label>

        <input type="text" name="email" id="email" />

      </label></td>

    </tr>

    <tr>

      <td>Confirm</td>

      <td><label>

      <input name="button" type="Button" value="submit" onclick="document.location.href='register.php'" />

      </label></td>

    </tr>

  </table>

</form>

</body>

</html>

 

Post to DB script register.php

 

[<?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.';

 

[?>]

 

 

Not to mention if you had it linked to the right page, you're trying to return the values like:

 

$_POST[$username_pos]

 

Which would equal to:

 

$_POST[$_SESSION[$username]]

 

Try instead, though baring in mind you should really secure your inputs, something like this:

 

$_POST['username']

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.