编辑/更新 - 所有在一个PHP页面? [英] edit/update - all in one PHP pages?

查看:51
本文介绍了编辑/更新 - 所有在一个PHP页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




让我解释一下我一般会做些什么。对于用户

编辑数据的页面,我通常称之为editfred.php(对于

示例),更新数据的页面将是调用

updatefred.php,同样处理删除的页面将是

deletefred.php。我喜欢用这种方式分割页面,感觉不那么混乱,而且比将所有功能集中在一起更有条理。

fred.php。

这是问题所在。如果用户将错误数据输入

表格editfred.php,该表格随后由updatefred.php

处理,则需要向用户报告该错误。传统上我已经完成了什么,我已经完成了updatefred.php列出它找到的任何错误然后

提供了一个返回或要求用户点击后退按钮的链接在他们的浏览器上
。这已经不再可行了,而是我想自己将
自动扔回到editfred.php,并且所有数据都已经填入了
已填写的字段和导致错误的字段突出显示。我的

问题是:最好的方法是什么?


有几种方法让人想到:


1)结合editfred.php和updatefred.php。再说一遍,我并不热衷于这个

,但它似乎最合乎逻辑,编程最简单。


2)使用会话来存储数据,然后,editfred.php会在每次加载时检查会话中的数据。是否有最大数据

大小用于会话对象?


3)编写代码将数据包装并存储在cookie中然后可以
由editfred.php读取,类似于我认为的会话。但是最大值

cookie大小是4Kb,这在某些形式上是不够的。


4)将editfred.php中的数据存储在一个表中

再次编辑的数据库editfred.php将在加载时检查。数据库访问的开销
每次都是



还有其他想法吗?你们现在用什么方法?


谢谢,


吉姆。

Hi,

Let me explain how I''d generally do things. For a page where the user
edits data, I''d generally call it something like editfred.php (for
example), the page which updates the data would be called
updatefred.php and equally the page which processes a delete would be
deletefred.php. I like splitting the pages up this way, it feels less
cluttered and more organised than throwing all the functionality in one
fred.php.

Here''s the problem though. If the user enters erroneous data into the
form editfred.php which is subsequently processed by updatefred.php
then that error needs to be reported to the user. Traditionally what
I''ve done is have updatefred.php list any errors it finds and then
provide a link to go back or ask the user to hit the back button on
their browser. This is no longer viable, instead I''d like to
automatically throw them back to editfred.php with all their data
already filled in and the fields causing errors to be highlighted. My
question is: what''s the best way to do this?

There springs to mind several ways:

1) combine editfred.php and updatefred.php. Again, I''m not keen on this
but it does seem the most logical and programatically easiest.

2) use sessions to store the data, editfred.php would then check
for data in the session each time it''s loaded. Is there a maximum data
size for use with session objects?

3) write code to wrap and store the data in a cookie which could then
be read by editfred.php, similar to sessions I believe. However max
cookie size is 4Kb which wouldn''t be enough on some forms.

4) store the data from editfred.php in a table in the database which
again editfred.php would check for when loaded. overhead of db access
each time however.

Any other ideas? What method do you guys currently use?

Thanks,

Jim.

推荐答案

嗨!


您是否正在寻找serialize() ?


Best

Olaf
Hi!

Are you looking for "serialize()" ?

Best
Olaf


我不相信。我还有同样的问题。如果我将所有表单数据序列化为

,我仍然需要将其发送回原始输入

页面并且必须通过cookie,数据库完成或者

文本文件。我能想到的唯一另一种方法是冒险使用

javascript来提交更新页面生成的隐藏表格。


我正在努力为了找到不将编辑/更新

功能放在一个php文件中的理由,我最初的担心(除了事实

我不喜欢这个想法将这两个过程结合起来)

是解释器必须解析文件的性能问题

可能是它需要的两倍大。


Jim。

I don''t believe so. I''d still have the same problems. If I serialise
all the form data, I still need to send it back to the original input
page and that''ll have to be done either through cookies, database or
text file. The only other way I can think of is the risky use of
javascript to submit a hidden form produced by the update page.

I''m struggling to find justification for not putting the edit/update
functionality in one php file, my original worry (other than the fact
that I just don''t like the idea of having the two processes combined)
was the performance issue of the interpreter having to parse a file
probably twice as big as it needs to be.

Jim.


你好!


将序列化数据放入会话变量....


Olaf
Hello!

Put the serialized data in a session Variable....

Olaf


这篇关于编辑/更新 - 所有在一个PHP页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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