HTML Form: Select-Option to insert data into MySQL phpmyadmin databaseWhich MySQL data type to use for storing boolean valuesHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to 'insert if not exists' in MySQL?How can I set the default value for an HTML <select> element?Insert into a MySQL table or update if existsWhat does enctype='multipart/form-data' mean?How to get the sizes of the tables of a MySQL database?jQuery Get Selected Option From Dropdownphp script echoing part of the php instead of what intended

Greco-Roman egalitarianism

Melting point of aspirin, contradicting sources

Aligning individual characters/glyphs like a monospace font

Why do IPv6 unique local addresses have to have a /48 prefix?

Freedom of speech and where it applies

Longest common substring in linear time

Drawing ramified coverings with tikz

How can Trident be so inexpensive? Will it orbit Triton or just do a (slow) flyby?

Should I install hardwood flooring or cabinets first?

ArcGIS not connecting to PostgreSQL db with all upper-case name

Why did the EU agree to delay the Brexit deadline?

Varistor? Purpose and principle

Query about absorption line spectra

Can I use my Chinese passport to enter China after I acquired another citizenship?

When quoting, must I also copy hyphens used to divide words that continue on the next line?

Find last 3 digits of this monster number

Would it be legal for a US State to ban exports of a natural resource?

Should I stop contributing to retirement accounts?

Are all species of CANNA edible?

Can somebody explain Brexit in a few child-proof sentences?

Is there a conventional notation or name for the slip angle?

Can someone explain how this makes sense electrically?

List of people who lose a child in תנ"ך

Could the E-bike drivetrain wear down till needing replacement after 400 km?



HTML Form: Select-Option to insert data into MySQL phpmyadmin database


Which MySQL data type to use for storing boolean valuesHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to 'insert if not exists' in MySQL?How can I set the default value for an HTML <select> element?Insert into a MySQL table or update if existsWhat does enctype='multipart/form-data' mean?How to get the sizes of the tables of a MySQL database?jQuery Get Selected Option From Dropdownphp script echoing part of the php instead of what intended













3















I have a php file named "add_report" with a form inside it. All my inputs are running, i can input data into my database, but everytime I use the select-option. my database accepts it as null. Why is that?



This is my form "add_report.php"



<div class="wrapper">
<form action="add_report_backend.php" method="post">
<input type="hidden" name="id">
<label>Agency: </label> <input class="input1" type="text" name="agency" value="CAAP" required readonly><br>
<label>File Name: </label> <input class="input2" type="text" name="filename" placeholder="file.pdf/xlsx/xls/docx" required autofocus><br>
<label>File Type: &nbsp;</label> <select name="myselectbox">
<option name="myoption1" value="myoption1">pdf</option>
<option name="myoption2" value="myoption2">excel</option>
<option name="myoption3" value="myoption3">word</option>
</select><br>
<label>Date: </label> <input class="input4" type="Date" name="date" required><br>
<input class="submit-btn" type="submit" name="insert" value="Save">
</form>
</div>


And this another php file "add_report_backend.php"



<?php
if(isset($_POST['insert']))

try
$pdoConnect = new PDO("mysql:host=localhost;dbname=annualdb","root","");

$pdoConnect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
catch (PDOException $exc)
echo $exc->getMessage();
exit();

$id = $_POST['id'];
$Agency = $_POST['agency'];
$FName = $_POST['filename'];
$FType = $_POST['filetype'];
$Date = $_POST['date'];

$pdoQuery = "INSERT INTO `company_report`(`agency`, `filename`, `filetype`, `date`) VALUES (:Agency,:FName,:FType,:Date)";
$pdoResult = $pdoConnect->prepare($pdoQuery);
$pdoExec = $pdoResult->execute(array(":Agency"=>$Agency,":FName"=>$FName,":FType"=>$FType, ":Date"=>$Date));

if($pdoExec)


$pdoQuery = 'SELECT * FROM company_report';
$pdoResult = $pdoConnect->prepare($pdoQuery);
$pdoResult->execute();
while ($row = $pdoResult->fetch())
echo $row['id'] . "
header("Location: ../agencies/company.php");
exit;
else
echo 'Data Not Inserted';


$pdoConnect = null;
?>









share|improve this question






















  • Have you checked if posted datas are not null before it saves to your database?

    – Roshan
    Mar 7 at 9:10











  • The data in my table are NULL as default, should I change them as not null?

    – Justin Saints
    Mar 7 at 9:31











  • What have you tried to debug the problem? Have you checked whether the proper data is transmitted to the server, whether it reaches the server, whether the proper variables where filled?

    – Nico Haase
    Mar 7 at 9:44















3















I have a php file named "add_report" with a form inside it. All my inputs are running, i can input data into my database, but everytime I use the select-option. my database accepts it as null. Why is that?



This is my form "add_report.php"



<div class="wrapper">
<form action="add_report_backend.php" method="post">
<input type="hidden" name="id">
<label>Agency: </label> <input class="input1" type="text" name="agency" value="CAAP" required readonly><br>
<label>File Name: </label> <input class="input2" type="text" name="filename" placeholder="file.pdf/xlsx/xls/docx" required autofocus><br>
<label>File Type: &nbsp;</label> <select name="myselectbox">
<option name="myoption1" value="myoption1">pdf</option>
<option name="myoption2" value="myoption2">excel</option>
<option name="myoption3" value="myoption3">word</option>
</select><br>
<label>Date: </label> <input class="input4" type="Date" name="date" required><br>
<input class="submit-btn" type="submit" name="insert" value="Save">
</form>
</div>


And this another php file "add_report_backend.php"



<?php
if(isset($_POST['insert']))

try
$pdoConnect = new PDO("mysql:host=localhost;dbname=annualdb","root","");

$pdoConnect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
catch (PDOException $exc)
echo $exc->getMessage();
exit();

$id = $_POST['id'];
$Agency = $_POST['agency'];
$FName = $_POST['filename'];
$FType = $_POST['filetype'];
$Date = $_POST['date'];

$pdoQuery = "INSERT INTO `company_report`(`agency`, `filename`, `filetype`, `date`) VALUES (:Agency,:FName,:FType,:Date)";
$pdoResult = $pdoConnect->prepare($pdoQuery);
$pdoExec = $pdoResult->execute(array(":Agency"=>$Agency,":FName"=>$FName,":FType"=>$FType, ":Date"=>$Date));

if($pdoExec)


$pdoQuery = 'SELECT * FROM company_report';
$pdoResult = $pdoConnect->prepare($pdoQuery);
$pdoResult->execute();
while ($row = $pdoResult->fetch())
echo $row['id'] . "
header("Location: ../agencies/company.php");
exit;
else
echo 'Data Not Inserted';


$pdoConnect = null;
?>









share|improve this question






















  • Have you checked if posted datas are not null before it saves to your database?

    – Roshan
    Mar 7 at 9:10











  • The data in my table are NULL as default, should I change them as not null?

    – Justin Saints
    Mar 7 at 9:31











  • What have you tried to debug the problem? Have you checked whether the proper data is transmitted to the server, whether it reaches the server, whether the proper variables where filled?

    – Nico Haase
    Mar 7 at 9:44













3












3








3








I have a php file named "add_report" with a form inside it. All my inputs are running, i can input data into my database, but everytime I use the select-option. my database accepts it as null. Why is that?



This is my form "add_report.php"



<div class="wrapper">
<form action="add_report_backend.php" method="post">
<input type="hidden" name="id">
<label>Agency: </label> <input class="input1" type="text" name="agency" value="CAAP" required readonly><br>
<label>File Name: </label> <input class="input2" type="text" name="filename" placeholder="file.pdf/xlsx/xls/docx" required autofocus><br>
<label>File Type: &nbsp;</label> <select name="myselectbox">
<option name="myoption1" value="myoption1">pdf</option>
<option name="myoption2" value="myoption2">excel</option>
<option name="myoption3" value="myoption3">word</option>
</select><br>
<label>Date: </label> <input class="input4" type="Date" name="date" required><br>
<input class="submit-btn" type="submit" name="insert" value="Save">
</form>
</div>


And this another php file "add_report_backend.php"



<?php
if(isset($_POST['insert']))

try
$pdoConnect = new PDO("mysql:host=localhost;dbname=annualdb","root","");

$pdoConnect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
catch (PDOException $exc)
echo $exc->getMessage();
exit();

$id = $_POST['id'];
$Agency = $_POST['agency'];
$FName = $_POST['filename'];
$FType = $_POST['filetype'];
$Date = $_POST['date'];

$pdoQuery = "INSERT INTO `company_report`(`agency`, `filename`, `filetype`, `date`) VALUES (:Agency,:FName,:FType,:Date)";
$pdoResult = $pdoConnect->prepare($pdoQuery);
$pdoExec = $pdoResult->execute(array(":Agency"=>$Agency,":FName"=>$FName,":FType"=>$FType, ":Date"=>$Date));

if($pdoExec)


$pdoQuery = 'SELECT * FROM company_report';
$pdoResult = $pdoConnect->prepare($pdoQuery);
$pdoResult->execute();
while ($row = $pdoResult->fetch())
echo $row['id'] . "
header("Location: ../agencies/company.php");
exit;
else
echo 'Data Not Inserted';


$pdoConnect = null;
?>









share|improve this question














I have a php file named "add_report" with a form inside it. All my inputs are running, i can input data into my database, but everytime I use the select-option. my database accepts it as null. Why is that?



This is my form "add_report.php"



<div class="wrapper">
<form action="add_report_backend.php" method="post">
<input type="hidden" name="id">
<label>Agency: </label> <input class="input1" type="text" name="agency" value="CAAP" required readonly><br>
<label>File Name: </label> <input class="input2" type="text" name="filename" placeholder="file.pdf/xlsx/xls/docx" required autofocus><br>
<label>File Type: &nbsp;</label> <select name="myselectbox">
<option name="myoption1" value="myoption1">pdf</option>
<option name="myoption2" value="myoption2">excel</option>
<option name="myoption3" value="myoption3">word</option>
</select><br>
<label>Date: </label> <input class="input4" type="Date" name="date" required><br>
<input class="submit-btn" type="submit" name="insert" value="Save">
</form>
</div>


And this another php file "add_report_backend.php"



<?php
if(isset($_POST['insert']))

try
$pdoConnect = new PDO("mysql:host=localhost;dbname=annualdb","root","");

$pdoConnect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
catch (PDOException $exc)
echo $exc->getMessage();
exit();

$id = $_POST['id'];
$Agency = $_POST['agency'];
$FName = $_POST['filename'];
$FType = $_POST['filetype'];
$Date = $_POST['date'];

$pdoQuery = "INSERT INTO `company_report`(`agency`, `filename`, `filetype`, `date`) VALUES (:Agency,:FName,:FType,:Date)";
$pdoResult = $pdoConnect->prepare($pdoQuery);
$pdoExec = $pdoResult->execute(array(":Agency"=>$Agency,":FName"=>$FName,":FType"=>$FType, ":Date"=>$Date));

if($pdoExec)


$pdoQuery = 'SELECT * FROM company_report';
$pdoResult = $pdoConnect->prepare($pdoQuery);
$pdoResult->execute();
while ($row = $pdoResult->fetch())
echo $row['id'] . "
header("Location: ../agencies/company.php");
exit;
else
echo 'Data Not Inserted';


$pdoConnect = null;
?>






php html mysql






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 7 at 9:06









Justin SaintsJustin Saints

318




318












  • Have you checked if posted datas are not null before it saves to your database?

    – Roshan
    Mar 7 at 9:10











  • The data in my table are NULL as default, should I change them as not null?

    – Justin Saints
    Mar 7 at 9:31











  • What have you tried to debug the problem? Have you checked whether the proper data is transmitted to the server, whether it reaches the server, whether the proper variables where filled?

    – Nico Haase
    Mar 7 at 9:44

















  • Have you checked if posted datas are not null before it saves to your database?

    – Roshan
    Mar 7 at 9:10











  • The data in my table are NULL as default, should I change them as not null?

    – Justin Saints
    Mar 7 at 9:31











  • What have you tried to debug the problem? Have you checked whether the proper data is transmitted to the server, whether it reaches the server, whether the proper variables where filled?

    – Nico Haase
    Mar 7 at 9:44
















Have you checked if posted datas are not null before it saves to your database?

– Roshan
Mar 7 at 9:10





Have you checked if posted datas are not null before it saves to your database?

– Roshan
Mar 7 at 9:10













The data in my table are NULL as default, should I change them as not null?

– Justin Saints
Mar 7 at 9:31





The data in my table are NULL as default, should I change them as not null?

– Justin Saints
Mar 7 at 9:31













What have you tried to debug the problem? Have you checked whether the proper data is transmitted to the server, whether it reaches the server, whether the proper variables where filled?

– Nico Haase
Mar 7 at 9:44





What have you tried to debug the problem? Have you checked whether the proper data is transmitted to the server, whether it reaches the server, whether the proper variables where filled?

– Nico Haase
Mar 7 at 9:44












2 Answers
2






active

oldest

votes


















2














The HTML name attribute and the $_POST name should be the same.



You need to change



$FType = $_POST['filetype'];


by



$FType = $_POST['myselectbox'];





share|improve this answer

























  • Thanks Pupil! It worked I also changed the value of my options to value="pdf", "excel" and "word" too.

    – Justin Saints
    Mar 7 at 9:38












  • @JustinSaints, you are welcome.

    – Pupil
    Mar 7 at 9:38


















2














Change $FType = $_POST['filetype']; to $FType = $_POST['myselectbox'];






share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55039847%2fhtml-form-select-option-to-insert-data-into-mysql-phpmyadmin-database%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    The HTML name attribute and the $_POST name should be the same.



    You need to change



    $FType = $_POST['filetype'];


    by



    $FType = $_POST['myselectbox'];





    share|improve this answer

























    • Thanks Pupil! It worked I also changed the value of my options to value="pdf", "excel" and "word" too.

      – Justin Saints
      Mar 7 at 9:38












    • @JustinSaints, you are welcome.

      – Pupil
      Mar 7 at 9:38















    2














    The HTML name attribute and the $_POST name should be the same.



    You need to change



    $FType = $_POST['filetype'];


    by



    $FType = $_POST['myselectbox'];





    share|improve this answer

























    • Thanks Pupil! It worked I also changed the value of my options to value="pdf", "excel" and "word" too.

      – Justin Saints
      Mar 7 at 9:38












    • @JustinSaints, you are welcome.

      – Pupil
      Mar 7 at 9:38













    2












    2








    2







    The HTML name attribute and the $_POST name should be the same.



    You need to change



    $FType = $_POST['filetype'];


    by



    $FType = $_POST['myselectbox'];





    share|improve this answer















    The HTML name attribute and the $_POST name should be the same.



    You need to change



    $FType = $_POST['filetype'];


    by



    $FType = $_POST['myselectbox'];






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Mar 7 at 9:36

























    answered Mar 7 at 9:31









    PupilPupil

    19.8k43156




    19.8k43156












    • Thanks Pupil! It worked I also changed the value of my options to value="pdf", "excel" and "word" too.

      – Justin Saints
      Mar 7 at 9:38












    • @JustinSaints, you are welcome.

      – Pupil
      Mar 7 at 9:38

















    • Thanks Pupil! It worked I also changed the value of my options to value="pdf", "excel" and "word" too.

      – Justin Saints
      Mar 7 at 9:38












    • @JustinSaints, you are welcome.

      – Pupil
      Mar 7 at 9:38
















    Thanks Pupil! It worked I also changed the value of my options to value="pdf", "excel" and "word" too.

    – Justin Saints
    Mar 7 at 9:38






    Thanks Pupil! It worked I also changed the value of my options to value="pdf", "excel" and "word" too.

    – Justin Saints
    Mar 7 at 9:38














    @JustinSaints, you are welcome.

    – Pupil
    Mar 7 at 9:38





    @JustinSaints, you are welcome.

    – Pupil
    Mar 7 at 9:38













    2














    Change $FType = $_POST['filetype']; to $FType = $_POST['myselectbox'];






    share|improve this answer



























      2














      Change $FType = $_POST['filetype']; to $FType = $_POST['myselectbox'];






      share|improve this answer

























        2












        2








        2







        Change $FType = $_POST['filetype']; to $FType = $_POST['myselectbox'];






        share|improve this answer













        Change $FType = $_POST['filetype']; to $FType = $_POST['myselectbox'];







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 7 at 9:31









        XunXun

        905




        905



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55039847%2fhtml-form-select-option-to-insert-data-into-mysql-phpmyadmin-database%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            1928 у кіно

            Захаров Федір Захарович

            Ель Греко