Not sure what I am looking for

Here’s a screenshot:

Ok. Well, I did read the tutorial, but probably not understood it all. So, the myscript.php is only working in the background. That’s where I’m supposed to write the insert into db code? So, when a user is clicking on the save button it will do the INSERT from myscript.php and then they have to continue to a new page where my website is moving on to?

Isn’t there a way to make the SAVE button take the user to a new page? So, when they have entered the text they click on the button and it takes them to test_two.php Or do I have to have the SAVE button to store the things and then another button that say CONTINUE? Is that the best way to use this?

Correct.

I would probably do it like so:

User enters input into header, content and footer areas.
User clicks “Save and proceed”
This fires off an ajax request (as we have set up here) to a PHP script.
The PHP script inserts the data to the database, then returns a code indicating that the insert was successful.
The success callback picks up this code and then redirects the user to the next page.

e.g.

success: function(code) {
     if (code === "success"){
         window.location.replace("http://mysite.com/page2.html");
    }
}

Job done :slight_smile:

Sounds right, but where is that success code generated and how? If I have the mysql insert on the my script.php
How would that code be generated? Do you mean that I should put a string after the INSERT into db like this:

$code = 'success';

Or am I missing something here?

Exactly.
Maybe wrap the insert in a try - catch block, then return the code after a successful insert.

Does that make sense?

Sorry, didn’t understand that last one.
“Maybe wrap the insert in a try - catch block, then return the code after a successful insert.”

Hi,

Well you use try ... catch when doing something that could go wrong, so that you can either ensure the operation completes successfully, or catch the error.

Something like this:

<?php

// Get $_POST variables
$header = $_POST['header'];
$content = $_POST['content'];
$footer = $_POST['footer'];

$status= "";

function get_db_connection( ){
  // db connection stuff here
}

try {
  $conn = get_db_connection();
  // insert header, content & footer into db here
  $status= "success"
} catch (Exception $e) {
  $status= "faliure"
}

echo $status;
?>

I didn’t test this.