Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Created by PhpStorm.
- * User: TheDigitalAcademy
- * Date: 16/02/24
- * Time: 12:59 PM
- */
- $sever = 'whm.empirestate.co.za';
- $user = 'empirest_applica';
- $pass = 'iloveempirestate';
- $dbName = 'da_app_db';
- try {
- $db = new PDO("mysql:host=whm.empirestate.co.za;dbname=da_app_db", "empirest_applica", "iloveempirestate");
- } catch (Exception $e) {
- die("Error : " . $e->getMessage());
- }
- if (!empty($_POST)) {
- if (isset($_POST['name'])) {
- $username = $_POST['name'];
- }
- if (isset($_POST['email'])) {
- $email = $_POST['email'];
- }
- if (empty($username) || empty($pass) ) {
- // Create some data that will be the JSON response
- $response["success"] = 0;
- $response["message"] = "Please fill in all fields.";
- //die will kill the page and not execute any code below, it will also
- //display the parameter... in this case the JSON data our Android
- //app will parse
- die(json_encode($response));
- }
- $query_params = array(
- ':user' => $_POST['username']
- );
- $query = "INSERT INTO Intern_tbl (Name, Personal_email)
- VALUES
- ('$username', '$email')";
- try {
- $stmnt = $db->prepare($query);
- $result = $stmnt->execute($query_params);
- } catch (Exception $e) {
- // For testing, you could use a die and message.
- die("Failed to run query: " . $ex->getMessage());
- //or just use this use this one:
- //$response["success"] = 0;
- //$response["message"] = "Database Error2. Please Try Again!";
- //die(json_encode($response));
- }
- //If we have made it this far without dying, we have successfully added
- //a new user to our database. We could do a few things here, such as
- //redirect to the login page. Instead we are going to echo out some
- //json data that will be read by the Android application, which will login
- //the user (or redirect to a different activity, I'm not sure yet..)
- $response["success"] = 1;
- $response["message"] = "Username Successfully Added!";
- echo json_encode($response);
- //for a php webservice you could do a simple redirect and die.
- //header("Location: login.php");
- //die("Redirecting to login.php");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement