I read some related questions regarding my problem, but I still cannot figure it out. So I decided to ask now.
I would like to know if there is something wrong with my code. In principle, the data in the input blocks should go to the database (MYSQL), but every time I click the "Submit" button, nothing happens.
code: insert_product.php <- main page
<!DOCTYPE html> <?php include("includes/db.php"); ?> <html> <head> </head> <script src="//cdn.tinymce.com/4/tinymce.min.js"></script> <script>tinymce.init({ selector:'textarea' });</script> <body bgcolor="#aad6bb"> <form action="insert_product.php" method="post" enctype="multipart/form-data"> <table align="center" width="600" border='1' bgcolor='#d6aac5'> <tr align="center"> <td colspan='8'><h2>Inser New Post Here</h2></td> </tr> <tr > <td align="right"> <b>Product Name:<b></td> <td><input type='text'name="product_name" size='50'/></td> </tr> <tr> <td align="right"><b> Product Description</b></td> <td><textarea name="product_desc" cols='20' rows='10'></textarea></td> </tr> <tr> <td align="right"> <b>Product Price:</b></td> <td><input type='text'name="product_price"/></td> </tr> <tr> <td align="right"><b> Product Quantity:</b></td> <td><input type='text'name="product_quantity"/></td> </tr> <tr> <td align="right"> <b>Product Category:</b></td> <td><select name="product_cat"> <option>Select Category</option> <?php $get_cats = "Select * from categories"; $run_cat = mysqli_query($con, $get_cats); while ($row_cats=mysqli_fetch_array($run_cat)){ $cat_id = $row_cats['cat_id']; $cat_title = $row_cats['cat_title']; echo"<option value='$cat_id'>$cat_title</option>"; } ?> </select> </td> </tr> <tr> <td align="right"> <b>Product Image:</b></td> <td><input type='file' name="product_img"/></td> </tr> <tr> <td align="right"> <b>Product Keywords:</b></td> <td><input type='text' size="40" name="product_kw"/></td> </tr> <tr align='center'> <td colspan='8'><input type='submit'name="insert_post" value="Insert Product"/></td> </tr> </table> </form> </body> </html> <?php if(isset($_POST['insert_post'])){
db.php <- for connection
<?php $con = mysqli_connect("localhost","root","","ecommerce"); ?>
The table from the database ( ecommerce name) is an item in my table item : ItemID Primary and AI ItemName ItemDesc ItemPrice ItemQty ItemCat ItemImg keywords
NOTE. I know that my code is vulnerable to SQL Injection attacks. But I'm still new and focus on connecting with HTML and PHP products :)
source share