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
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: </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
add a comment |
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: </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
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
add a comment |
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: </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
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: </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
php html mysql
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
The HTML name
attribute and the $_POST
name should be the same.
You need to change
$FType = $_POST['filetype'];
by
$FType = $_POST['myselectbox'];
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
add a comment |
Change $FType = $_POST['filetype'];
to $FType = $_POST['myselectbox'];
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
The HTML name
attribute and the $_POST
name should be the same.
You need to change
$FType = $_POST['filetype'];
by
$FType = $_POST['myselectbox'];
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
add a comment |
The HTML name
attribute and the $_POST
name should be the same.
You need to change
$FType = $_POST['filetype'];
by
$FType = $_POST['myselectbox'];
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
add a comment |
The HTML name
attribute and the $_POST
name should be the same.
You need to change
$FType = $_POST['filetype'];
by
$FType = $_POST['myselectbox'];
The HTML name
attribute and the $_POST
name should be the same.
You need to change
$FType = $_POST['filetype'];
by
$FType = $_POST['myselectbox'];
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
add a comment |
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
add a comment |
Change $FType = $_POST['filetype'];
to $FType = $_POST['myselectbox'];
add a comment |
Change $FType = $_POST['filetype'];
to $FType = $_POST['myselectbox'];
add a comment |
Change $FType = $_POST['filetype'];
to $FType = $_POST['myselectbox'];
Change $FType = $_POST['filetype'];
to $FType = $_POST['myselectbox'];
answered Mar 7 at 9:31
XunXun
905
905
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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