I hope this is helpful now
当您向我询问数据库结构时,我创建了一个

我感谢您的帮助!提前致谢!

到目前为止,我所拥有的是以下html代码:



<html>
    <head>
      <title>Test Software</title>
    </head>
    <body>
      <label>
         Datum:<br/>
        <input name="date" type="date" placeholder="Datum" style="height: 50px; width: 100px;"/>
      </label>
      <label>
        <p> <form action="#"> </p>
		    <label>Station:<br>
			        <select name="top5" style="height: 50px; width: 100px;"/>
				    <option>Choice 1 </option>
			    	<option>Choice 2 </option>
				    <option>Choice 3 </option>
				    <option>Choice 4 </option>
				    <option>Choice 5 </option>
			    </select>

		    </label>
	    </form>
   </main>
      <br/><br/><br/>
      <input type="submit" name="button[Button1]" value="Button 1" style="height: 50px; width: 100px;"/>
      <input type="submit" name="button[Button2]" value="Button 2" style="height: 50px; width: 100px;"/>
      <input type="submit" name="button[Button3]" value="Button 3" style="height: 50px; width: 100px;"/>
      <input type="submit" name="button[Button4]" value="Button 4" style="height: 50px; width: 100px;"/>
      <input type="submit" name="button[Button5]" value="Button 5" style="height: 50px; width: 100px;"/>

     </form>
  </body>
</html>





我如何才能将数据Tom发送给php文件,然后将其存储在数据库中?

DB
CREATE TABLE button_counter (
id INTEGER PRIMARY KEY,
name VARCHAR(64) NOT NULL,
datum DATE NOT NULL,
savedate TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
Button BIT NOT NULL DEFAULT 0,
Button2 BIT NOT NULL DEFAULT 0,
Button3 BIT NOT NULL DEFAULT 0,
Button4 BIT NOT NULL DEFAULT 0
Button5 BIT NOT NULL DEFAULT 0
);

最佳答案

我已将您的代码更改为以下代码并进行检查。它的工作。在您的问题中,我可以看到该日期字段填充有当前时间戳。但是有一个输入字段可以为用户选择日期。所以我修改了您的代码,假设该用户将记录日期。请查看下面的代码,如果您有所需,请标记为答案。谢谢

index.php

<html>

<head>
    <title>Test Software</title>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <script>
        var counter1 = 0;
        $(document).on('click', '#button01', function(e) {
            e.preventDefault();
            counter1++;
            $("#button01").text('You have clicked' + counter1);
            $("#hidde_val_of_button01").val(counter1);
        });
        var counter2 = 0;
        $(document).on('click', '#button02', function(e) {
            e.preventDefault();
            counter2++;
            $("#button02").text('You have clicked' + counter2);
            $("#hidde_val_of_button02").val(counter2);
        });
        var counter3 = 0;
        $(document).on('click', '#button03', function(e) {
            e.preventDefault();
            counter3++;
            $("#button03").text('You have clicked' + counter3);
            $("#hidde_val_of_button03").val(counter3);
        });
        var counter4 = 0;
        $(document).on('click', '#button04', function(e) {
            e.preventDefault();
            counter4++;
            $("#button04").text('You have clicked' + counter4);
            $("#hidde_val_of_button04").val(counter4);
        });
        var counter5 = 0;
        $(document).on('click', '#button05', function(e) {
            e.preventDefault();
            counter5++;
            $("#button05").text('You have clicked' + counter5);
            $("#hidde_val_of_button05").val(counter5);
        });
    </script>
</head>

<body>
    <form action="action.php" method="post">
        <label>
            Datum:
            <br/>
            <input name="date" type="date" placeholder="Datum" style="height: 50px; width: 100px;" />
        </label>
        <label>
            <p> </p>
            <label>Station:
                <br>
                <select name="top5" style="height: 50px; width: 100px;" />
                <option>Choice 1 </option>
                <option>Choice 2 </option>
                <option>Choice 3 </option>
                <option>Choice 4 </option>
                <option>Choice 5 </option>
                </select>

            </label>

            </main>
            <br/>
            <br/>
            <br/>
            <button id="button01" style="height: 50px; width: 100px;">Button 1</button>
            <!--Using hiddne text input typeto pass the data!-->
            <input type="text" hidden value="0" id="hidde_val_of_button01" name="button01" />

            <button id="button02" style="height: 50px; width: 100px;">Button 2</button>
            <!--Using hiddne text input typeto pass the data!-->
            <input type="text" hidden value="0" id="hidde_val_of_button02" name="button02" />

            <button id="button03" style="height: 50px; width: 100px;">Button 3</button>
            <!--Using hiddne text input typeto pass the data!-->
            <input type="text" hidden value="" id="hidde_val_of_button03" name="button03" />

            <button id="button04" style="height: 50px; width: 100px;">Button 4</button>
            <!--Using hiddne text input typeto pass the data!-->
            <input type="text" hidden value="" id="hidde_val_of_button04" name="button04" />

            <button id="button05" style="height: 50px; width: 100px;">Button 5</button>
            <!--Using hiddne text input typeto pass the data!-->
            <input type="text" hidden value="" id="hidde_val_of_button05" name="button05" />
            <br/>
            <br/>
            <button type="submit" style="height: 50px; width: 100px;background-color:green;">Submit</button>
              <br/>
                 <textarea name="comment" >Enter your comment here...</textarea>
    </form>
</body>

</html>


action.php

<?php

//FETCH DATA
$date = $_POST['date'];
$option = $_POST['top5'];
$btn01 = $_POST['button01'];
$btn02 = $_POST['button02'];
$btn03 = $_POST['button03'];
$btn04 = $_POST['button04'];
$btn05 = $_POST['button05'];
$comment = $_POST['comment'];

// echo $date."<br/>";
// echo $option."<br/>" ;
// echo $btn01."<br/>" ;
// echo $btn02."<br/>" ;
// echo $btn03."<br/>" ;
// echo $btn04."<br/>" ;
// echo  $btn05."<br/>";

$sql = "INSERT INTO your_table_name(Date,Choice,Button_01,Button_02,Button_03,Button_04,Button_05,comment) VALUES ($date,$option,$btn01,$btn02,$btn03,$btn04,$btn05,$comment) ";

?>

10-06 13:43
查看更多