项目用PHP做,在此之前我对PHP一无所知,项目中的代码写成这样可以吗,存在哪些问题?希望大家指点,其中的is_price , is_date, is_invited, is_first 都来自页面复选框  $state = '1';
$state .= isset($_REQUEST['is_price'])?'1':'0'; //有价格区间
$state .= isset($_REQUEST['is_date'])?'1':'0'; //有日期取件
$state .= isset($_REQUEST['is_times'])?'1':'0'; //有次数限制
$is_first .= isset($_REQUEST['is_first'])?'1':'0';
$is_invited .= isset($_REQUEST['is_invited'])?'1':'0';
$use_times = empty($_REQUEST['use_times'])?'0':$_REQUEST['use_times'];
$start_price = empty($_REQUEST['start_price'])?"null":$_REQUEST['start_price'];
$end_price = empty($_REQUEST['end_price'])?"null":$_REQUEST['end_price'];
$start_date = empty($_REQUEST['start_date'])?"null":$_REQUEST['start_date'];
$end_date = empty($_REQUEST['end_date'])?"null":$_REQUEST['end_date'];

$cutoff_money = 0;
$cutoff_percent = 0;
if($_REQUEST['cutoff_type']=='M')
$cutoff_money = $_REQUEST['cutoff_value'];
else
$cutoff_percent = $_REQUEST['cutoff_value']; 

$series_list = isempty($_REQUEST['series_list'])?"":$_REQUEST['series_list'];

$sql = sprintf( "insert into tbl_preference ( preference_state, cutoff_type, " .
"start_price, end_price, use_times. series_list, start_date, end_date, is_first, is_invited ".
"cutoff_money, cutoff_percent, used_times ) values( '%s','%s',
%s, %s, %s, '%s', '%s', '%s', '%s', '%s', %s, %s, '0' )",
$state, $_REQUEST['cutoff_type'], $start_price, $end_price,
$use_times, $series_list, $start_date, $end_date,
$is_first, $is_invited, $cutoff_money, $cutoff_percent);

mysql_query($sql) or die("error : " . mysql_error() . " :sql : $sql");刚注册的号为啥不能设置点数啊,晕,一会加分

解决方案 »

  1.   

    sql = sprintf( "insert into tbl_preference ( preference_state, cutoff_type, " .
                        "start_price, end_price, use_times. series_list, start_date, end_date, is_first, is_invited ".
                        "cutoff_money, cutoff_percent, used_times ) values( '%s','%s',
                        %s, %s, %s, '%s', '%s', '%s', '%s', '%s', %s, %s, '0' )",
                        $state, $_REQUEST['cutoff_type'], $start_price, $end_price,
                        $use_times, $series_list, $start_date, $end_date,
                        $is_first, $is_invited, $cutoff_money, $cutoff_percent);
    可以直接这样values ('$state'...)