我正在尝试使用PHP更新数据库中的列但是我无法完成它但我无法弄清楚Error.I已经解决了此站点上的先前问题但到目前为止没有解决方案,下面是我的代码 我的edititem.php页面代码
<body>
<br><br><br>
<center><font color="#660066" size="+3">Update Item</font></center>
<br><br>
<a href="?con=4"><button>view all items</button></a>
<center><fieldset style="width:50%">
<?php
require_once("Dbconfig.php");
$sel=mysqli_query($conn,"select * from items where Id='{$_GET['itemno']}'") or die(mysqli_error($conn));
$result_set=mysqli_fetch_array($sel);
$id=$result_set['id'];
$category=$result_set['catg'];
$subcategory=$result_set['subcatg'];
$amount=$result_set['stock'];
$itemno=$result_set['itemno'];
$price=$result_set['price'];
$description=$result_set['descr'];
$chair=$result_set['chairm'];
$table=$result_set['tablem'];
$material=$result_set['material'];
$amount=$result_set['amount'];
$glass=$result_set['glass'];
$pieces=$result_set['pieces'];
$seats=$result_set['seats'];
$stools=$result_set['stools'];
$guarantee=$result_set['guarantee'];
?>
<?php
require_once("Dbconfig.php");
$sel=mysqli_query($conn,"select category from category where cat_id='$category'") or die(mysqli_error($conn));
$results_set=mysqli_fetch_array($sel);
$cat=$results_set['category'];
?>
<?php
require_once("Dbconfig.php");
$sel=mysqli_query($conn,"select subcategory from subcategory where subcategory='$subcategory'") or die(mysqli_error($conn));
$result_sets=mysqli_fetch_array($sel);
$subcat=$result_sets['subcategory'];
?>
<?php
sleep(1);
?>
<form name="testform" method="post" action="editItem.php" enctype="multipart/form-data" >
<table align="center">
<tr>
<td><span class="style3">Product Name:</span></td>
<td><input name="product_name" type="text" required="required" placeholder="Product name"></td></tr>
<tr><td width="111"><span class="style3">Category:</span></td>
<td width="264"><select name="cat" onChange="showUser(this.value)">
<option value="<?php echo $cat; ?>"><?php echo $cat; ?></option>
<?php
require "Dbconfig.php";// connection to database
$q=mysqli_query($conn,"select * from category ");
while($n=mysqli_fetch_array($q)){
echo "<option value=".$n['cat_id'].">".$n['category']."</option>";
}
?>
</select></td>
</tr>
<tr><td><span class="style3"> Sub Category:</span></td>
<td>
<select name="subcat" id="subcat">
<option value="<?php echo $subcat; ?>"><?php echo $subcat; ?></option>
<?php
require "Dbconfig.php";// connection to database
$q=mysqli_query($conn,"select * from subcategory ");
while($n=mysqli_fetch_array($q)){
echo "<option value=".$n['subcategory'].">".$n['subcategory']."</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td><span class="style3">Amount:</span></td>
<td><input name="amount" type="text" value="<?php echo $amount; ?>"></td></tr>
<tr>
<td><span class="style3">Image:</span></td>
<td><input name="file" type="file"></td></tr>
<tr>
<td><span class="style3">Item No: </span></td>
<td><label>
<input name="t1" type="text" id="t1" value="<?php echo $itemno; ?>">
</label></td>
</tr>
<tr>
<td><span class="style3">Price:</span></td>
<td><label>
<input name="t2" type="text" id="t2" value="<?php echo $price; ?>">
</label></td>
</tr>
<tr>
<td><span class="style3">Table Measurement:</span></td>
<td><label>
<input name="t3" type="text" id="t3" value="<?php echo $table; ?>" >
</label></td>
</tr>
<tr>
<td><span class="style3">Chair Measurement:</span></td>
<td><label>
<input name="t4" type="text" id="t4" value="<?php echo $chair; ?>">
</label></td>
</tr>
<tr>
<td><span class="style3">Glass Measurement:</span></td>
<td><label>
<input name="t15" type="text" id="t15" value="<?php echo $glass; ?>">
</label></td>
</tr>
<tr>
<td><span class="style3">Material:</span></td>
<td><label>
<input name="t5" type="text" id="t5" value="<?php echo $material; ?>">
</label></td>
</tr>
<tr>
<td><span class="style3">Seats:</span></td>
<td><label>
<input name="t13" type="text" id="t13" value="<?php echo $seats; ?>">
</label></td>
</tr>
<tr>
<td><span class="style3">Stools:</span></td>
<td><label>
<input name="t12" type="text" id="t12" value="<?php echo $stools; ?>">
</label></td>
</tr>
<tr>
<td><span class="style3">Pieces Included:</span></td>
<td><label>
<input name="t10" type="text" id="t10" value="<?php echo $pieces; ?>" >
</label></td>
</tr>
<tr>
<td><span class="style3">Guarantee:</span></td>
<td><label>
<input name="t9" type="text" id="t9" value="<?php echo $guarantee; ?>">
</label></td>
</tr>
<tr>
<td><span class="style3">Description:</span></td>
<td><textarea name="text" cols="35" rows="6"><?php echo $description; ?></textarea></td></tr>
<tr><td colspan="2" align="center">
<input type="hidden" name="id" value="<?php echo $id; ?>" />
<input name="edititem" type="submit" value="Submit"></td></tr>
</table>
</form>
</fieldset></center>
</body>
我的edititem.php代码是
<?php
session_start();
$name=$_SESSION['usr_id'];
include("Dbconfig.php");
if(isset($_POST['submit']))
{
$productname=$_POST['product_name'];
$catg=$_POST['cat'];
$subcatg=$_POST['subcat'];
$img=$_FILES['file']['tmp_name'];
$itemno=$_POST['t1'];
$price=$_POST['t2'];
$chair=$_POST['t3'];
$table=$_POST['t4'];
$material=$_POST['t5'];
$descr=$_POST['text'];
$amount=$_POST['amount'];
$glass=$_POST['t15'];
$pieces=$_POST['t10'];
$seats=$_POST['t13'];
$stools=$_POST['t12'];
$guarantee=$_POST['t9'];
$pid=$_POST['id'];
include("Dbconfig.php");
$sql = mysqli_query($conn,"UPDATE `items` SET
(`product_name`='$productname',`catg`='$catg',`subcatg`='$subcatg',
`img`='$image',`price`='$price',`tablem`='$table',
`chairm`='$chair',`material`='$material',`descr`='$descr',
`glass`='$glass',`pieces`='$pieces',`seats`='$pieces',
`stools`='$stools',`guarantee`='$guarantee')
WHERE `id` ='$pid'");
echo "<script>'Window.alert(productUpdated successful)'</script>";
echo ("<script>location.href='admin.php'</script>");
} else {
echo "Update Failed!Please Try Again";
}
?>
该页面显示一个空的白色屏幕。帮助我找出我的代码的问题,因为我已经尝试了所有可能的资源,但我找不到解决方案。
答案 0 :(得分:-2)
<?php
session_start();
$name=$_SESSION['usr_id'];
include("Dbconfig.php");
if(isset($_POST['submit']))
{
$productname=$_POST['product_name'];
$catg=$_POST['cat'];
$subcatg=$_POST['subcat'];
$img=$_FILES['file']['tmp_name'];
$itemno=$_POST['t1'];
$price=$_POST['t2'];
$chair=$_POST['t3'];
$table=$_POST['t4'];
$material=$_POST['t5'];
$descr=$_POST['text'];
$amount=$_POST['amount'];
$glass=$_POST['t15'];
$pieces=$_POST['t10'];
$seats=$_POST['t13'];
$stools=$_POST['t12'];
$guarantee=$_POST['t9'];
$pid=$_POST['id'];
include("Dbconfig.php");
$sql = mysqli_query($conn,"UPDATE `items` SET `product_name`='$productname', `catg`='$catg', `subcatg`='$subcatg', `img`='$image', `price`='$price', `tablem`='$table', `chairm`='$chair', `material`='$material', `descr`='$descr', `glass`='$glass', `pieces`='$pieces', `seats`='$pieces', `stools`='$stools', `guarantee`='$guarantee' WHERE `id` ='$pid'");
echo "<script>Window.alert('productUpdated successful')</script>";
// echo ("<script>location.href='admin.php'</script>");
} else {
echo "Update Failed!Please Try Again";
}
?>
嗨,我已更新了您的edititem.php
文件。
你说的是它的空白页面,这意味着它将处于成功状态但不会移动下一步。
我更新了警戒线。请试试这个。
我评论了重定向,让我们保持评论,让我们看看是否收到提醒。
然后取消注释并查看它是否重定向
答案 1 :(得分:-2)
如果这些文件已完成,则缺少$ conn初始化。
如果在Dbconfig.php中初始化$ conn,则需要将其指定为全局变量,并在此文件中调用global。 Php可能只是错误输出,如果您的页面为空,请尝试启用错误输出:
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
另一个问题可能是没有验证输入,你至少可以使用if(!empty())语句
旁注,您不会转义/验证变量,并且您的代码容易受到sql注入的攻击。</ p>