Welcome to Dream.In.Code
Getting Help is Easy!

Join 131,500 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,833 people online right now. Registration is fast and FREE... Join Now!




Preventing empty registration

 
Reply to this topicStart new topic

Preventing empty registration

triplexduplex
post 7 Oct, 2008 - 07:28 AM
Post #1


New D.I.C Head

*
Joined: 4 Apr, 2008
Posts: 19

Hi,

I was just wondering how to prevent someone from submitting a blank registration form to my database.
Here is my code at the moment:

CODE

<?
$conn = mysql_connect("localhost","USERNAME","PASSWORD");

$db = mysql_select_db("members");

$username = $_POST["username"];
$password = $_POST["password"];
$email = $_POST["email"];

$result= MYSQL_QUERY("INSERT INTO users (id, username, password, email)".
   "VALUES ('NULL', '$username', '$password', '$email')");
  
echo "Your name and password have been submitted into our database";
?>


Currently, when I click the signup button without even filling up the above fields, it will automatically submit a blank entry into my database and credit it with an ID number.

Help would be appreciated, thanks.
User is offlineProfile CardPM

Go to the top of the page


jens
post 7 Oct, 2008 - 07:38 AM
Post #2


D.I.C Head

Group Icon
Joined: 9 May, 2008
Posts: 84



Thanked 2 times

Dream Kudos: 150
My Contributions


You have two choises.
1) Check user input in your code. If empty then dont call the DB insert stuff.
2) Tell the DB that the field username may not be null. (search for "alter table not null"...)

/Jens
User is offlineProfile CardPM

Go to the top of the page

Trogdor
post 7 Oct, 2008 - 07:57 AM
Post #3


D.I.C Addict

Group Icon
Joined: 6 Oct, 2006
Posts: 515



Thanked 3 times

Dream Kudos: 125
My Contributions


I see you dont do any filtering on the posted fields.
That is an invitation to people that like to do nasty things.
Have a look on the web for "sql-injection".
Please be wise and filter out quotes, and put the normal escaping functions around the parameters.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/20/08 12:24AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month