Maison >développement back-end >tutoriel php >mysqli_stmt_bind_param不能处理时间类型吗?

mysqli_stmt_bind_param不能处理时间类型吗?

WBOY
WBOYoriginal
2016-06-23 13:49:501639parcourir

 报错的这条语句

mysqli_stmt_bind_param($stmt, 'idii', $c, $a, $t, $w);


完整代码
<?phprequire ('inc/config.php');$page_title = '住宅数据添加-feige数据中心';include ('inc/header.php');require (MYSQL);if ($_SERVER['REQUEST_METHOD'] == 'POST') {		$trimmed = array_map('trim', $_POST);	$errors = array();	if(empty($trimmed['wdate'])) {		$errors[] = '日期不能为空';	} else {		$w = mysqli_real_escape_string ($conn, $trimmed['wdate']);	}		if ( isset($trimmed['city']) && filter_var($trimmed['city'], FILTER_VALIDATE_INT, array('city' => 1)) ) {		$c = mysqli_real_escape_string ($conn, $trimmed['city']);;	} else {		$errors[] = '请选择区域';	}		if (is_numeric($trimmed['taoshu']) && ($trimmed['taoshu'] > 0)) {		$t = mysqli_real_escape_string ($conn, (int) $trimmed['taoshu']);	} else {		$errors[] = '请输入一个正确的套数';	}	if (is_numeric($trimmed['area']) && ($trimmed['area'] > 0)) {		$a = mysqli_real_escape_string ($conn, (float) $trimmed['area']);	} else {		$errors[] = '请输入一个正确的面积';	}			if (empty($errors)) {		$q = 'INSERT INTO f_chengjiao (city_id, area, taoshu, fang_time, os_time) VALUES (?, ?, ?, ?, ?, NOW())';		$stmt = mysqli_prepare($conn, $q);		mysqli_stmt_bind_param($stmt, 'idii', $c, $a, $t, $w);		mysqli_stmt_execute($stmt);		if (mysqli_stmt_affected_rows($stmt) == 1) {			echo '<p>这条数据已经被添加</p>';			$_POST = array();			} else {			echo '<p style="font-weight: bold; color: #C00">程序发生错误,请重新添加</p>'; 		}			mysqli_stmt_close($stmt);		}	} if ( !empty($errors) && is_array($errors) ) {	echo '<p style="font-weight: bold; color: #C00">发生下列错误:<br />';	foreach ($errors as $msg) {		echo " - $msg<br />\n";	}	echo '请在试一遍</p>';}?><div class="portlet wrap mT50">	<div class="portlet-title">住宅数据添加</div>	<div class="portlet-body">	<form action="zhuzhai_add.php" method="post">		<div class="control-group">			<label class="control-label">时间</label>			<div class="controls">				<input type="text" name="wdate" class="add-in" onClick="WdatePicker()" value="" />时间格式例如:2014-12-12			</div>		</div>         <div class="control-group">			<label class="control-label">区域</label>			<div class="controls">				<select name="city" class="select-city">                    <?php 					$q = "SELECT city_id, city_name FROM f_city ORDER BY city_id ASC";							$r = mysqli_query ($conn, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($conn));					if (@mysqli_num_rows($r) > 0) {						while ($row = mysqli_fetch_array ($r, MYSQLI_NUM)) {							echo "<option value=\"$row[0]\"";							if (isset($trimmed['city']) && ($trimmed['city'] == $row[0]) ) echo ' selected="selected"';							echo ">$row[1]</option>\n";						}						mysqli_free_result ($r);					} else {						echo '<option>暂无区域,请添加一个新地区</option>';					}					mysqli_close($conn);					?>				</select>			</div>		</div>        <div class="control-group">			<label class="control-label">套数</label>			<div class="controls">				<input type="text" name="taoshu" class="add-in" value="" />套			</div>		</div>         <div class="control-group">			<label class="control-label">面积</label>			<div class="controls">				<input type="text" name="area" class="add-in" value="" />平方			</div>		</div>         <div class="form-actions">            <button class="btn" name="submit" type="submit">提交</button>	   	</div>   	</form>    </div></div><?phpinclude ('inc/footer.php');?>



报错提示
出错文件是 'D:\wamp\www\zhuzhai_add.php' 出错行号是 36: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, boolean givenDate/Time: 9-11-2014 03:52:53Array(    [_GET] => Array        (        )    [_POST] => Array        (            [wdate] => 2014-09-11            [city] => 1            [taoshu] => 50            [area] => 10000            [submit] =>         )    [_COOKIE] => Array        (        )    [_FILES] => Array        (        )    [_ENV] => Array        (        )    [_REQUEST] => Array        (            [wdate] => 2014-09-11            [city] => 1            [taoshu] => 50            [area] => 10000            [submit] =>         )


回复讨论(解决方案)

你的$conn 在哪初始化的? 且inser 语句的字段与值个数没匹配上吧。

mysqli_stmt_bind_param($stmt, 'idi s', $c, $a, $t, $w);

你的$conn 在哪初始化的? 且inser 语句的字段与值个数没匹配上吧。


$conn是数据库连接
insert的确多了一个?,但是还是会报错

mysqli_stmt_bind_param($stmt, 'idi s', $c, $a, $t, $w);


修改成s也报错

你的$conn 在哪初始化的? 且inser 语句的字段与值个数没匹配上吧。


<?php//数据库连接信息DEFINE ('DB_HOST', 'localhost');	// 服务器地址 DEFINE ('DB_USER', 'root');			// 数据库用户名DEFINE ('DB_PASSWORD', '');			// 数据库密码DEFINE ('DB_NAME', 'fang01');			// 数据库名$conn = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // 连接MYSQL数据库,选择指定的数据库if (!$conn) {	trigger_error ('Could not connect to MySQL: ' . mysqli_connect_error() );} else { 	mysqli_set_charset($conn, 'utf8'); // 设置字符集}?>

贴出修改后的sql串和错误信息

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Article précédent:php执行shell脚本问题Article suivant:PHP微信公众开发笔记(十)