我是php的初学者。我创建了如下形式,根据我的说法,它必须完成以下任务。
但它不起作用。它不会在 view.php 中显示来自DB的数据,并发出如下警告。
警告:mysql_fetch_array()期望参数1为资源,第81行的view.php中给出布尔值
请帮我解决这个问题。 感谢。
view.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="CSS/jquery.dataTables.css" type="text/css" />
<script type="text/javascript" src="JS/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="JS/jquery.dataTables.min.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
$('#example').dataTable();
} );
</script>
<?php session_start(); ?>
<?php
if(isset($_SESSION['example']))
{
echo $_SESSION['example'];
}
else
{
//echo "Session destroyed";
}
?>
</div>
</head>
<body>
<table id="example" class="row-border" cellspacing="0" width="100%">
<thead>
<tr>
<th>SRN</th>
<th>Client</th>
<th>Category</th>
<th>Short Description</th>
<th>Full Description</th>
<th>File Upload</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php while($row = mysqli_fetch_array($selectQ)){ ?>
<tr>
<td><?php echo $row['srn'];?></td>
<td><?php echo $row['client'];?></td>
<td><?php echo $row['category'];?></td>
<td><?php echo $row['sd'];?></td>
<td><?php echo $row['fd'];?></td>
<td><?php echo $row['upload'];?></td>
<td><a href="updateview.php?srn=<?php echo $row['srn']; ?>" target="_blank">Edit</a></td>
</tr>
<?php } ?>
</tbody>
</table>
</body>
</html>
dbconn.php
<?php
$mysqli = new mysqli("localhost", "root", "root", "eservice");
/* ESTABLISH CONNECTION */
if (mysqli_connect_errno()) {
echo "Failed to connect to mysql : " . mysqli_connect_error();
exit();
}
?>
updateview.php
<?php
include_once('dbconn.php');
$srn = $_GET['srn'];
$selQ = "Select * from main where srn = '".$srn."'";
$selectQ = mysql_query($selQ);
?>
<?php
while($row = mysql_fetch_array($selectQ)){ ?>
<form action="update.php" method="post" enctype="multipart/form-data" novalidate>
<?php
include_once('dbconn.php');
$srn = $_GET['srn'];
if($stmt = $mysqli->prepare("SELECT srn, client, category, sd, fd,upload FROM main WHERE srn=?")){
$stmt->bind_param("s",$_GET["srn"]);
$stmt->execute();
$stmt->bind_result($srn,$client,$category,$sd,$fd);
$stmt->fetch();
$stmt->close();
}
?>
<div class="item">
<label> <span>SRN</span>
<input name="srn" type="text" id="srn" size="15" readonly="readonly" maxlength="40" value="<?php echo $srn; ?>"/>
</label>
</div>
<div class="item">
<label> <span>Client</span>
<select class="required" name="client"/>
<?php
if($stmt = $mysqli->prepare("SELECT cname FROM client")){
$stmt->execute();
$stmt->bind_result($cname);
while($stmt->fetch()){
?>
<option value="<?php echo $cname; ?>" <?php if($cname==$client){ echo "selected"; } ?>> <?php echo $cname; ?> </option>
<?php
} /* END OF WHILE LOOP */
$stmt->close();
} /* END OF PREPARED STATEMENT OF CLIENT */
?>
</select>
</label>
</div>
<div class="item">
<label> <span>Category</span>
<select class="required" name="category"/>
<?php
if($stmt = $mysqli->prepare("SELECT name FROM category")){
$stmt->execute();
$stmt->bind_result($name);
while($stmt->fetch()){
?>
<option value="<?php echo $name; ?>" <?php if($name==$category){ echo "selected"; } ?>> <?php echo $name; ?> </option>
<?php
} /* END OF WHILE LOOP */
$stmt->close();
} /* END OF PREPARED STATEMENT OF CATEGORY */
?>
</select>
</label>
</div>
<div class="item">
<label> <span>Short Description</span>
<textarea required="required" name='sd'><?php echo $sd; ?></textarea>
</div>
<div class="item">
<label> <span>Full Description</span>
<textarea required="required" name='fd'><?php echo $fd; ?></textarea>
</div>
<div class="item">
<label> <span>Input Attachment</span>
<input type="file" name ="filename" required>
</label>
</div>
<br/><br/>
<div class="item">
<button id='cancel' type='cancel'>Cancel</button>
<button id='send' type='submit'>Update</button>
</div>
</form>
<?php } ?>
update.php
<?php
include('dbconn.php');
$stmt = $mysqli->prepare("UPDATE main SET client=?, category=?, sd=?, fd=? upload=? WHERE srn=?");
$stmt->bind_param('srn', $_POST["client"], $_POST["category"], $_POST["sd"], $_POST["fd"],$_POST["upload"],$_POST["srn"]);
$stmt->execute();
?>
答案 0 :(得分:0)
在你的dbconn.php中使用mysql而不是mysqli函数。在你的整个项目中使用mysql或使用mysqli。不要在不同的文件中使用不同的函数。