MYSQL Select Qurey Help Needed..

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
pavanpuligandla
Forum Contributor
Posts: 130
Joined: Thu Feb 07, 2008 8:25 am
Location: Hyderabad, India

MYSQL Select Qurey Help Needed..

Post by pavanpuligandla »

hii..
i'm developing a php forgot password script with the below 4 steps in which i need to validate userid from one table and user's addresses from other table.
i've 2 tables in my DB customers and customer_addresses.

in the first form i'm validating the form input with user ID.
my code for first form:

Code: Select all

$query="SELECT customerID FROM ss_customers WHERE Login='" . mysql_real_escape_string($Login) . "'";
secondly i've to check those user's firstname, lastname, state and zip code with another table.
heres my code:

Code: Select all

$query="SELECT customerID FROM ss_customer_addresses WHERE first_name='" . mysql_real_escape_string($first_name) . "' and last_name='" . mysql_real_escape_string($last_name) . "' and state='" . mysql_real_escape_string($state) . "' and zip='" . mysql_real_escape_string($zip) . "'";
my problem is, when i input user say "MYSQL" and if tht exist in customers tanle then i can see the second form, there if i enters firstname, lastname, state and zip of other user that is in DB i'm getting success page, i need to validate the second form's input with user "MYSQL" only.
can anyone please help me out..
awaiting ur reply's
many thanks,
NOmeR1
Forum Newbie
Posts: 8
Joined: Sat Feb 14, 2009 8:32 am

Re: MYSQL Select Qurey Help Needed..

Post by NOmeR1 »

You have to use customerID from first mysql query in second query..

Code: Select all

// First mysql query
$query = mysql_query("SELECT customerID FROM ss_customers WHERE Login='" . mysql_real_escape_string($Login) . "'");
$customerID = mysql_fetch_array($query);
$customerID = $customerID['customerID']; // Get customer ID
// Second mysql query
$query = mysql_query("SELECT customerID FROM ss_customer_addresses WHERE first_name='" . mysql_real_escape_string($first_name) . "' and last_name='" . mysql_real_escape_string($last_name) . "' and state='" . mysql_real_escape_string($state) . "' and zip='" . mysql_real_escape_string($zip) . "' and customerID = '".$customerID."'");
if($query) {
// Login successful
} else {
// Error page
}
User avatar
pavanpuligandla
Forum Contributor
Posts: 130
Joined: Thu Feb 07, 2008 8:25 am
Location: Hyderabad, India

Re: MYSQL Select Qurey Help Needed..

Post by pavanpuligandla »

hii..
nothing had changed..
let me clear my scenario frm my side..
i'm having 2 forms.. in the first form, i take userID as input and validates it against the DB and shows the second form if tht userID matches with the DB.
In the second form, i'm validating more details like firstname, lastname, mobile for tht particular userID against the DB.. if those details were entered correctly for tht USERID, then i've to show a success message else no records found..

Now when i enter firstname, lastname, mobile of other userID's then an error message should be thrown instead i can see success message..

suppose for userID "MYSQL" firstname = M lastname= S and mobile = 9
if i enter another user's details say "PHP" where firstname = p lastname -= h mobile =0
then it should not show the success page, i mean here we are validating the fields against MYSQL only not for PHP.
i think u understood my problem..
Post Reply