mardi 25 avril 2017

webpage form not sending input to mysql database

I have a web page which needs to send data back to a MySQL database but the first two form boxes data is not sent across to the database.

I have very limited php mysql knowledge and cannot figure out the problem on my own.

//create the connection 
$conn = mysqli_connect($servername, $username, $password, $dbname);

if(!$conn)
{

//Error handler
die("MySQL Connection Error: ".mysqli_error());
}

//Extracting information from the user to add to the outputs table in the Database
if (isset($_POST['confirmbut'])) {
    $sensorname = mysqli_real_escape_string($conn,$_POST['sensorname']);
    $sensorip = mysqli_real_escape_string($conn,$_POST['sensorip']);
    $state = mysqli_real_escape_string($conn,$_POST['state']);

//Selecting Database and inserting user inputted data to the database
    mysqli_query($conn,"SELECT * FROM outputs");
    mysqli_query($conn,"INSERT INTO outputs(Sensor_ID, Sensor_IP, State, Pending_Update) VALUES ('$sensorname', '$sensorip','$state','1')");

    header("location: insertname.php");
}


?>

<!DOCTYPE html>
    <html>
        <head>
        <meta charset="utf-8">
        <title> Switch </title>
    </head>
<body>

<h2 class="title">Please fill in your switches Details</h2>

    <!-- Posts data inserted here -->
    <form method="post" action="insertname.php">

        <!-- Form to enter Device Name, Output IP, State --> 
        <tr>    
            <td>  Relay Name: </td>
            <td><input type="text" name="output name" class="textInput" required="required"></td>
        </tr> 

        <tr>
            <td>  Relay IP:</td>
            <td><input type="text" name="outputIP" class="textInput" required="required"></td>
        </tr>

        <tr>
            <td>  Relay State: On = 1  Off = 0</td>
            <td><input type="text" name="state" class="textInput" required="required"></td>
        </tr>
            <td><input type="submit" name="confirmbut" value="Enter" class="enterbutton" > </td>
        </tr>

       </form>  
    </body>
 </html>




Aucun commentaire:

Enregistrer un commentaire