<?
$stop = $_GET['stop']
$onoff = $_GET['onoff']
$linkid=@mysql_connect("localhost", "root" , "12345") or die("不能连接到数据库服务器!可能是数据库服务器没有启扮腔动,或者用户名密码有误!")
@mysql_select_db("ok_11",$linkid) or die("选择数据库出错,可能是您指定的数据库不存在!")
$stop_query = "update tb_1 set $stop=$onoff"
$stop_result = @mysql_query("$stop_query",$linkid)
echo '<meta http-equiv="Content-Type" conten'
echo 't="text/html charset=gb2312" />
<html>
<head>
<title>开关面板</title>
<meta http-equiv="Content-Type" content="text/html charset=iso-8859-1">
<scrip'
echo 't language="JavaScript">
<!--
function Stopan(i) {
with(document.getDataForm){
st'
echo 'op.value = stop_1
onoff.value = i
submit()
}
}
//-->
</scri'
echo 'pt>
</head>
<body>
<a h'
echo 'ref="JavaScript: Stopan(0)">打开</a> / <a href=http://topic.csdn.net/t/20061230/07/"JavaScript: Stopan(1)">关闭</a>
</body>
</html>'
?>
总是提示SCRIPT ERROR!不知错在哪里,初学者,不会请别见笑!谢谢指棚没导!
--------------------------------------------------------------------------------
顶!!!!!!
--------------------------------------------------------------------------------
<?
if(isset($_GET['stop']) && isset($_GET['onoff'])) {
$stop = $_GET['stop']
$onoff = $_GET['onoff']
$linkid=@mysql_connect("localhost", "root" , "12345") or die("不能连接到数据库服务器!可能是数据库服务器没有启动,或者用户名密码有误!")
@mysql_select_db("ok_11",$linkid) or die("选择数据库出错,可能是您指定的数据库不存在!")
$stop_query = "update tb_1 set $stop=$onoff"
$stop_result = @mysql_query("$stop_query",$linkid)
}
echo '<meta http-equiv="Content-Type" conten'
echo 't="text/html charset=gb2312" />
<html>
<head>
<title>开关面板</title>
<meta http-equiv="Content-Type" content="text/html charset=iso-8859-1">
<scrip'
echo 't language="JavaScript">
<!--
function Stopan(i) {
with(document.test){
st'
echo 'op.value = "stop_1"
onoff.value = i
submit()
}
}
//-->
</scri'
echo 'pt>
</head>
<body>
<a h'
echo 'ref="JavaScript: Stopan(0)">打开</a> / <a href=http://topic.csdn.net/t/20061230/07/"JavaScript: Stopan(1)">关闭</a>
<form name="test" method="GET" action="test1.php">
<input type="hidden" name="stop">
<input type="hidden" name="onoff">
</form>
</body>
</html>'
?>
哈,楼主用过zend framework啊,那这个更容易解释了。
首先声明,如果不进行特别的处理,使用php构造表单和直接使用html表单本身区别并不大。否则,有如下好处(尤其已Zend_Form为例):
1.Zend_Form对象允许你绑定验证器,有利于保证数据的有效性,且相同的Zend_Form_Element元素只需声明一次即可在任意表单空隐中使用,保证了他们的一致性,同时易于维护。例如
class My_Form extend Zend_Form {public function init() {
$this->addElement('text', 'user_id', array(
'label'=>'user',
'required' =>true,
'filters' =>array('StringTrim'),
'validators' =>array('Int'),
))
}
}
class Other_Form extend Zend_Form {
public function init() {
$form = new My_Form()
$this->addElement($form->getElement('user_id'))
}
}
第二个form直接从第一个form中取得元素而不需要二次声明
2.便于管理html样式,一般来说各个表单的字段不同,但是每个字段的外观一般是一样的,这虚猛样我们统一使用一个helper来输出字段,当需要修改样式的时候只要修改helper就行了,而不必逐个页面修改,例如
class Helper_Form_Checkbox extends Project_View_Helper_Form_Abstract {
/**
* Get html
* @see Project_View_Helper_Form_Abstract::_html()
*/
protected function _html(Zend_Form_Element $element, $item) {
$id = $element->getId()
$title = $element->getLabel()
$description = $element->getDescription()
return <<<_html
<div class="formElement">
<div class="clearFloat">
<div class="floatLeft">{$item}</div>
<label class="floatLeft" for="{$id}">斗誉厅{$title}</label>
</div>
</div>
_html
}
/**
* Get html use for display checkbox
* @param Zend_Form_Element $element
* @param array $attributes
* @return string
*/
public function form_checkbox(Zend_Form_Element $element, $attributes = array()) {
$attributes = array_merge($element->getAttribs(), $attributes)
if (isset($attributes[Project_Form::NAME_OF_ATTRIBUTE_REQUIRED])) {
unset($attributes[Project_Form::NAME_OF_ATTRIBUTE_REQUIRED])
}
$attributes['checked'] = (bool) $element->getValue()
$item = $this->view->formCheckbox($element->getName(), '1', $attributes)
return $this->_html($element, $item)
}
}
而输出的时候直接就可以
echo $this->form_text($zendFormElementInstance)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)