Jump to content


Photo

MySQL phpmyadmin


  • Please log in to reply
3 replies to this topic

#1 hugoboss

hugoboss

    Young Padawan

  • Members
  • Pip
  • 5 posts

Posted 16 December 2006 - 01:38 PM

Hi folks, Im pretty new to php and MySQL so firstly forgive any mistakes i make and secondly feel free to critic good or bad its all a big learning curve for me.. So here goes, im setting up a user registration form on a php web site, I've got my database and tables set up in MySQL using the script below

CREATE TABLE Ukkiss_Memberlist (
user_name VARCHAR(32) NOT NULL,
password VARCHAR(255) NOT NULL,
gender VARCHAR(7) NULL,
email VARCHAR(50) NOT NULL,
date_modified TIMESTAMP,
date_joined TIMESTAMP,
PRIMARY KEY(user_name) );


Notice the highlighted line, well thats so "registrants" can select whether they are male or female by clicking the relevant radio button, (i did have it set to "NOT NULL") however its causing me problems, everything works ok on testing but these radio buttons fail me all the time and then registration fails even though a button has been selected.How can i change that line so that the clicked radio button returns whether the "new user" is male or female to my database, the image below shows what error is made upon submitting the form..
Posted Image

Thanks for your time in reading this post..

#2 Mr. Matt

Mr. Matt

    Moderator

  • Validating
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 16 December 2006 - 01:56 PM

well, firstly for the gender field in the database I would use an enum field, so in phpMyAdmin I would select Enum from the list, and the values would be 'male','female'. I would then use a select box personally, so:

<select name="gender"><option value="male">Male</option><option value="female">Female</option></select>

And then in your query use $_POST['gender']; to get weather if it was a male or female selected.

Matt

#3 Hayden

Hayden

    P2L Jedi

  • Members
  • PipPipPip
  • 717 posts
  • Gender:Male
  • Location:Texas

Posted 16 December 2006 - 02:20 PM

well, firstly for the gender field in the database I would use an enum field, so in phpMyAdmin I would select Enum from the list, and the values would be 'male','female'. I would then use a select box personally, so:

<select name="gender"><option value="male">Male</option><option value="female">Female</option></select>

And then in your query use $_POST['gender']; to get weather if it was a male or female selected.

Matt


Well, I was going to say the same thing about using the ENUM field as well.... :blush:

to add to that though, I would do an enum to either '0','1' or 'm','f'. save some space in your DB. having the full word male or female will add up fairly quickly and take up more space.

#4 hugoboss

hugoboss

    Young Padawan

  • Members
  • Pip
  • 5 posts

Posted 16 December 2006 - 05:01 PM

Excellant advice from both you guys, i just can thankyou enough, was'nt as easy a ride as i thought but with some persistance on my part and the great advice from you 2 guys all is well and good.. Once again thanks.. Heres the final script i used

CREATE TABLE Ukkiss_Memberlist (
user_name VARCHAR(32) NOT NULL,
password VARCHAR(255) NOT NULL,
gender enum('Male','Female') NULL,
email VARCHAR(50) NOT NULL,
date_modified TIMESTAMP,
date_joined TIMESTAMP,
PRIMARY KEY(user_name) );


Thats the line changed as you guys recommended, i had a bit of trouble with the values for the male and female menu but i didnt want to pester you more than i have done in a day and finally it all came together, thanks again




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users