插入值是动态的

时间:2017-01-23 13:01:21

标签: php

MyMethod

我有这个代码,它应该在我点击添加按钮时添加,但我怎么想写"插入"查询当我不知道我希望它插入值的字段名称时,任何人都可以帮我这个吗? 我点击添加时得到的错误是:

<?php
require "connection.php";
error_reporting(E_ALL);
ini_set('display_errors',1);
$username = "jasmine";
?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <link href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">
<link href = "http://fonts.googleapis.com/css?family=Roboto:400">
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<style>
.modal-dialog{
    width:100%;
    overflow: scroll;

}

</style>


</head>
<body>


  <h2>Modal Example</h2>
  <!-- Trigger the modal with a button -->
  <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>

  <!-- Modal -->
  <div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog">

      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">ADD</h4>
        </div>
        <div class="modal-body">
          <p>


<form action="" method="post">
<table>
<thead>
   <?php 
    $query = mysqli_query($conn,"SHOW columns FROM `rsvp`");
    // Loop over all result rows
    while($row = mysqli_fetch_array($query))
    {
        echo '<th>';
        echo $row["Field"];
        echo '</th>';
    }
 ?>
 </thead>
 <tbody>
 <?php 
    $query4="SELECT * from `rsvp` WHERE `Gathered By` = '$username'";

    $result4=  mysqli_query($conn, $query4);
    while($row4 = mysqli_fetch_assoc($result4)){
        echo '<tr>';
        foreach($row4 as $values3){
        echo '<td>';
        echo '<input type="text" name="' .$row['Field'] .'">';
        echo '</td>';
        }
        ?>
        <td>
        <input type="submit" name="add" value="Add">
        </td>
        <?php
        echo '</tr>';}
 ?>
 </tbody>
</table>
</form>

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

$result2= mysqli_query($conn,"SELECT * FROM users WHERE username = '$username'");
$row2 = mysqli_fetch_row($result2);

$row["Field"] = $columns;
mysqli_query($conn,'INSERT INTO table (text, category) VALUES '.implode(',', $columns));




//// WHAT DO I DO HERE?

}
?>  

          </p>
        </div>
      </div>

    </div>
  </div>



</body>
</html>

没有任何补充。

1 个答案:

答案 0 :(得分:0)

尝试使用此代码

<?php
if(isset($_POST['add'])){
      // insert query after upload data
}
?>


<table>
<thead>
   <?php 
    $query = mysqli_query($conn,"SHOW columns FROM `call`");
    // Loop over all result rows
    while($row = mysqli_fetch_array($query))
    {
        echo '<th>';
        echo $row["Field"];
        echo '</th>';
    }
 ?>
 </thead>
 <tbody>
 <?php 
    $query4="SELECT * from `call` WHERE `Generated By` = '$username'";

    $result4=  mysqli_query($conn, $query4);
    while($row4 = mysqli_fetch_assoc($result4)){
        echo '    <form action="" method="post"><tr>';
        foreach($row4 as $values3){
        echo '<td>';
        echo '<input type="text" name="field_name">';
        echo '</td>';
        }
        ?>
        <td>
        <input type="submit" name="add" value="Add">
        </td>
        <?php
        echo '</tr></form>';
 ?>
 </tbody>
</table>

一些重要的更改请在您的最后完成,例如field_name fetch等。