PHP数据提交思想
上次说过表单提交简单获取方法.后来想想.原来SQL语句也可以简化.
if(!emptyempty($_POST)){
foreach ($_POST as $key=>$val)
{
$sql.=$key.",";
$value.="'".$val."',";
}
mysql_connect("localhost","root","");
mysql_select_db("tryease");
mysql_query("INSERT INTO `table` (".substr($sql, 0, -1).")VALUES(".substr($value, 0, -1).")");
echo "INSERT INTO `table` (".substr($sql, 0, -1).")VALUES(".substr($value, 0, -1).")";
}
要保持表单名和数据库中的字段名一到,再有就是注意表单的安全问题.
跟据个人而定.