以下代码正常工作,直到我向DB
添加了5个新字段。错误在于
INSERT
部分,在mysqli_stmt_execute ( $stmt_2 );
行上奇怪地,使用相同参数的UPDATE
部分没有错误。我现在已经读了几个小时的相同行,我没有看到解析错误的原因。
$bdd = mysqli_connect('localhost', 'root', '', 'webpage');
if ( mysqli_connect_errno() ) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); }
$num = NULL ;
$oferta = $_POST['oferta'];
$titulo = $_POST['titulo'];
$desd = NULL ;
$hast = NULL ;
$descuen = NULL ;
$tipo_hab = NULL ;
$dias_min = NULL ;
mysqli_set_charset ( $bdd , 'utf8' );
$stmt_1 = mysqli_stmt_init($bdd);
$query = "SELECT num FROM promo"; //.......................... counting offers
if ( mysqli_stmt_prepare($stmt_1, $query))
{
mysqli_stmt_execute($stmt_1);
mysqli_stmt_store_result($stmt_1);
$number_of_offers = mysqli_stmt_num_rows($stmt_1);
mysqli_stmt_close($stmt_1);
}
else { echo ' no select'; exit; }
if ( $number_of_offers < 1 ) // ...................... if offers < 1 : INSERT (used on the 1st time when there is no record )
{
$stmt_2 = mysqli_stmt_init($bdd);
if ( mysqli_stmt_prepare ( $stmt_2, "INSERT INTO promo
( num , date , oferta , titulo , desd , hast , descuen , tipo_hab , dias_min ) Values(?,?,?,?,?,?,?,?,?)"))
{
mysqli_stmt_bind_param( $stmt_2 ,"issssssss",$num,$date,$oferta,$titulo,$desd,$hast,$descuen,$tipo_hab,$dias_min)
mysqli_stmt_execute ( $stmt_2 );
mysqli_stmt_close ( $stmt_2 );
mysqli_close($bdd);
}
else { echo ' no insert'; exit; }
}
else //................................................... if offers not < 1 : UPDATE
{
$stmt_3 = mysqli_stmt_init($bdd);
if ( mysqli_stmt_prepare ( $stmt_3, "UPDATE promo SET num= ? , date= ? , oferta= ? , titulo= ? , desd= ? , hast= ? , descuen= ? , tipo_hab= ? , dias_min= ? " ))
{
mysqli_stmt_bind_param( $stmt_3 ,"issssssss", $num , $date, $oferta , $titulo, $desd , $hast , $descuen , $tipo_hab , $dias_min );
mysqli_stmt_execute ( $stmt_3 );
mysqli_stmt_close ( $stmt_3 );
}
else { echo ' no update'; exit; }
}
答案 0 :(得分:4)
之前错过了分号!