PHP表单,下拉列表&;mysql表

PHP表单,下拉列表&;mysql表,php,mysql,database,Php,Mysql,Database,我有一个表格,可以在我的数据库中插入书籍的详细信息。我的数据库中有4个表1)ssc_eng 2)ssc_hindi 3)ssc_urdu 4)ssc_marathi。在我的insert_book表单中,他们是一个下拉列表,上面有这些表格。如果管理员从下拉列表中选择其中一个表,则管理员在insert_book表单中插入的所有数据都应插入到选定的下拉项中,即我的数据库中的表。所以,我打成平局,但不明白其中的逻辑。示例:如果管理员在下拉列表中选择“ssc_eng”,则表单中的所有数据都必须插入我的数据

我有一个表格,可以在我的数据库中插入书籍的详细信息。我的数据库中有4个表1)ssc_eng 2)ssc_hindi 3)ssc_urdu 4)ssc_marathi。在我的insert_book表单中,他们是一个下拉列表,上面有这些表格。如果管理员从下拉列表中选择其中一个表,则管理员在insert_book表单中插入的所有数据都应插入到选定的下拉项中,即我的数据库中的表。所以,我打成平局,但不明白其中的逻辑。示例:如果管理员在下拉列表中选择“ssc_eng”,则表单中的所有数据都必须插入我的数据库中的“ssc_eng”表中

简要问题:

Use drop down list to insert form data to the selected database of the drop down list



<?php 
  include("includes/connect.php"); 

     if(!isset($_SESSION['user_email']))
    {
     echo "<script>window.open('login.php?not_admin=You are not an     Admin!','_self')</script>";
    }
    else
    {

     ?>

<html>
<head>

<title> Product Insert Page</title>
</head>

<body bgcolor="#414141">

<div class="container-fluid">
<div class="row">
<div class="col-lg-4"></div>
<div class="col-lg-4">
 <form method="post" action="insert_product.php" enctype="multipart/form-data">

 <table align="center" width="700" height="800" border="2" bgcolor="#5E0000">

  <tr align="center">
  <td colspan="7" style="padding-top: 10px; font-size:20px; font-family:'Adobe Garamond Pro', 'Times New Roman'; color:#EEEEEE"><h2>Insert Books</h2></td>
  </tr>

  <tr>
  <td align="right" style="font-family:'Adobe Garamond Pro', 'Times New Roman'; font-size:20px; padding-right: 16px; background:#B6B6B6;"><b>Book Title:</b></td>
  <td style="padding-left: 16px; background:#B6B6B6;"><input type="text" name="b_title" size="30" required/></td>
  </tr>

  <tr>
  <td align="right" style="font-family:'Adobe Garamond Pro', 'Times New Roman'; font-size:20px; padding-right: 16px; background:#B6B6B6;"><b>Language:</b></td>
  <td style="padding-left: 16px; background: #B6B6B6;">
  <select name="b_language" required/>
  <option>Select Language</option>
  <?php
   $cat_query= "select * from categories";
   $query_runs= mysqli_query($con, $cat_query);
   while($row_cat=mysqli_fetch_array($query_runs))
 {
   $cat_id=$row_cat['cat_id'];
   $cat_title=$row_cat['cat_title'];
   echo "<option value='$cat_id'>$cat_title</option>";
}
?>
  </select>
  </td>
  </tr>

  <tr>
  <td align="right" style="font-family:'Adobe Garamond Pro', 'Times New Roman'; font-size:20px; padding-right: 16px; background:#B6B6B6;"><b>Standard(Class):</b></td>
  <td style="padding-left: 16px; background:#B6B6B6;">
  <select name="b_class" required/>
  <option> Select Standard </option>
  <?php
  $brd_query="select  * from brands";
  $run_query=mysqli_query($con, $brd_query);
  while($row_brd=mysqli_fetch_array($run_query))
 {
  $brand_id=$row_brd['brand_id'];
  $brand_title=$row_brd['brand_title'];
  echo "<option value='$brand_id'>$brand_title</option>";
 }
 ?>
 </select>
  </td>
  </tr>

  <tr>
  <td align="right" style="font-family:'Adobe Garamond Pro', 'Times New Roman'; font-size:20px; padding-right: 16px; background:#B6B6B6;"><b>Book Image:</b></td>
  <td style="padding-left: 16px; background:#B6B6B6;"><input type="file" name="b_image" size="30" required/></td>
  </tr>

  <tr>
  <td align="right" style="font-family:'Adobe Garamond Pro', 'Times New Roman'; font-size:20px; padding-right: 16px; background:#B6B6B6;"><b>Author Name:</b></td>
  <td style="padding-left: 16px; background:#B6B6B6;"><input type="text" name="b_author" size="30" required/></td>
  </tr>

  <tr>
  <td align="right" style="font-family:'Adobe Garamond Pro', 'Times New Roman'; font-size:20px; padding-right: 16px; background:#B6B6B6;"><b>Publish Year:</b></td>
  <td style="padding-left: 16px; background:#B6B6B6;"><input type="text" name="b_publish" size="30" required/></td>
  </tr>


  <tr>
  <td align="right" style="font-family:'Adobe Garamond Pro', 'Times New Roman'; font-size:20px; padding-right: 16px; background:#B6B6B6;"><b>Book Price:</b></td>
  <td style="padding-left: 16px; background:#B6B6B6;"><input type="text" name="b_price" size="30" required/></td>
  </tr>

  <tr>
  <td align="right" style="font-family:'Adobe Garamond Pro', 'Times New Roman'; font-size:20px; padding-right: 16px; background:#B6B6B6;"><b>Book Description:</b></td>
  <td style="padding-left: 16px; background:#B6B6B6;">
  <textarea name="b_desc" cols="20" rows="10" required></textarea>
  </td>
  </tr>

  <tr>
  <td align="right" style="font-family:'Adobe Garamond Pro', 'Times New Roman'; font-size:20px; padding-right: 16px; background:#B6B6B6;"><b>No. of Pages:</b></td>
  <td style="padding-left: 16px; background:#B6B6B6;"><input type="text" name="b_pages" size="30" required/></td>
  </tr>

  <tr>
  <td align="right" style="font-family:'Adobe Garamond Pro', 'Times New Roman'; font-size:20px; padding-right: 16px; background:#B6B6B6;"><b>Stock(In/Out):</b></td>
  <td style="padding-left: 16px; background:#B6B6B6;">
  <select name="b_stock" required/>
  <option> Stock In </option>
  <option> Stock Out </option>
  </tr>

  <tr>
  <td align="right" style="font-family:'Adobe Garamond Pro', 'Times New Roman'; font-size:20px; padding-right: 16px; background:#B6B6B6;"><b>Delivery within(in days)</b></td>
  <td style="padding-left: 16px; background:#B6B6B6;">
  <select name="b_delivery" required/>
  <option> 6 </option>
  <option> 7 </option>
  <option> 8 </option>
  <option> 9 </option>
  <option> 10 </option>
  </tr>

  <tr>
  <td align="right" style="font-family:'Adobe Garamond Pro', 'Times New Roman'; font-size:20px; padding-right: 16px; background:#B6B6B6;"><b>Delivery Charges:</b></td>
  <td style="padding-left: 16px; background:#B6B6B6;"><input type="text" name="b_deliverychar" size="30" required/></td>
  </tr>

  <tr>
  <td align="right" style="font-family:'Adobe Garamond Pro', 'Times New Roman'; font-size:20px; padding-right: 16px; background:#B6B6B6;"><b>Book Keywords:</b></td>
  <td style="padding-left: 16px; background:#B6B6B6;"><input type="text" name="b_keywords" size="30" required/></td>
  </tr>

  <tr align="center">
  <td colspan="7"><input type="submit" name="insert_post" value="Insert Book Now"  class="btn btn-primary"/></td>
  </tr>

</table>

</form>
</div>
<div class="col-lg-4"></div>
</div>
</div>
</body>
</html>



<?php

if(isset($_POST['insert_post']))
{
// getting the text fields from form
 $b_title = preg_replace('#[^a-z]#', '', $_POST['b_title']);
 $b_language = preg_replace('#[^a-z]#', '', $_POST['b_language']);
 $b_class = preg_replace('#[^a-z]#', '', $_POST['b_class']);
 $b_author = preg_replace('#[^a-z]#', '', $_POST['b_author']);
 $b_publish = preg_replace('#[^a-z0-9]#', '', $_POST['b_publish']);
 $b_price = preg_replace('#[^0-9]#', '', $_POST['b_price']);
 $b_desc = preg_replace('#[^a-z]#', '', $_POST['b_desc']);
 $b_pages = preg_replace('#[^0-9]#', '', $_POST['b_pages']);;
 $b_stock = preg_replace('#[^a-z]#', '', $_POST['b_stock']);
 $b_delivery = preg_replace('#[^a-z0-9]#', '', $_POST['b_delivery']);
 $b_deliverychar = preg_replace('#[^0-9]#', '', $_POST['b_deliverychar']);
 $b_keywords = preg_replace('#[^a-z]#', '', $_POST['b_keywords']);

 //getting image data from the form
 $b_image = $_FILES['b_image']['name'];
 $b_image_tmp = $_FILES['b_image']['tmp_name'];

 move_uploaded_file($b_image_tmp,"books_images/$b_image");

 $insert_books=  "insert into products (product_cat, product_brand, product_title, product_price, product_desc, product_image, product_keywords) values ('$product_cat','$product_brand','$product_title','$product_price','$product_desc','$product_image','$product_keywords')";

 $insert_pro = mysqli_query($con, $insert_books) or die(mysqli_error($con));

 if($insert_pro)
 {
  echo "<script>alert('Book is sucessfully added!')</script>"; 
  echo "<script>window.open('index.php?insert_product','_self')</script>"; 
 }

}

?>


<?php } ?>
使用下拉列表将表单数据插入下拉列表的选定数据库

您告诉它插入到products表中,因此如果您希望它进入ssc_eng表,那么您必须检查存在哪个select选项($b_类),并将其替换为“products”

下拉列表是动态列表&如果我在数据库中添加表,则下拉列表中都有新表的名称。我有一个单独的php程序用于这个下拉列表的分类。phpI没有看到这个问题。如果您的下拉列表基于现有的表,那么当您执行插入并替换表名时,它将起作用,因为该表存在。IE:“插入到$b_类(…”。你能为我提供这个问题的插入查询吗?我是mysql和php的新手,对这些语言不太了解。你已经有了这个查询,你只需要更改你插入的表的名称,就像我上面指出的那样。好的,所以我必须从插入查询中删除“产品”并添加“$b_类”。我会试试这个,然后再给你回复。谢谢。我有更多的疑问,任何人都可以解决。请注意,这是紧急情况