Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * Following code will create a new transaction row
- */
- // array for JSON response
- $response = array();
- //check for required fields
- if (isset($_POST['title']) && isset($_POST['amount']) && isset($_POST['currencyID']) && isset($_POST['date']) && isset($_POST['groupID']) && isset($_POST['expensesTableID'])){
- $title = $_POST['title'];
- $amount = $_POST['amount'];
- $currencyID = $_POST['currencyID'];
- $date = $_POST['date'];
- $groupID = $_POST['groupID'];
- $expensesTableID = $_POST['expensesTableID'];
- //include db configuration class
- require_once __DIR__ . '/db_config.php';
- //connecting to database
- $mysqli = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD, DB_DATABASE) or die(mysql_error());
- if ($mysqli->connect_errno) {
- printf("Connect failed: %s\n", $mysqli->connect_error);
- exit();
- }
- // mysql inserting a new row
- $result = mysqli_query($mysqli,"INSERT INTO transaction(title, amount, currencyID, date, groupID, expensesTableID) VALUES('$title', '$amount', '$currencyID', '$date', '$groupID', '$expensesTableID');");
- // check if row inserted or not
- if ($result) {
- // successfully inserted into database
- $response["success"] = 1;
- $response["message"] = "Transaction successfully created.";
- // echoing JSON response
- echo json_encode($response);
- }
- }else{
- // required field is missing
- $response["success"] = 0;
- $response["message"] = "Transaction field(s) is missing";
- // echoing JSON response
- echo json_encode($response);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment