如何使用表单插入或更新 [英] How to use a form to insert OR update

查看:56
本文介绍了如何使用表单插入或更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我接近编程选择表单的结束,我很快就会需要创建插入和更新表单。我对如何最好地处理这个问题有疑问。


我想用一个表单来进行插入和更新。现在,就数据库中的数据而言,如果我已经在表中有一些数据并且只需要更新一个字段,那么这是如何工作的?我应该使用if吗?在表格中的每个字段上都有条件和isset,或者只是更新整个表格?


换句话说,如果用户想要更新记录并且只更改表单中的1个字段,我会*认为*只应更新1个字段而不是表格中的所有字段。我对此是否正确?


我也很好奇如何处理新数据的INSERT。让我们说上面的相同形式有3个字段有* NO *数据,用户想要更新表单中的1或2个字段,并看到其中3个字段为空,然后决定填写它。那些字段刚刚填写的用户需要INSERT而不是更新。怎么做得最好?


我想我确切地询问如何处理同步更新和插入。


谢谢,


弗兰克

Hi all,

I am nearing the end of programming my select forms and I will be soon need to create my insert and update forms. I have a question as to how this is best handled.

I want to use one form to do the inserts and updates. Now, as far as the data in the database goes, if I have some data in a table already and only 1 field needs to be updated how does this work? Should I use an "if" conditional and isset on every field in the form or just update the whole table?

In other words, if the user wants to update a record and only changes 1 field in the form, I would *think* that only that 1 field should be updated and not all of the fields in the form. Am I correct on this?

I am also curious as how to handle the INSERT of new data as well. Lets say that the same form from above has 3 fields that have *NO* data and the user wants to update 1 or 2 fields in the form and sees that 3 of these fields are blank and then decides to fill it in. Those fields that the user just filled in will need an INSERT and not an update. How is this best done?

I suppose I am asking exactly how simultaneous updates and inserts are handled.

Thanks,

Frank

推荐答案

嗨弗兰克。欢迎来到The Scripts!


始终验证从表单中收到的任何数据非常重要。特别是如果你要将它插入数据库中。

如果你不是,黑客可以通过在表单输入字段中键入SQL语法来清理整个数据库! br />
如果您需要一个地方,请查看 htmlentities()功能开始。


至于更新查询。我同意你的意见,你不应该更新尚未更改的字段。然而,值得经常更麻烦的是,试图找出一个字段是否已经改变。我不会经历任何真正的麻烦,以避免更新未更改的数据,但我希望尽可能(特别是如果它们包含大量数据)。


即使a如果字段在已存在的行中为空,则它在技术上会有一个值,即使它是NULL(实际上,NULL不是值)。因此,要将数据插入到这样的字段中,您将使用UPDATE命令。

INSERT仅用于创建新行。
Hi Frank. Welcome to The Scripts!

It is very important to always validate any data that you receive from your form. Especially if you are going to be inserting it into a Database.
If you don''t, a hacker might be able to clean out your entire database by typing SQL syntax into the form input fields!
Check out the htmlentities() function, if you need a place to start.

As for the update queries. I agree with you that you should not update fields that have not been changed. It is, however, often more trouble that it is worth, trying to find out if a field has been changed or not. I would not go through any real trouble to avoid updating data that has not changed, but I would prefer it if possible (especially if they contain large amounts of data).

Even if a field is empty in a row that already exists it will technically have a value, even if it is NULL (tho in reality NULL is not a value). So to insert data into such a field you would use an UPDATE command.
INSERT is only used to create new rows.



嗨弗兰克。欢迎来到The Scripts!


始终验证从表单中收到的任何数据非常重要。特别是如果你要将它插入数据库中。

如果你不是,黑客可以通过在表单输入字段中键入SQL语法来清理整个数据库! br />
如果您需要一个地方,请查看 htmlentities()功能开始。


至于更新查询。我同意你的意见,你不应该更新尚未更改的字段。然而,值得经常更麻烦的是,试图找出一个字段是否已经改变。我不会经历任何真正的麻烦,以避免更新未更改的数据,但我希望尽可能(特别是如果它们包含大量数据)。


即使a如果字段在已存在的行中为空,则它在技术上会有一个值,即使它是NULL(实际上,NULL不是值)。因此,要将数据插入到这样的字段中,您将使用UPDATE命令。

INSERT仅用于创建新行。
Hi Frank. Welcome to The Scripts!

It is very important to always validate any data that you receive from your form. Especially if you are going to be inserting it into a Database.
If you don''t, a hacker might be able to clean out your entire database by typing SQL syntax into the form input fields!
Check out the htmlentities() function, if you need a place to start.

As for the update queries. I agree with you that you should not update fields that have not been changed. It is, however, often more trouble that it is worth, trying to find out if a field has been changed or not. I would not go through any real trouble to avoid updating data that has not changed, but I would prefer it if possible (especially if they contain large amounts of data).

Even if a field is empty in a row that already exists it will technically have a value, even if it is NULL (tho in reality NULL is not a value). So to insert data into such a field you would use an UPDATE command.
INSERT is only used to create new rows.



嗨Atli,

有几件事。首先,我注意到了......我在TSDN上有两个账号。我有一个名为fjm的帐户同样。有没有办法整合帐户或者只是删除这个? :)


你的权利。数据验证是我将在程序中使用的东西,并且非常有用。你在谈论注射,我知道..


所以,如果我正确理解你的Alti,你只是想更新表格上的所有信息,对吗?这确实会更容易*。


好​​的。所以,如果我正确理解你,INSERT只是创建一个新行,UPDATE只更新* existing *行,即使给定字段中没有值。正确吗?


这将是我的问题。我不希望有一个单独的新记录。和编辑 buttion。我宁愿只有一个按钮用于BOTH插入和更新,并在脚本中编写一些逻辑来决定需要发生什么。这可能吗?


谢谢,


Frank

Hi Atli,

A couple of things. Firstly, I noticed that somehow... I have two accounts on TSDN. I have an account called "fjm" as well. Is there any way to consolidate accounts or maybe just delete this one? :)

Your right. data validation is something that I will be using in the program and is really nessessary. You are talking about injection, I know..

So, if I am understanding you correctly Alti, you are saying to simply just update all info on the form, right? That will be *much* easier indeed.

Ok. So again, if I am understanding you correctly, INSERT is only to create a new row and UPDATE just updates the *existing* row even if there is no value in a given field. Correct?

Here would be my issue then. I do not want to have a seperate "New record" and "Edit" buttion. I would prefer to have just one button for BOTH inserts and updates and program some logic into the script to decide what needs to happen. Is this possible?

Thanks,

Frank



嗨Atli,

有几件事。首先,我注意到了......我在TSDN上有两个账号。我有一个名为fjm的帐户同样。有没有办法整合帐户或者只是删除这个? :)
Hi Atli,

A couple of things. Firstly, I noticed that somehow... I have two accounts on TSDN. I have an account called "fjm" as well. Is there any way to consolidate accounts or maybe just delete this one? :)



我不知道删除它但可能有可能禁止它:P

它可能是如果你刚停止使用它并登录到另一个就更容易了。

I don''t know about deleting it but it is probably possible to ban it :P
Tho it would probably be easier if you just stopped using it and logged into the other one.


所以,如果我正确理解你的Alti,你只是说更新表格上的所有信息,对吗?这确实会更容易*。
So, if I am understanding you correctly Alti, you are saying to simply just update all info on the form, right? That will be *much* easier indeed.



确实更容易。但是当你创建第一个Service Pack时回到那个可能是个好主意:)

Much easier indeed. But it would maybe be good idea to come back to that when you create the first Service Pack :)


好​​的。所以,如果我正确理解你,INSERT只是创建一个新行,UPDATE只更新* existing *行,即使给定字段中没有值。正确?
Ok. So again, if I am understanding you correctly, INSERT is only to create a new row and UPDATE just updates the *existing* row even if there is no value in a given field. Correct?



正确。

Correct.


这将是我的问题。我不希望有一个单独的新记录。和编辑 buttion。我宁愿只有一个按钮用于BOTH插入和更新,并在脚本中编写一些逻辑来决定需要发生什么。这可能吗?
Here would be my issue then. I do not want to have a seperate "New record" and "Edit" buttion. I would prefer to have just one button for BOTH inserts and updates and program some logic into the script to decide what needs to happen. Is this possible?



一切皆有可能! :)


正如我想象的那样,您必须选择一个或多个字段作为唯一字段。然后,当您的用户填写表单时,您必须检查是否存在唯一字段。如果他们这样做,你会更新它们。如果他们不是你会创造一个新的行。


我个人会创建一个''新''按钮和一个''编辑''按钮,但那是'只是我。

Everything is possible! :)

As I imagine this scenario, you would have to choose one or more fields as Unique fields. Then when your user fills out the form you would have to check whether the Unique fields exist. If they do you would update them. If they don''t you would create a new row.

I personally would create a ''New'' button and an ''Edit'' button, but that''s just me.


这篇关于如何使用表单插入或更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆