Home>
(Overview)

I want to decorate an existing php file using Bootstrap.

I created a simple EC site with php, but I want to make the decoration part cool.
I'd like to use Bootstrap's example and decorate it, but it doesn't work well and it's unknown even if I examine it
I would like to ask a question.

Specific issues
-Login screen input check screen cannot be decorated.

Status

・ We built a simple EC site with PHP.
・ I just want to decorate using Bootstrap because it is not decorated at all with CSS.
-Screen transition of login.html → login-check.php → ec_top.php

I want to hear

-Convert an existing PHP file into an html file for decoration, decorate with Bootstrap, etc., and embed the original php part, "I want to run an existing program in the decorated state."

Current screen.


The design I want to realize.

https://getbootstrap.com/docs/4.1/examples/navbar-bottom/

Tried

1. Since the above file is a php file, change it to an html file
2. Add code to load Bootstrap
3. Load the current php part.
* Currently, an error occurs when converting a php file to a html file, so
Not even decorated with Bootstrap.

※ After this, I was trying to copy and paste the Bootstrap example source.
The following site.
https://getbootstrap.com/docs/4.1/examples/navbar-bottom/

Source code

(Current status)

<? php
try
{
// omitted for database connection settings

if ($rec == false)
{
    echo 'Your email address or password is incorrect.<br />';
    echo '<a href = "member_login.html">Back</a>';
}
else
{
    session_start ();
    $_SESSION ['member_login'] = 1;
    $_SESSION ['member_code'] = $rec ['code'];
    $_SESSION ['member_name'] = $rec ['name'];
    header ('Location: shop_list.php');
    exit ();
}
}
catch (Exception $e)
{
    echo 'I'm very sorry for the inconvenience. ';
    exit ();}
?>

↓ ↓ ↓
(I tried it)

<! DOCTYPE html>
<html lang = "en">
  <head>
    <meta charset = "utf-8">
    <meta http-equiv = "X-UA-Compatible" content = "IE = edge">
    <meta name = "viewport" content = "width = device-width, initial-scale = 1">
    <title>Bootstrap Sample</title>
            <!-Bootstrap CSS reading->
            <link href = "css/bootstrap.min.css" rel = "stylesheet">
            <!-Load jQuery->
            <script src = "https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
            <!-Load Bootstrap JS->
            <script src = "js/bootstrap.min.js"></script>
          </head>
            <body>
        <? php
        try
        {
        // omitted for database connection
        if ($rec == false)
        {
            echo '<p>Email address or password is wrong.<br /></p>';
            echo '<p><a href = "member_login.html">Back</a></p>';
        }
        else
        {
            session_start ();
            $_SESSION ['member_login'] = 1;
            $_SESSION ['member_code'] = $rec ['code'];
            $_SESSION ['member_name'] = $rec ['name'];
            header ('Location: shop_list.php');
            exit ();
        }
        }
        catch (Exception $e)
        {
            echo 'I'm very sorry for the inconvenience. ';
            exit ();
        }
        ?>
            </body>
</html>
Summary of what I want to hear

-Since existing php files are not decorated at all, I want to decorate them using Bootstrap.
・ However, there is no way to consider how to convert a php file into an html file and embed the original php part.
・ I would like to give you advice on how to achieve this.

Supplement

-Since the product list screen is also created with a php file (list.php), if you can tell us this time,
I want to apply it.

  • Answer # 1

    PHP processing cannot be performed on HTML files. First, let's return the file from PHP to HTML.

    I think the syntax is correct, but is the BootStrap file located in the CSS folder?
    In the original syntax, the HTML description is

    echo<<<HTML_END;
    <! DOCTYPE html>
    <html lang = "en">
      <head>
        <meta charset = "utf-8">
        <meta http-equiv = "X-UA-Compatible" content = "IE = edge">
        <meta name = "viewport" content = "width = device-width, initial-scale = 1">
        <title>Bootstrap Sample</title>
                <!-Bootstrap CSS reading->
                <link href = "css/bootstrap.min.css" rel = "stylesheet">
                <!-Load jQuery->
                <script src = "https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
                <!-Load Bootstrap JS->
                <script src = "js/bootstrap.min.js"></script>
              </head>
                <body>
    HTML_END;
    Let's output directly like

    . Design the web with an image that builds HTML on the server side.

  • Answer # 2

    PHP just interprets something as HTML on the server and outputs a character string, for example, with echo, and so on.
    "Decorating PHP" is a different dimension.
    Switch to the idea of ​​"decorating HTML output in PHP".
    In .html, PHP will not work unless special settings are made. You don't need to change.php to .html unless you have special settings.

    In a simple example, the results confirmed on the screen are exactly the same.

    <style>
    p {
     color: red;
    }
    </style>
    <? php
    echo "<p>test</p>";
    <? php
    echo "
    <style>
    p {
     color: red;
    }
    </style>
    <p>test</p>";

  • Answer # 3

    Because you are not at the level where you can publish your EC site in the first place, please learn again. I have litigation risk

    Although other people have commented, please write the content you want to display correctly in html.
    If you still have Bootstrap problems, cut them out and ask questions.
    Then replace the part of the html that you want to make variable with the display contents as a variable.
    All that remains is to incorporate the variable as logic.

    Hereafter, regarding this presented script

    I understand that you need to run it as php.
    When running as php, there is a problem with the handling of the header (it is not recommended to output others before outputting the header function)
    Since logic and view are not separated, I think that it can be handled naturally by separating them.

    Are you saving your raw password? Since there is if ($rec == false), I feel like comparing passwords with where.
    For security reasons, we recommend using some kind of framework.