0

I have a pop up file in popup.html and I have a data.php file in root folder. When user click on submit then data.php is on form action. So I want to show modal. Html file when data.php echo command implement.

Baiscally i want to access modal.html file on the output of data.php.

modal.html

<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
</head>
<body>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header" style="border-bottom:0px;">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
      </div>
      <div class="modal-body">
  <h4 class="text-center" style="font-size:30px;padding:30px;">Thank you for Booking!</h4><p Your booking has been confirmed. Please be present 10 minutes before your booking slot to avoid any inconvenience. </p>
   </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">OK</button>
      </div>
    </div>
  </div>
</div>
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</body>
</html>

data.php

<?php
$servername = "localhost";
$username = "root";
$password = "xxx";
$dbname = "xxxx";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
$sql = "INSERT INTO data (name,phone,email,date,time)
VALUES ('$_POST[name]', '$_POST[phone]', '$_POST[email]',  '$_POST[date]', '$_POST[time]')";
if (mysqli_query($conn, $sql)) {
    echo "$(<modal.html)"
} else {
    echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}

mysqli_close($conn);
?>

So I want to access the file on echo

Danila Ganchar
  • 10,266
  • 13
  • 49
  • 75
Ashu Garg
  • 5
  • 1
  • 9
  • If you want to show modal box. Simply use : $('#myModal').show(); You don't have to use different page for that use the same page – Happy Coding Aug 17 '15 at 12:28
  • i want to show the html code of modal.html file – Ashu Garg Aug 17 '15 at 12:31
  • 1
    Unrelated issue but your code is wide open for SQL injections. – chris85 Aug 17 '15 at 12:34
  • If you're trying to include an html file in PHP, check out http://stackoverflow.com/questions/12294120/how-to-embed-html-files-in-php-code – harris Aug 17 '15 at 12:36
  • No. this question os diffrent. I have a file modal.html. I wan to show the output of this file in echo function of data.php – Ashu Garg Aug 17 '15 at 12:40
  • Different how? You want data.php to display modal.html if the query succeeds? Still sounds like include is the way to go. – harris Aug 17 '15 at 13:04

3 Answers3

1

I suggest to keep it simple unless you want to manipulate the data in the files:

$file = './path/to/modal.html';

include $file;      // Throws warnings if file does not exist
include_once $file; // Does not include if file is already included.
require $file;      // Errors if file does not exist.
require_once $file; // Errors when file is already included.

With functions like readfile() & file_gets_contents() you can catch the data in a variable and replace certain values if desired. include and require also parse the file and directly echo it automatically.

Also, since you're using a modal setup in the html code by bootstrap, you should add the following below the other script includes.

<script>
  $('#myModal').show();
</script>

However I have to say that how this is created is wrong.

  • You're viable to SQL injection attacks.
  • You should use JSON for a nice server response.
Xorifelse
  • 7,878
  • 1
  • 27
  • 38
0

You can use

readfile("/path/to/file"); //It is better

or

echo file_get_contents("/path/to/file");   //may not work if large files

to read contents of html page and display in browser

  • The effect is exactly the same as using include, as I mentioned in the comments and mentioned in the other answer. – harris Aug 18 '15 at 08:02
  • readfile('file.php'); will just read in the file and send it out as is to the browser.. include('file.php'); will send that file through the php parser and evaluate the code in it.... –  Aug 18 '15 at 18:00
0

Difference between include() and readfile()

fastest and best way to do this would be to use the php include function. the server hit from doing this is very minimal and you would never notice the difference between using a include or just simply having the code right in the page. readfile is mainly used for processing files and has a lot more overhead with it than include since include just dumps the file in.

Using javascript is not a good way to do it, especially for navigation content since it relies too much on the browser side and all of its fun variations. if a user doesn't have javascript, there isn't a way to then use php or ssi since php and ssi are processed before the page is displayed to the browser, hence before javascript would have a chance to run.

Community
  • 1
  • 1