I think i have bugs here, my database didn't receive data from this modal when I inputted data. And also, when I clicked the submit button in modal, it is not closing.
Asked
Active
Viewed 43 times
-2
-
2As per the [How To Ask](https://stackoverflow.com/help/how-to-ask) guide, which you are encouraged to read before using the site, please don't post images of code, data or error messages. This information is text-based. Pasting it as graphics is very impractical as it can't be copied, searched, re-used in answers etc. It makes it difficult for those who might want to help you. Please [edit] your question to include _relevant_ code as text and use the [formatting tools](https://stackoverflow.com/help/formatting) to present it nicely, so that it is usable for those who want to help you. Thanks – ADyson Oct 24 '22 at 23:52
-
1See also 1) [Why not upload images of code/data/errors when asking a question?](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question) and 2) how to create a [mre] of your issue. As you're new, you would also benefit from taking the [tour]. Thanks. – ADyson Oct 24 '22 at 23:52
-
`my database didn't receive data`...ok, but that's just a symptom right at the end of the process you want to accomplish. Have you done any debugging? Test your code line by line, to see where its behaviour starts to deviate from what you expected. Make sure you check your JavaScript and PHP error logs for errors and warnings, too. We don't have a clear or precise problem description, and we cannot execute the code, so unless there are some blatant errors in it which we can read, we're relying on you to tell us clearly what happens when you try to run it. – ADyson Oct 24 '22 at 23:54
-
And after I said that....basic error: your submit button is outside your ` – ADyson Oct 24 '22 at 23:58
-
**Warning:** Your code is vulnerable to SQL Injection attacks. You should use parameterised queries and prepared statements to help prevent attackers from compromising your database by using malicious input values. http://bobby-tables.com gives an explanation of the risks, as well as some examples of how to write your queries safely using PHP / mysqli. **Never** insert unsanitised data directly into your SQL. The way your code is written now, someone could easily steal, incorrectly change, or even delete your data. – ADyson Oct 24 '22 at 23:58
-
https://phpdelusions.net/mysqli also contains good examples of writing safe SQL using mysqli. See also the [mysqli documentation](https://www.php.net/manual/en/mysqli.quickstart.prepared-statements.php) and this: [How can I prevent SQL injection in PHP?](https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) . Parameterising your queries will also greatly reduce the risk of accidental syntax errors as a result of un-escaped or incorrectly quoted input values. If you learnt your current technique from a tutorial or book, please don't use it again. – ADyson Oct 24 '22 at 23:59
-
Never configure your web app to login to the database as `root`. Root can do whatever it likes, so on top of the SQL injection vulnerabilities this just leaves your database an open book for hackers. Instead create a separate user account specifically for this application which has only the permissions it actually _needs_ in order to work properly. Don't even use the root account as a shortcut during development or testing, because you need to test your account permissions as well - otherwise when you go live you might have unexpected errors relating to the user account setup. – ADyson Oct 24 '22 at 23:59
-
Add `mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);` before your `mysqli_connect()` (or `new mysqli()`) command, and this will ensure that errors with your SQL queries are reported correctly to PHP automatically, and you won't have to guess what went wrong when a SQL statement fails. – ADyson Oct 25 '22 at 00:00
-
do not post screenshot of code – pmatatias Oct 25 '22 at 06:34
1 Answers
1
After analyzing your code
- Submit button must be enclosed between Form Tag
<form><input type="submit" value="Submit"></form>
- But in your code
submit button is outside of the <form> tag
. If you correct it then form must be submitted to following action page. - Bootstrap modal must be like.
<!-- BOOTSTRAP FORM MODAL -->
<div class="modal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<!-- Title -->
</div>
<form action="#">
<!--FORM TAG OPEN -->
<div class="modal-body">
<!-- INPUT FIELDS-->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Save changes</button>
</div>
<!--FORM TAG CLOSE -->
</form>
</div>
</div>
</div>
- For good practice use prepare statement to store or retrieve data From database.

Naveen
- 246
- 1
- 8