我是初學者的PHP。我已經創建瞭如下的表單,並根據我的需要執行以下任務。MYSQL更新交易顯示頁面
- view.php - 它會顯示來自數據庫的數據。在此頁面中,如果用戶點擊 編輯它將轉到updateview.php頁面。
- 在updateview.php頁面的用戶將只更新三個字段即,類別,簡要描述完整說明&文件上傳。當用戶點擊更新按鈕時,它將轉到update.php,然後它將處理,然後它將返回到帶有更新記錄的view.php。
但它不工作。它不顯示來自DB的數據view.php並給出警告如下。
警告:mysql_fetch_array()預計參數1是資源,布爾在view.php給出線81
請幫我解決這個問題。 謝謝。
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();
?>
停止使用不推薦的'mysql_ *'函數;改用MySQLi/PDO。 – Raptor 2015-02-12 06:50:22
我也檢查過。它的mysql_fetch_array($ selectQ)。但是,這種警告即將到來。 – Kiran 2015-02-12 07:18:46