douchuang4402 2017-01-23 13:01
浏览 31

插入值是动态的

<?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>

I have this code, it should add when I click the add button, but how am I suppose to write the "insert" query when I don't know the field names that I want it to insert into the values, could anyone help me with this? And the errors I get when I click add are:

Notice: Undefined variable: columns 
Notice: Undefined variable: columns 
Warning: implode(): Invalid arguments passed 

And nothing gets added.

  • 写回答

1条回答 默认 最新

  • doubingjiu3199 2017-01-23 13:24
    关注

    Try with this code

    <?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>
    

    Some important change please do at your end like field_name fetch etc.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起