0
昨天我的問題是關於插入和更新的一種形式,我做了,但數據插入,當我點擊編輯鏈接,它可以在displayp.php它顯示所有數據的字段,但是當我更新任何數據,並點擊提交按鈕其不更新,但它下一次插入數據在數據庫中,我在數據庫中獲取多個記錄。其實我已經把插入和更新中,如果當我更新它不是在其他部分動,所以請幫我...條件謝謝..以一種形式插入和更新
<div id="page-wrapper" >
<div id="page-inner">
<div class="row">
<div class="col-md-12">
<h2>Add Product</h2>
</div>
</div>
<!-- /. ROW -->
<hr />
<div class="row">
<?php
include('config.php');
if($_SERVER['REQUEST_METHOD']=='POST')
{
if(isset($_POST['submit'])=='POST')
{
echo "working";
$fileName=$_FILES["filepdf"]["name"];
$fileSize=$_FILES["filepdf"]["size"]/2024;
$fileType=$_FILES["filepdf"]["type"];
$fileTmpName=$_FILES["filepdf"]["tmp_name"];
if($fileType=="application/pdf"){
if($fileSize<=200){
//New file name
$random=rand(1111,9999);
$newFileName=$random.$fileName;
//File upload path
$uploadPath="testUpload/".$newFileName;
//function for upload file
if(move_uploaded_file($fileTmpName,$uploadPath))
{
echo "Successful<BR>";
echo "File Name :".$newFileName."<BR>";
echo "File Size :".$fileSize." kb"."<BR>";
echo "File Type :".$fileType."<BR>";
}
else
{
echo "Maximum upload file size limit is 200 kb";
}
}
else
{
return false;
echo "You can only upload a pdf doc file.";
}
echo "here downld";
$updates = isset($_POST['updates']) ? 'Yes' : 'No';
$catnm=$_POST['catnm'];
$prodnm=$_POST['prodnm'];
$prod_dtl=$_POST['prod_dtl'];
//$updates=$_POST['downld'];
$date=$_POST['date'];
$query=("insert into addproduct(catnm,prodnm,prod_dtl,pdf,downld,date)
values('$catnm','$prodnm','$prod_dtl','$uploadPath','$updates','$date')");
$result = mysql_query($query,$conn);
echo"record inserted";
if($result)
{
header("location:addProduct.php");
}
}
}
}
else if($_SERVER['REQUEST_METHOD']=='GET')
{
if(isset($_GET['id']))
{
$id = $_GET['id'];
if(isset($_POST['submit']))
{
$updates['downld'] = isset($_POST['downld']) ? 'Yes' : 'No';
$cat['catnm']=$_POST['catnm'];
$prodnm['prodnm']=$_POST['prodnm'];
$prod_dtl['prod_dtl']=$_GET['prod_dtl'];
$pdf['pdf']=$_GET['pdf'];
$downld['downld']=$_GET['downld'];
$date['date']=$_GET['date'];
$query3=mysql_query("update addproduct set catnm='$cat',
prodnm='$prodnm',prod_dtl='$prod_dtl'
,pdf='$pdf',downld='$updates',date='$date' where id='$id'");
if($query3)
{
header('location:addProduct.php');
}
}
$query1=mysql_query("select * from addproduct where id='$id'");
$query4=mysql_fetch_array($query1);
//echo "<pre>";
//print_r($query4);
}
}
?>
<div class="col-md-6 col-sm-12 col-xs-12">
<div class="panel-body">
<form role="form" method="post"
enctype="multipart/form-data" name="myform" >
<br/>
<label>Select Category:</label>
<div class="form-group">
<?php
include('config.php');
$query1=mysql_query("select catnm from addcategory");
?>
<select class=form-control m-b-10 name=catnm id=catnm >
<?php
echo"<option>---Select---</option required>";
while($query=mysql_fetch_array($query1))
{
$selectedCat = '';
if($query[catnm] == $query4['catnm'])
{
$selectedCat = "selected";
}
echo "<option value='$query[catnm]' $selectedCat >$query[catnm]</option>";
}
?>
</select>
<br/>
<div class="form-group">
<input type="text" class="form-control"
id="prodnm" placeholder="Product Name" name="prodnm" required
value= " <?php if(isset($query4['prodnm'])){echo $query4['prodnm'];}?>"/>
</div>
<div class="form-group">
<textarea class="form-control" id="catdtl"
name="prod_dtl" placeholder="Product Detail"
"rows="10" cols="62" required>
<?php if(isset($query4['prod_dtl'])){
echo $query4['prod_dtl'];} ?>
</textarea>
</div>
<div class="form-group">
<label for="exampleInputFile">PDF File</label>
<input type="file" id="exampleInputFile"
accept="application/pdf" name="filepdf" required >
file : <?php if(isset($query4['pdf'])){
echo $query4['pdf'];} ?>
</div>
<div class="checkbox">
<label>
<input id="checkbox" type="checkbox" name="updates" required
<?php if(isset($query4['downld']))
{ if($query4['downld'] == 'Yes')
echo "checked='checked'"; echo $query4['downld'];}
?> />
Is Downloadable <br />
</label>
</div>
<input type="text"
placeholder="Date of Upload" id="datepicker-7"
name="date" value="<?php if(isset($query4['date'])){
echo $query4['date'];}?>" required />
<div style="padding-top:20px;padding-bottom:40px;width:650px;">
<input type="submit" name="submit" id="button" tabindex="2"/>
<hr/>
</form>
</div>
<!-- /. ROW -->
</div>
<!-- /. PAGE INNER -->
</div>
<!-- /. PAGE WRAPPER -->
</div>
</body>
</html>
現在感謝它的工作... – asfaak
如果它工作選擇答案接受和問題將被視爲解決 – Michael