Page 1 of 1

MYSQL Select Qurey Help Needed..

Posted: Fri Mar 27, 2009 11:53 pm
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,

Re: MYSQL Select Qurey Help Needed..

Posted: Sat Mar 28, 2009 3:06 am
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
}

Re: MYSQL Select Qurey Help Needed..

Posted: Sat Mar 28, 2009 12:53 pm
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..