alerting redundant field to user

images php coding issues or problems here.

Moderators: macek, egami, gesf

nigussie
New php-forum User
New php-forum User
Posts: 4
Joined: Thu Nov 11, 2010 4:57 am

alerting redundant field to user

Postby nigussie » Thu Nov 11, 2010 5:20 am

hello all,
i'm using php 5 and mysql 5 to develop a website. i have a database that stores application for vacancies and i used email address field as primary key. so for uniquness purpose i want to alert back a user to use another email address in case he/she tries to apply more than once using the same email address....what i tried was to take the supplied email filed on my vacancy page and compare it with all previously stored email fields in my database and to alert back if i get.

but it didn't work as i thought it to be...pls help.
i can post my code if needed
thank you guys!

User avatar
egami
php-forum GURU
php-forum GURU
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: alerting redundant field to user

Postby egami » Thu Nov 11, 2010 6:01 am

why is this in an Images forum?

nigussie
New php-forum User
New php-forum User
Posts: 4
Joined: Thu Nov 11, 2010 4:57 am

Re: alerting redundant field to user

Postby nigussie » Thu Nov 11, 2010 10:40 am

yup,egami u r right infact! but it wasn't deliberate.

User avatar
egami
php-forum GURU
php-forum GURU
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: alerting redundant field to user

Postby egami » Thu Nov 11, 2010 10:48 am

a.) I wouldn't use an email address for primary keys or UNIQUE fields. I would use Integers because it's MUCH faster.

b.) You can put a "UNIQUE" field on the email address, to ensure that you have one copy of email in your db for one single user, no problem there, just be aware that doing so will chew up disk and cpu.

c.) $query = "SELECT email FROM my_table WHERE email='$_POST[email]'"; // <-- This IS NOT SAFE.. you should use some kind of filtering, error checking, etc.. I used this as a pure example, and nothing more. //
$result = mysql_query($query);
$numrow = mysql_num_rows($result);
if ($numrow == 1) {
$user_error['email_address'] = "The E-Mail Address is already in use.";
} else {
do this..
}
Last edited by egami on Thu Nov 11, 2010 11:51 am, edited 1 time in total.

nigussie
New php-forum User
New php-forum User
Posts: 4
Joined: Thu Nov 11, 2010 4:57 am

Re: alerting redundant field to user

Postby nigussie » Thu Nov 11, 2010 11:02 am

yeah i used that logic -email='$_POST[email]', but i think it couldn't do well as both the email text box on the form and the database field for email have the same field name 'email'. so may this create some sort of confusion for the case not to work?...

egami, i will post the whole code here anywya, thank you,brother!

User avatar
egami
php-forum GURU
php-forum GURU
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: alerting redundant field to user

Postby egami » Thu Nov 11, 2010 11:07 am

no, it wouldn't be any trouble at all. The field name of a table has no correlation to the field name of an HTTP_VAR.

You can name a field "kitten" and the name of the field be "puppy"

just have to assign it as such on the backside.

INSERT INTO my_table (kitten) VALUES ('$_POST[puppy]')

nigussie
New php-forum User
New php-forum User
Posts: 4
Joined: Thu Nov 11, 2010 4:57 am

Re: alerting redundant field to user

Postby nigussie » Thu Nov 11, 2010 11:12 am

ok. you did great to help me. hope i'll fix it though i didn't have much experience in it . i think i got to read more. thanks!!!!


Return to “PHP coding => Images”

Who is online

Users browsing this forum: No registered users and 1 guest