0

I'm trying to invoke a PHP script from my HTML file.

Following is my HTML code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Welcome to B.O.A.T</title>
    <link rel="stylesheet" type="text/css" href="CSS/css.css" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>

<body>
    <!-- Navigation Bar -->



    <div class="tab_content">
        <div id="home" class="tab_active">
                <div id="banner-container">
                    <div id="banner">
                        <p id="boat-banner"> Welcome to Bike Operation Automation Technology </p>
                    </div>
                </div>



                <div id="buttons">
                    <form method="post" action="lock.php">
                    <input type="button" name="Lock" class="button" value="LOCK" />
                    </form>

                    <form method="post" action="unlock.php">
                    <input type="button" name="Lock" class="button" value="UNLOCK" />
                    </form>

                    <form method="post" action="ledOn.php">
                    <input type="button" name="Lock" class="button" value="IGNITION ON" />
                    </form>

                    <form method="post" action="ledOff.php">
                    <input type="button" name="Lock" class="button" value="IGNITION OFF" />
                    </form>


                   <form method="post" action="GPSTracker.php">
                    <input type="submit" name="GPSTracker" class="button" value="GPS TRACKER"/>
                    </form>
                </div>
                </div>

         </div>

</body>
</html>

Following is my ledOn.php file that I want to invoke (It's one of those PHP scripts that are not being invoked)

<html>
<head>
<title>LEDON</title>
</head>
<body>
<?php
    define('HOST','mysql.hostinger.in');
    define('USER','u414932932_usr');
    define('PASS','xyz123');
    define('DB','u414932932_bdb');

    $con = mysqli_connect(HOST,USER,PASS,DB);

    //$ign = $_POST['ignition'];


    $sql = "UPDATE BOATOP SET ignition='1' WHERE user_name='boatusr'";
    if(mysqli_query($con,$sql))
    {
        echo 'SUCCESS'; ?>
        <H3> SUCESS </H3>
    <?php 
    }
    else
    {
        echo "FAILURE";
        ?>
        <H3> FAILURE </H3>
      <?php
    }
    mysqli_close($con);
?>

</body>
</html>

When I click the Ignition On button, nothing happens. I don't understand.. Neither do any of the other buttons open their respective PHP files. Where am I going wrong?

4 Answers 4

2

it's an input type="button" which won't submit the form. these should be type="submit"

<div id="buttons">

    <form method="post" action="lock.php">
      <input type="submit" name="Lock" class="button" value="LOCK" />
    </form>

    <form method="post" action="unlock.php">
      <input type="submit" name="Lock" class="button" value="UNLOCK" />
    </form>

    <form method="post" action="ledOn.php">
      <input type="submit" name="Lock" class="button" value="IGNITION ON" />
    </form>

    <form method="post" action="ledOff.php">
      <input type="submit" name="Lock" class="button" value="IGNITION OFF" />
    </form>


    <form method="post" action="GPSTracker.php">
      <input type="submit" name="GPSTracker" class="button" value="GPS TRACKER"/>
    </form>

</div>
Sign up to request clarification or add additional context in comments.

Comments

1

Edit: Someone has pointed out that, we can use input type submit or button type submit.

Functionality wise, they are the same but buttons created with button element offer richer rendering possibilities.

https://www.w3.org/TR/html4/interact/forms.html#h-17.5

<div id="buttons">
        <form method="post" action="lock.php">
            <button type="submit" class="button" value="lock"> LOCK </button>
        </form>
        <form method="post" action="unlock.php">
            <button type="submit" class="button" value="unlock"> UNLOCK </button>
        </form>
        <form method="post" action="ledOn.php">
            <button type="submit" class="button" value="on"> IGNITION ON </button>
        </form>
        <form method="post" action="ledOff.php">
            <button type="submit" class="button" value="off"> IGNITION OFF</button>
        </form>
        <form method="post" action="GPSTracker.php">
            <button type="submit" class="button" value="gps'> GPSTracker </button>
        </form>
    </div>

2 Comments

What are these richer rendering possibilities? Your link only provides the basic html specification. CSS can be used to render input elements just as richly as buttons.
@JeffPuckettII FROM W3: "Buttons created with the BUTTON element function just like buttons created with the INPUT element, but they offer richer rendering possibilities: the BUTTON element may have content. For example, a BUTTON element that contains an image functions like and may resemble an INPUT element whose type is set to "image", but the BUTTON element type allows content."
0

It looks to me like you will be well-served using links instead of buttons for what you are trying to do since there is absolutely no data inside the forms that you are using.

<form method="post" action="ledOn.php">
    <button type="submit" class="button" value="on"> IGNITION ON </button>
</form>

can become

<a href="ledOn.php">
    IGNITION ON
</a>

1 Comment

This is a perfectly valid answer, so I'm not sure why you were downvoted. The simplest answer is usually the best. I had the same thought about simply using links, but I didn't mention anything because it seemed like a nice introduction to forms and how they can be used simply without data. I also noticed that op probably has intentions to develop data usage because of the commented stub //$ign = $_POST['ignition'];
0

You can do this in two ways

1) Need to change the button into input type submit like you did for last form:-

<input type="submit" name="GPSTracker" class="button" value="GPS TRACKER"/>

2) You need to use jQuery for this you need to add id in the form and click event on button like:-

 <form method="post" action="lock.php" id="form_id">
  <input type="button" name="Lock" class="button" value="LOCK" onclick=" $('#form_id').submit();" />

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.