Guide on Retrieving the Most Recent Database Entry with the Aid of AngularJS and PHP

I have developed two unique web pages. One is called BookTicket which contains a form with two buttons. The first button submits the form and stores the information in a database, while the second button navigates to a payment page. The other page is called Payment. In the BookTicket page, the submitted form values are stored correctly in the database. Now, I want to display the currently entered data from the form on the Payment page, so that users can see the details they have entered. How can I achieve this? What do I need to write in the payment.html page and the PHP page for payment in order to retrieve the currently inserted record?

Here is an example of the code in the BookTicket.html file:


<div class="col-lg-12 well">
  <h2 style="text-align:center;">BOOK MOVIE TICKETS</h2>
  
  ...
  
  <form name="bookticket" ng-app="BookTicket" ng-controller="BookTicketCtrl" ng-submit="submitForm(bookticket.$valid)" novalidate>

    ...
    
    <button type="submit" class="btn btn-success col-lg-8 col-lg-offset-2">REGISTER DETAILS</button>
    <button type="submit" class="btn btn-success col-lg-8 col-lg-offset-2" style="margin-top:1.5em;" ui-sref="payment">PROCEED TO PAY</button>

  </form>
</div>

And here is an example of the code in the main.js file:

// Angular controller for BookTicket
app.controller('BookTicketCtrl', function($scope, $location, $http) {
  ...
});

Lastly, here is an example of the code in the BookTicket.php file:

<?php
...

$data = json_decode(file_get_contents("php://input"));
$city = mysql_real_escape_string($data->city);
$locations = mysql_real_escape_string($data->locations);
$theater = mysql_real_escape_string($data->theater);
$showdate = mysql_real_escape_string($data->showdate);
$showtime = mysql_real_escape_string($data->showtime);
$classes = mysql_real_escape_string($data->classes);
$seatno = mysql_real_escape_string($data->seatno);

...
?>

Answer №1

Retrieve the ID of the most recent insertion in a database table using the mysql_insert_id() function.

Here's an example:

$recent_insertion_id = mysql_insert_id();

To learn more about this function, visit http://php.net/manual/en/function.mysql-insert-id.php.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Transform the JSON data into an array

I am attempting to save the titles in an array and retrieve the lengthy cmcontinue string from the following URL. http://en.wikipedia.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:1980_births&format=json Here is my current ...

Is there a way to successfully submit a form in PHP once it has been validated using JavaScript?

I'm interested in creating a register/login system. I've set up a form in Register.php and handled the validation part in JavaScript, but I'm encountering an issue where no values are being sent to the database upon clicking submit. Registe ...

Which specific button is selected out of a variable number of buttons?

In my database, I store an autoincrement id along with the location and date of each trip. The piece of code below helps me display the results of my query. $mysqli = new mysqli("localhost", "root", "password", "trip"); $result = $mysqli->query("SELECT ...

Invoke a Python function from JavaScript

As I ask this question, I acknowledge that it may have been asked many times before. If I missed the answers due to my ignorance, I apologize. I have a hosting plan that restricts me from installing Django, which provided a convenient way to set up a REST ...

Retrieving all rows from MySQL using PHP when a variable is empty

$frame_type = ''; $ret = mysqli_query($con, "select * from products where status='1' AND frame_type = '$frame_type' "); while ($row = mysqli_fetch_array($ret)) { $emparray[] = $row; } Retrieve All ...

Obtain the initial row (image) from the ACF repeater field

I am currently utilizing the ACF plugin on my website and looking to showcase only the first row (which contains an image URL) of a repeater field from child pages, all on a single page. On my website page, although all images are loaded, only the first o ...

Methods for passing JavaScript variables to PHP

I have encountered this problem on Stack Overflow before, but I couldn't find a solution that worked for me. I am using Codeigniter and have a form where users can rate a product. What I need to achieve is to insert the user's rating into the dat ...

Deleting a symbolic link using PHP on a Windows system

What is the best way to delete a symbolic link using PHP on a Windows system? When attempting to remove a symlink by running the following code: mkdir('test'); symlink('test', 'test2'); unlink('test2'); An error i ...

Exploring the methods of accessing $scope within an AngularJS directive

My custom directive is designed for handling form controls like input, select, and radio buttons. Each input has a default value set, and if the corresponding value exists in $scope.answers, it should be displayed in the input box. The code snippet below ...

AngularJS allows you to toggle the visibility of a div at set intervals, creating

I am struggling with the task of showing and hiding a div that serves as an alert for my application. Currently, I am using $interval to create a continuous show and hide action on the div. However, what I aim for is to have the DIV visible for X amount o ...

Transmit data from an HTML form to PHP using JSON

I am attempting to utilize JavaScript to send POST data. I have the data in an HTML form: <form name="messageact" action=""> <input name="name" type="text" id="username" size="15" /> <input name="massage" type="text" id="usermsg" si ...

Using jQuery Datepicker Beforeshowday to dynamically retrieve an array of unavailable dates through Ajax

Currently, I am working on implementing a datepicker that will update an array of unavailable dates. While it successfully works with a PHP variable being passed, the challenge lies in properly returning the data for the option (as it is throwing a console ...

AngularJS faces issue with view not reflecting changes made to model

A web-based game I am developing lets players bid on cards and trade them with one another. The technology stack for this application includes Node, Express, MongoDB, and Angular. The player avatars and names, along with their connection status, are displ ...

Steps to remotely access a file stored on a Windows drive from Ubuntu using PHP

In my Windows environment, I had the following command: exec('copy /V "'.$file.'" "'.$dest.'"'); where $file is a REMOTE file in a windows drive such as: \\server\dr1$\folder\file \\serv ...

What is the best way to transmit JSON data to PHP using AJAX?

I built a form to collect user information, which I then encode into JSON and send to PHP for storage in a MySQL database using AJAX. Below is the script I included just before the closing </body> tag. Unfortunately, I'm facing an issue where t ...

PHP Issues with PHP While and ForEach loops causing unexpected outcomes

I am having trouble with my code logic. Currently, I am using a while loop to retrieve associated records for each meal_id. However, my foreach loop is not functioning as expected. My aim is to display the meal information first and then list the meal item ...

Retrieving Information from Ajax Response Following a Successful Insert Query in Codeigniter

I am trying to use ajax method to insert form data into a database and then redirect it to the next page. I have successfully passed the data in ajax and inserted it into the database table. However, I am facing an issue with getting the generated referenc ...

Custom styling options for Google Chart

I have been attempting to dynamically adjust the width and height of a google-chart directive by utilizing input field values. However, I am encountering an issue where the width and height are not updating as expected. Check out the Plunker here $scope. ...

Utilizing AngularJS to upload numerous independent attachments to CouchDB

My goal is to upload multiple files to a couchdb document using angularjs. Despite my efforts with an angular.forEach loop, I am facing issues as the asynchronous $http calls do not wait for the previous loop to finish before moving on to the next one. Her ...

Slow query in MySQL and PHP causing a delay in execution time that has been exceeded

I am facing an issue with fetching records from my 20 tables which each contain over 5000 records. The data fetching process is extremely slow and instead of displaying the data, I am getting the following error: Fatal error: Maximum execution time of 3 ...