Click here to Skip to main content
15,894,907 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a table in mysql , called customer. it has id,name,number,password & balance with respective data's. i have an Android application which is connect with this database and login with number and password . If it is match then ask amount to detect from particular customer balance.the number and password is successfully verified but i need to detect some the amount from customer balance.how to do that.. below code is for verify the number and password

if my question is not clear. please let me know .. thanks in advance :)

What I have tried:

PHP
verify.php
<?php 
    $con = mysqli_connect("localhtost", "root","", "data"); 
     $number = $_POST["number"]; 
    $password = $_POST["password"]; 
     $statement = mysqli_prepare($con, "SELECT * FROM customer WHERE number = ? AND        password = ?"); 
    mysqli_stmt_bind_param($statement, "ss", $number, $password); 
    mysqli_stmt_execute($statement); 
    mysqli_stmt_store_result($statement); 
    mysqli_stmt_bind_result($statement,$id,$name,$number,$password,$balance); 
     
    $response = array(); 
    $response["success"] = false;   
     
    while(mysqli_stmt_fetch($statement)){ 
    $response["success"] = true;   
    $response["id"] = $id; 
    $response["name"] = $name; 
    $response["number"] = $number; 
    $response["password"] = $password; 
    $response["balance"] = $balance; 
    } 
     echo json_encode($response); 
?>
Posted
Updated 3-May-17 1:13am
Comments
Wessel Beulink 3-May-17 5:32am    
You have the balance already. Is the amount in a table or as input on the android application? I do not understand what you mean with: 'I need to detect some the amount'
Member 13168378 3-May-17 6:34am    
i mean already have some balance in my account ex:1000.. when the user enter a amount like 100. the amount 100 should detect and 900 should have update

1 solution

You can directly return
$response["amount"] = $balance - [your input value (amount)]


Or directly update

$updatestatement = mysqli_prepare($con, "UPDATE customer SET balance = (balance - [your input value (amount)]) WHERE number = ? AND password = ? "); 


mysqli_stmt_bind_param($updatestatement , "ss", $number, $password); 
mysqli_stmt_execute($updatestatement ); 
mysqli_stmt_bind_param($statement, "ss", $number, $password);
mysqli_stmt_execute($statement); 
mysqli_stmt_store_result($statement); 
mysqli_stmt_bind_result($statement,$id,$name,$number,$password,$balance); 
 
Share this answer
 
Comments
Member 13168378 3-May-17 7:45am    
wessel beulink @ thanks for reply.i will try.but i have a 2 doubts. 1. if i have 3 customer details means, which customer's amount will be detected for above method?? and 2.my input amount is the integer value which i created in my android code ..please check my detail question: https://www.codeproject.com/Questions/1185206/How-do-I-subtract-a-columns-value-amount-from-a-ta
Wessel Beulink 3-May-17 7:55am    
How do you know what amount you need to take if you have 3 customer details?
Member 13168378 3-May-17 8:01am    
actually my android application is verify the number & password (verify.php) which is stored in database, if it is match one more activity will open for that particular customer in android application. in that, it will ask enter the amount.for example in that database there are 3 customers. table fields are id,name,number,password & balance
Wessel Beulink 3-May-17 8:11am    
Than you need to create a new function to handle that or make a extra user handling would be the easiest way. You can also combine you current activity and combine all info you have, followed by a database transaction?

I should suggest to make a balance.php or something simulair
Member 13168378 4-May-17 0:14am    
ok sir, i'll try. thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900