PHP编辑表单不会更改数据库值

时间:2017-02-10 18:15:42

标签: php mysql

我的html / php表单不会改变数据库值,它在前段时间工作,现在我无法找到我的问题所在..也无法找到任何错误..我我真的不知道如何调试它。

这就是我的ViewParts(index.php)的外观:

php代码:

if((isset($_GET['action']) ? $_GET['action'] : null) == "formedit")
{
$part_id = strip_tags($_POST['part_id']);
$name = strip_tags($_POST['name']);
$manufacture = strip_tags($_POST['manufacture']);
$category = strip_tags($_POST['category']);
$code = strip_tags($_POST['code']);
$info = strip_tags($_POST['info']);

if (move_uploaded_file($_FILES["UploadImage"]["tmp_name"], $target_file)) {
    $image = $target_file;
} else {
}

if($name=="")   {
    $error[] = "Please, insert name!";  
}
if($manufacture=="")    {
    $error[] = "Please, insert manufacture!";   
}
else if($category=="")  {
    $error[] = "Please, select category!";  
}
else if($code=="")  {
    $error[] = 'Please, insert code!';
}
else if($info=="")  {
    $error[] = 'Please, insert info!';
}

if($part->editPart($part_id,$name,$manufacture,$category,$code,$info,$image)){  
                $auth_user->redirect('ViewParts.php');
            }

}

HTML方面:

    <?php 
    if((isset($_GET['action']) ? $_GET['action'] : null) == "edit"){
    $part_id = $_GET['part_id'];    ?>

<div class="container">
  <!-- <div class="col-sm-9 col-md-9">-->
        <div class="panel-group" id="accordion">
            <div class="panel panel-default">

   <form method="post" id="login-form" enctype="multipart/form-data" action="ViewParts.php?action=formedit">

    <center><h2 class="form-signin-heading">EDIT PART</h2><hr /></center>

    <div id="error">
    <?php
        if(isset($error))
        {
            ?>
            <div class="alert alert-danger">
               <i class="glyphicon glyphicon-warning-sign"></i> &nbsp; <?php echo $error; ?> !
            </div>
            <?php
        }
    ?>
    </div>

    <div class="form-group">
        <?php $part->selectPartForEdit();  ?>
    </div>

    <hr />

    <div class="form-group">
        <center><button type="submit" name="btnedit" class="btn btn-default">Edit</button></center>
    </div>

  </form> 

<!--</div>-->
</div>
</div>
</div>
    <?php } ?>

Class.partcatalogue.php

public function selectPartForEdit()
{
    try
    {
        $part_id = $_GET['part_id'];
        $stmt = $this->conn->prepare("SELECT part_id,image,name,manufacture,category,code,info FROM partcatalogue WHERE part_id=('$part_id')");

        $stmt->execute();

        echo "<table style='width:100%'>";
        echo "<tr>";
        echo "<th><center>Id</center></th>";            
        echo "<th><center>Name</center></th>";
        echo "<th><center>Code</center></th>";
        echo "<th><center>Manufacture</center></th>";
        echo "<th><center>Category</center></th>";
        echo "<th><center>Info</center></th>";
        echo "<th><center>Image</center></th>";
        echo "</tr>";

        foreach($stmt as $part){ 

        echo "<th style='width:50px'><center>"; ?><input class="form-control" type='text' name='part_id' value="<?php echo $part['part_id']?>"> <?php echo"</center></th>";
        echo "<th><center>"; ?><input class="form-control" type='text' name='name' value="<?php echo $part['name']?>"> <?php echo"</center></th>";
        echo "<th><center>"; ?><input class="form-control" type='text' name='code' value="<?php echo $part['code']?>"> <?php echo"</center></th>";
        echo "<th><center>"; ?><select class="form-control" type='text' name='manufacture'><option value='<?php echo $part['manufacture']?>'><?php echo $part['manufacture']?><?php $this->selectManufacture(); ?></option></select> <?php echo"</center></th>";
        echo "<th><center>"; ?><select class="form-control" type='text' name='category'><option value='<?php echo $part['category']?>'><?php echo $part['category']?><?php $this->selectCategory(); ?></option></select> <?php echo"</center></th>";
        echo "<th><center>"; ?><input class="form-control" type='text' name='info' value="<?php echo $part['info']?>"> <?php echo"</center></th>";
        echo "<th><center>"; echo "<img src='../../Images/Partcategories/".$part['image']."' width='50' height='50'/>"; echo"</center></th>";
        echo "<th><center>"; ?><input class="form-control" type='file' name='UploadImage' value="<?php echo $part['image']?>"> <?php echo"</center></th>";          
        echo "</tr>";
        }

        echo "</table>";

        return $stmt;   
    }
    catch(PDOException $e)
    {
        echo $e->getMessage();
    }               
}

public function editPart($part_id,$name,$manufacture,$category,$code,$info,$image)
{
    try
    {
        $part_id = $_GET['part_id'];
        $stmt = $this->conn->prepare("UPDATE partcatalogue SET part_id=:part_id, name=:name, manufacture=:manufacture, category=:category, code=:code, info=:info, image=:image  WHERE part_id=('$part_id')");

        $stmt->bindparam(":part_id", $part_id); 
        $stmt->bindparam(":name", $name);   
        $stmt->bindparam(":manufacture", $manufacture); 
        $stmt->bindparam(":category", $category);
        $stmt->bindparam(":code", $code);   
        $stmt->bindparam(":info", $info);               
        $stmt->bindparam(":image", $image);


        $stmt->execute();   

        return $stmt;   
    }
    catch(PDOException $e)
    {
        echo $e->getMessage();
    }               
}

0 个答案:

没有答案