0

I am attempting to submit form data to my MySQL Database but when I press submit the browser page remains completely white (error reporting is on) and no data is submitted to the database, my code is below any help would be appreciated :)

<?php
    session_start();

    include_once("db.php");

    if(isset($_POST['widget_name']) && isset ($_POST['widget_type']) && isset ($_POST['language_support']) && isset ($_POST['widget_description']) && isset ($_POST['widget_dependencies'])){   
        if($_POST['widget_name'] != "" && $_POST['widget_type'] != "" && $_POST['language_support'] != "" && $_POST['widget_description'] != "" && $_POST['widget_dependencies'] != ""){
            $name = $_POST['widget_name'];
            $type = $_POST['widget_type'];
            $language = $_POST['language_support'];
            $description = $_POST['widget_description'];
            $dependencies = $_POST['widget_dependencies'];

            $sql_store = "INSERT INTO 'submissions' (ID, Author, Widget_Name, Widget_Type, Language_Support, Description, Dependencies, Icon) VALUES ('', '', '$name', '$type', '$language', '$description', '$dependencies', '')";
            $sql = mysqli_query($db, $sql_store) or die(mysql_error());

        } else {echo "<span class='enter-data' id='enter-data'>You need to enter data in all fields.</span>";}

    } else {echo "<span></span>";}

    /* if(isset($_POST['submit'])){

            $iconName = mysql_real_escape_string($_FILES["image"]["name"]);
            $iconData = mysql_real_escape_string(file_get_contents ($_FILES["image"]["tmp_name"]));
            $imageType = mysql_real_escape_string($_FILES["image"]["type"]);

            if(substr($imageType,0,5) == "image"){
                mysqli_query("INSERT INTO 'submissions' VALUES('','$ImageName','$imageData') ")
            } else {echo "Only images allowed.";}

    } */

?>

<!DOCTYPE html>
<html>
</head>
    <title>Test</title>
    <style>
    body{font-family:Helvetica;}

    span{margin-left:10; width:30%; display:inline-block;} 

    input{margin-top:10; width: 60%;}

    #submission-form{float:left;}
    #text-inputs{width:500px; background:red; border-radius:15px; display:inline-block;}
    #image-upload{width:500px; background:blue; border-radius:15px; display:inline-block; vertical-align:top; height: 250; width: 250px;}

    .description-box{margin-top:10; min-width:60%; max-width:60%; height:100;}
    .dependencies-box{margin-bottom:10;}
    .submit-button{float:right; width:20%; margin-top:-10; margin-right:10;}

    input[type='file'] {
  color: transparent;
}
    </style>    
<head>

<body>

<div id="submission-form">
    <form action="index.php" method="POST" enctype="multipart/form-data">
                <div id="image-upload">
            <span style="width:auto; margin-top:10;">Widget Icon:</span>
            <input style="float:right; margin-right: -15;" type="file" name="widget_icon" onchange="loadFile(event)">
            <center><img style="width: 80%; height: auto;  margin-top:5;" src="http://placehold.it/500x500" id="output"></center>
                <script>
                    var loadFile = function(event) {
                        var output = document.getElementById('output');
                    output.src = URL.createObjectURL(event.target.files[0]);
                    };
                </script>
        </div>


        <div id="text-inputs">
            <span>Widget Name: </span><input type="text" name="widget_name" value="">
            <br>
            <span>Widget Type: </span><input type="text" name="widget_type" value="">
            <br>
            <span>Language Support: </span><input type="text" name="language_support" value="">
            <br>
            <span style="vertical-align:top; padding-top:10;}">Description: </span><textarea rows="1" cols="26" name="widget_description" value="" class="description-box"></textarea>
            <br>
            <span>Dependencies: </span><input type="text" name="widget_dependencies" value="" class="dependencies-box">
            <br>
        </div>

        <br>

        <br>

        <input type="submit" name="submit_data" value="Submit" class="submit-button">   
    </form>
</div>


</body>
</html>
Dylan Duff
  • 71
  • 1
  • 6

1 Answers1

1

Your INSERT statement is wrong. Table name does not need the single-quotes. Change to:

$sql_store = "INSERT INTO submissions (ID, Author, Widget_Name, Widget_Type, Language_Support, Description, Dependencies, Icon) VALUES ('', '', '$name', '$type', '$language', '$description', '$dependencies', '')";

Be aware that this code allows sql injection. Have a look at: How can I prevent SQL injection in PHP?

Community
  • 1
  • 1
deChristo
  • 1,860
  • 2
  • 17
  • 29