Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 74381

How is PHP seeing the input fields as null when they contain data?

$
0
0

Hi I'm trying to get data from a form and send it to php which will then upload it to a MySQL.However , the input fields seem to be empty because i get this "All fields are required !"

inputting data - https://imgur.com/nBHfkYX result - https://imgur.com/X8YXaco

html

<form target="_blank" method="POST" action="connect.php">
                        <input type="text" value="-" name="productname" id="item-name-form">
                        <h4>MODEL LIST</h4>
                        <select id="model" name="productmodel">
                            <option value="Iphone X/XS">Iphone X/XS</option>
                            <option value="Iphone XR">Iphone XR</option>
                            <option value="Iphone XS Max">Iphone XS Max</option>

                        </select><br><br>

                        <h4>QUANTITY</h4>
                        <input id="qty" type="number" name="productquantity" min="1" value="1" required><br><br>
                        <h4>COLOR</h4>
                        <select id="clr-list" name="productcolor"></select><br><br>
                        <input id="submit-button" type="submit" value="ADD TO CART">

                    </form><br>
                    <!--END OF FORM-->

connect.php

<?php

    $productname = filter_input(INPUT_POST, 'productname');
    $productmodel = filter_input(INPUT_POST, 'productmodel');
    $productquantity = filter_input(INPUT_POST, 'productquantity');
    $productcolor = filter_input(INPUT_POST, 'productcolor');


    if(trim($productname)!=null && trim($productmodel)!=null && trim($productquantity)!=null && trim($productcolor)!=null){
        $host = "localhost";
        $dbusername = "root";
        $dbpassword = "";
        $dbname = "nodemysql";

        //connection
        $conn = new mysqli($host ,$dbusername,$dbpassword,$dbname);
        if(mysqli_connect_error()){
            die('Connect error (' .mysqli_connect_errno() . ') ' 
            .mysqli_connect_error()); 
        }
        else{
            $sql = "INSERT INTO posts (productname,productmodel,productquantity,productcolor)
            values ('$productname','$productmodel','$productquantity','$productcolor')";

            if($conn->query($sql)){
                echo "new record was inserted successfully.";
            }
            else{
                echo "Error: " .$sql ."<br>" .$conn->error;
            }
            $conn->close();
        }
    }
    else{
        echo "All fields are required !";
        die();
    }
?>

Thank you


Viewing all articles
Browse latest Browse all 74381

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>