Forum Moderators: open

Message Too Old, No Replies

How to check if one entry exists in my database

         

antreas

2:05 pm on Mar 3, 2006 (gmt 0)

10+ Year Member



Hello,
Im a newbie in all this and i want to ask somethnig..
I make one progran for one garage to store the customers and their car..
All the data are being store in one database..
When the owner of the program want to update the data
i want to check first if the data exist in the database and then continue..
If the data exist continue to the next step else show one msg that the customer does not exist

Can somebody help me pls?

Thnx in advance

Demaestro

5:59 pm on Mar 3, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



what you can do is, set up a search form that will find records based on last name or part of last name or some other piece of identifying info.

So if you search 'smith' it would show. John, jane, harry. You pick the one that you want, and if you don't find one matching. Then you can give them the option to create a new record.

Does this sovle what you are asking? If not post your questiona gain and I will try to help.

antreas

9:31 pm on Mar 3, 2006 (gmt 0)

10+ Year Member



thnx a lot my friend Demaestro.
this solve my problem but i dont know how to wirte the code..
this is my problem..
i dont know how to write this in php so if you can help me with this i will be very gratefull
thnx again

Demaestro

10:51 pm on Mar 3, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



well to be honest I don't know how to do this in PHP. That is the one web thing I don't know. I can help you a little though, but you may want to ask this in the PHP section.

What you need though is 3 basic SQL statements.

1 select
1 update
1 insert

This is roughly what they will look like in SQL although you will ahve to PHP-ify this.

*****select*****
<incoming param>last_name</incoming param>
select
*
from
customer_table c
where
lower(c.last_name) like 'last_name%';
**********************

*****update*****
<incoming param>unique_customer_id, first_name, last_name, and_so_on</incoming param>
update customer_table set
if last_name:
last_name = last_name,
if first_name:
first_name = first_name
if and_so_on:
and_so_on = and_so_on
where
unique_customer_id = unique_customer_id;
**********************

*****insert*****
<incoming param>new_unique_customer_id, first_name, last_name, and_so_on</incoming param>
insert into customer_table(
unique_customer_id,
last_name,
first_name,
and_so_on
)values(
new_unique_customer_id,
last_name,
first_name,
and_so_on
);
**********************

Good Luck and if you need any SQL systax you can sticky me or post back here.

antreas

8:30 pm on Mar 4, 2006 (gmt 0)

10+ Year Member



thnx a lot...
i will try it and i will tell u the result...

Demaestro

9:34 pm on Mar 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Cool, Let me know for sure.

antreas

8:10 pm on Mar 8, 2006 (gmt 0)

10+ Year Member



In the end i found on easiest solution
and i add it here to see it..
THANKS again for your help

$result=mysql_query("select fname,lname,lcnumber from input where fname='$Name' and lname='$Sname' and lcnumber='$Plates'" );
$row = mysql_fetch_row($result);
if ($row<1)
{
echo "The customer does not exists";
}
else
{
continue in the form to add the data
}

The program makes the search and give the fail result if the customer does not exist in the if.
as else i add the page which the owner goes to update his customer..