Hi i'm practising in creating an android application where a user can store records into an external database (my local server in myphpadmin). I can store records into the the database just fine but I wish to prevent the same information being entered twice. I wish for my system to check against the database if the record does exist, if it does an error should be pointed in the existence of the data.
Doing the error handling is no problem but the problem comes in when i use the PHP codes to check the server (im not very good with php) I have two php codes where it checks the records on the database and I was wondering what can I do in order for it to check data duplication. My friend helped me with the php files before he went on for vacation and I'm at a dead end at the moment for php.
The first php file is to add the record into the database.
<?php
$response = array();
if (isset($_POST['name']) && isset($_POST['datetime']) && isset($_POST['log'])) {
$name = $_POST['name'];
$datetime = $_POST['datetime'];
$log = $_POST['log'];
require_once __DIR__ . '/db_connect.php';
$db = new DB_Connect();
$result = mysql_query("INSERT INTO bookingdb(name, datetime, log) VALUES('$name', '$datetime', '$log')");
if ($result) {
$response["success"] = 1;
$response["message"] = "Booking created.";
echo json_encode($response);
} else {
$response["success"] = 0;
$response["message"] = "Error.";
echo json_encode($response);
}
} else {
$response["success"] = 0;
$response["message"] = "Information is missing";
echo json_encode($response);
}
?>
The second php file is to modify the records in the database.
<?php
$response = array();
if (isset($_POST['bid']) && isset($_POST['name']) && isset($_POST['datetime']) && isset($_POST['log'])) {
$bid = $_POST['bid'];
$name = $_POST['name'];
$datetime = $_POST['datetime'];
$log = $_POST['log'];
require_once __DIR__ . '/db_connect.php';
$db = new DB_Connect();
$result = mysql_query("UPDATE bookingdb SET name = '$name', datetime = '$datetime', log = '$log' WHERE bid = $bid");
if ($result) {
$response["success"] = 1;
$response["message"] = "Booking created.";
echo json_encode($response);
} else {
}
} else {
$response["success"] = 0;
$response["message"] = "Information is missing";
echo json_encode($response);
}
?>