Skip to main content
January 14, 2007
Question

Registration

  • January 14, 2007
  • 2 replies
  • 288 views
I am new to the PHP world and as I am developing for friends and family I get questions on can certain functions be done and one has come to me recently which I do not know how to structure.

As you know my heading talks about registration.

I have already developed where someone can register by placing their name, address, phone number and e-mail. However, now it is going a little further which I do not know what is the structure for PHP and MySQL.

For example, I know if I wanted a name field it is a VARCHAR in MySQL, and if I wanted a yes or no I can use a checkbox field and that would by a tinyint in MySQL. The confusion for me is how do I set up the database for when you see registration where they ask for what is your favorite sports and there is a list of checkboxes and at the bottom there is a check box that says all and some how you see the checkbox has a check mark in all the boxes. How is this set up within PHP or I guess it will be HTML form tag. What I do not understand is what is the structure that if you have more than one checkbox which can be different interests, how does that get applied to the database of MySQL, is it a VARCHAR, or INT or even LONGTEXT? How does this get setup for registration applications? This is where I need guidance.

Can someone guide me in this, it is greatly appreciated.

Thank you,
AdonaiEchad
This topic has been closed for replies.

2 replies

Inspiring
January 16, 2007
AdonaiEchad wrote:
> registration where they ask for what is your favorite sports and there is a
> list of checkboxes and at the bottom there is a check box that says all and
> some how you see the checkbox has a check mark in all the boxes. How is this
> set up within PHP or I guess it will be HTML form tag.

It's not done with PHP, but JavaScript. Do a Google search. You'll find
plenty of scripts.

> What I do not
> understand is what is the structure that if you have more than one checkbox
> which can be different interests, how does that get applied to the database of
> MySQL, is it a VARCHAR, or INT or even LONGTEXT?

Use a SET as the MySQL column type:

http://dev.mysql.com/doc/refman/5.0/en/set.html

All checkboxes should have the same name followed by an empty pair of
square brackets so that they form an array. For example:

<input type="checkbox" name="interests[]" value="tennis" />

If no checkbox is selected, $_POST['interests'] will not exist, so you
need to test for its existence, and then use implode() to turn it into a
string before passing it to the SQL query.

if (isset($_POST['interests'])) {
$interests = implode(',', $_POST['interests']);
}
else {
$interests = '';
}

--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
January 16, 2007
No body knows?