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

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




Preventing empty registration

 
Reply to this topicStart new topic

Preventing empty registration

triplexduplex
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
+Quote Post

jens
RE: Preventing Empty Registration
7 Oct, 2008 - 07:38 AM
Post #2

D.I.C Head
Group Icon

Joined: 9 May, 2008
Posts: 113



Thanked: 3 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 online!Profile CardPM
+Quote Post

Trogdor
RE: Preventing Empty Registration
7 Oct, 2008 - 07:57 AM
Post #3

D.I.C Addict
Group Icon

Joined: 6 Oct, 2006
Posts: 523



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
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/3/08 12:48AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month