Home  >  Article  >  Backend Development  >  TP的一个自动创建问题

TP的一个自动创建问题

WBOY
WBOYOriginal
2016-06-23 13:54:08857browse

手册上面的方法是
$up->create();
$up->add();  然后就不用自己一个一个来写子段了。

但是如果我表单里只有两个值,但是数据库里面有4个字段,那这个方法怎么知道我表单的这两值是插入到那两个字段呢。
我的表单写法

<div class="user">									{$note}					<hr>					<form action='__APP__/index.php/u/upadmin' method='post'>					<table>							<caption>添加管理员名称</caption>						<tr>							<th>用户</th>							<td><input type='text' name='user' maxlength='10'></td>						</tr>						<tr>							<th>密码</th>							<td><input type='text' name='pwd' maxlength='10'/></td>						</tr>						<tr>							<td colspan='2'>								<input type='submit' />								<input type='reset' />							</td>						</tr>					</table>					</form>		</div>


我现在用的方法是
		               $data['aname']=$_POST['user'];		$data['apwd']=md5($_POST['pwd']);		$data['bak']=$_POST['pwd'];		if($_POST['user']==''){						$this->error('请输入用户名');			exit();		}		if($_POST['pwd']==''){			$this->error('密码没有输入,请认真检查');			exit();		}				$count=$upadmin->add($data);


我数据库有4个字段,表单的值只有两个,一个是用户名,一个是密码,插入数据库有三个值,一个是用户名,一个是加密的MD5,一个是没有加密的。


如果用自动,应该怎么插入,如果要用数组,一条一条来写,那还不是一样的,就不是自动了,比如一个表单有100+个值要插入数据库,那不是很麻烦。


现在我的目的就是用自动方法来插入到数据库。


回复讨论(解决方案)



这个是数据库的字段

呵呵,你只看到简单的 $up->create(); 一下
却没有看到前期的准备工作

呵呵,你只看到简单的 $up->create(); 一下
却没有看到前期的准备工作

恩,明白了,谢谢

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn