简体   繁体   English

单击提交按钮时如何显示结果? (如查看历史记录)

[英]How to show the result when I click the submit button? (Like View history)

Here's the concept. 这是概念。 The users will input the data from the text bar.. And when click the submit button, the data will be saved to the "VIEW HISTORY" menu bar. 用户将从文本栏输入数据。单击“提交”按钮时,数据将保存到“查看历史记录”菜单栏中。 View history is where the data's inputted from the home.php are being made. 查看历史记录是从home.php输入数据的地方。

Eg: 例如:

Home.php

(data1)
Enter Name: (I type..)Black Cat
Age: (I type..)21
Job: (I type..)Spy

(data2)
Enter Name: (I type..)Black Dog
Age: (I type..)24
Job: (I type..)Cook

Submit Button (I click it) and it says the data is submitted to my database. 提交按钮(我单击它),它说数据已提交到我的数据库。 Then when I click the "View History Menu Bar".. The ff will be shown: 然后,当我单击“查看历史记录菜单栏”时。ff将显示:

DATA1
DATA2
<Click next to view next page.. etc>

When I click data1, the whole name, age and job from data1 will appear. 当我单击data1时,将显示data1的全名,年龄和工作。 And so is from data2.. and so on.. :) 从data2 ..如此等等.. :)

That's my only problem.. I can't show those data :( Please help! I have some codes in here.. But I dunno how to fix it :( I hope you can give some samples so I can imitate the moves, or better if we help on fixing this. :( THANKS Y'ALL! 那是我唯一的问题。.我无法显示这些数据:(请帮助!我在这里有一些代码。.但是我不知道如何解决它:(我希望您可以提供一些示例,以便我可以模仿动作,或者更好,如果我们能解决这个问题。:(谢谢!

<?php
$cfccon = include("E:/xampp/conn1/cfmscsd.php");
//This is about the localhost, username, password stuff

$query="SELECT * FROM contents";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

$i=0;
while ($i < $num) {

$B1=mysql_result($result,$i,"B1");
$B2=mysql_result($result,$i,"B2");
$B3=mysql_result($result,$i,"B3");
$B4=mysql_result($result,$i,"B4");
$B5=mysql_result($result,$i,"B5");
$B6=mysql_result($result,$i,"B6");
$B7=mysql_result($result,$i,"B7");
$B8=mysql_result($result,$i,"B8");
$B9=mysql_result($result,$i,"B9");
$B10=mysql_result($result,$i,"B10");

$i++;
}
?>


<html>
<tr>
                <td bgcolor="#bfb9a7"><span class="style77">CCC</span></td>
                <td bgcolor="#CCCCCC"><div  align="center" class="style66"><input name="B1" type="text" size="18" id="B1" value="<?php echo $B1;?>" disabled="disabled"/></div></td>
                <td bgcolor="#CCCCCC"><div  align="center" class="style66"><input name="B2" type="text" size="18" id="B2" value="<?php echo $B2;?>" disabled="disabled"/></div></td>
                <td bgcolor="#CCCCCC"><div  align="center" class="style66"><input name="B3" type="text" size="18" id="B3" value="<?php echo $B3;?>" disabled="disabled"/></div></td>
                <td bgcolor="#CCCCCC"><center><div class="style66"><input type="button" onclick="tbsp1()" value="<?php echo $tbsp1;?>add" disabled="disabled"/></center></td>
                <td bgcolor="#FEEDD8"><div  align="center" class="style66"><input name="B4" type="text" size="18" id="B4" value="<?php echo $B4;?>" disabled="disabled"/></div></td>
              </tr>
              <tr>
                <td><span class="style77">SCC</span></td>
                <td><div align="center" class="style66"><input name="B5" type="text" size="18" id="B5" value="<?php echo $B5;?>" disabled="disabled"/></div></td>
                <td><div align="center" class="style66"><input name="B6" type="text" size="18" id="B6" value="<?php echo $B6;?>" disabled="disabled"/></div></td>
                <td><div align="center" class="style66"><input name="B7" type="text" size="18" id="B7" value="<?php echo $B7;?>" disabled="disabled"/></div></td>
                <td><center><input type="button" onclick="tbsp2()" value="<?php echo $tbsp2;?>add" disabled="disabled"/></center></td>
                <td bgcolor="#FEEDD8"><div align="center"><input name="B8" type="text" size="18" id="B8" value="<?php echo $B8;?>" disabled="disabled"/></div></td>
              </tr>
              <tr>
                <td bgcolor="#bfb9a7"><span class="style77">NCC</span></td>
                <td bgcolor="#CCCCCC"><div align="center" class="style66"><input name="B9" type="text" size="18" id="B9" value="<?php echo $B9;?>" disabled="disabled"/></div></td>
                <td bgcolor="#CCCCCC"><div align="center" class="style66"><input name="B10" type="text" size="18" id="B10" value="<?php echo $B10;?>" disabled="disabled"/></div></td>
             </tr>
</html>

First of all, I recommend that you rename your table columns, B1, B2, B3 etc are very very bad names, instead use something descriptive like name, age, email, etc. That will make your code a lot easier to read and debug. 首先,我建议您重命名表列,B1,B2,B3等都是非常糟糕的名称,而应使用诸如名称,年龄,电子邮件等描述性名称。这将使您的代码更易于阅读和调试。

To achieve what you're asking for, do something like this: 要实现您的要求,请执行以下操作:

1) When the user clicks the submit button, do a form post to a script on your site, eg 1)当用户单击“提交”按钮时,将表单发布到您网站上的脚本中,例如

<form method=post action=home.php>
Enter data: <input type=text name=data>
<input type=submit value=Submit />
</form>

2) When the user clicks the submit button, you could get the data he posted in $_POST , eg $_POST['data'] . 2)当用户单击提交按钮时,您可以获取他在$_POST发布的数据,例如$_POST['data'] Save this to a mysql database. 将此保存到mysql数据库。 You should give the user a unique user ID. 您应该给用户一个唯一的用户ID。 Each row in your table should have these fields: 表格中的每一行都应具有以下字段:

dataId (int,primary, auto_increment)
userID (int)
name (varchar 255)
age  (int)
etc...

Then you should have a different table for users, called a user table. 然后,应该为用户提供另一个表,称为user表。 Each user who visits the website should have a unique userId. 每个访问该网站的用户都应具有唯一的userId。 You can store this userId in $_SESSION , I recommend you read about session handling. 您可以将此userId存储在$_SESSION ,建议您阅读有关会话处理的信息。

Then whenever the user submits his form, you add a new row to your data table with his info, and the userId field with the given user's id. 然后,每当用户提交表单时,您就会在其数据表中添加一个新行,其中包含他的信息,以及一个具有给定用户ID的userId字段。

3) When the user clicks 'next' to see the data, you would do something like this: 3)当用户单击“下一步”以查看数据时,您将执行以下操作:

$userId = $_SESSION['userId'];
$sql = "SELECT * FROM data WHERE userId='$userId'";
$result = mysql_query($sql) or die(mysql_error());
$history = array();
while ($row = mysql_fetch_assoc($result))
{
  $history[] = $row;     
}

4) Then simply loop through the $rows using foreach and display the history. 4)然后只需使用foreach $rows并显示历史记录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么当我单击提交按钮时 isset($_POST['like']) 不起作用? - Why is isset($_POST['like']) not working when I click on submit button? 提交按钮不会一键显示结果,第二次单击会显示结果 - submit button will not show the result by one click it will show it by second click 我如何在一个页面中使用2个表单,以及在单击第一个提交按钮时如何以第二个表单显示某些内容 - How i can use 2 forms in one page and when click in first submit button show something in second form 单击按钮时,表单提交无效 - form submit is not working when i click button 我想用按钮做一些功能。 我想要当我单击按钮时将显示结果。 结果来自数据库 - i want to do some functions with button. i want when i click on button it will be show result. result comes from database 当用户点击喜欢按钮然后只显示喜欢按钮 - When user click on like butten then show only like button 如何在提交按钮单击时增加值 - How to increment a value when submit button click 用户单击注册号时如何显示所有维护历史记录 - How to show all the maintainance history when user click on the registration number 为什么单击提交按钮时丢失文件名值 - Why I lost the filename value when I click the submit button 为什么我点击提交按钮时什么也没有得到? - Why am I not gettiing anything when I click the submit button?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM