Mysqli Update语句没有更新数据库没有错误

时间:2017-02-27 03:22:21

标签: php html ajax

我尝试了不同的方法/语句方法来使这个更新语句起作用,但我不知道发生了什么......数据库没有得到更新,也没有出现错误。什么都没发生。有些事情是错的。

//editDetails
if(isset($_POST['editDetails'])){

//bind parameters
$updatecompany = $db->prepare("UPDATE company SET `title`=?, `description`=?, `address`=?, `type`=?, `country`=?, `timezone`=? WHERE `id`=?");
$updatecompany->bind_param('ssssss',$_POST['title'],$_POST['type'],$_POST['description'],$_POST['address'],$_POST['country'],$_POST['timezone']);
$updatecompany->execute();

    // set parameters and execute
    $companyid = mysqli_real_escape_string($db, $_POST["id"]);
    $title = mysqli_real_escape_string($db, $_POST["title"]);
    $type = mysqli_real_escape_string($db, $_POST["type"]);
    $description = mysqli_real_escape_string($db, $_POST["description"]);
    $address = mysqli_real_escape_string($db, $_POST["address"]);
    $country = mysqli_real_escape_string($db, $_POST["country"]);
    $timezone = mysqli_real_escape_string($db, $_POST["timezone"]);

if($updatecompany){
 // echo "Data Submitted succesfully";
  header('Location: ' . $_SERVER['HTTP_REFERER']);
exit;
  }
$updatecompany->close();
$db->close();
}

修改

//editDetails
if(isset($_POST['editDetails'])){

//bind parameters
$updatecompany = $db->prepare("UPDATE company SET `title`=?, `description`=?, `address`=?, `type`=?, `country`=?, `timezone`=? WHERE `id`=?");
$updatecompany->bind_param('ssssssi',$_POST['title'],$_POST['description'],$_POST['address'],$_POST['type'],$_POST['country'],$_POST['timezone'],$_POST['id']);
$updatecompany->execute();

    // set parameters and execute
    $companyid = $_POST["id"];
    $title = $_POST["title"];
    $type = $_POST["type"];
    $description = $_POST["description"];
    $address = $_POST["address"];
    $country = $_POST["country"];
    $timezone = $_POST["timezone"];

if($updatecompany){
 // echo "Data Submitted succesfully";
  header('Location: ' . $_SERVER['HTTP_REFERER']);
exit;
  }
$updatecompany->close();
$db->close();
}

form.php的

 <form id="editDetails" method="POST" action="core/query.php">
<table>
<thead></thead>
 <tbody>
 <?php while($company=mysqli_fetch_array($result)){ ?>
  <tr>
      <td data-th="Name"><?=$company['title'];?></td>
    <td data-th="Description"><?=$company['description'];?></td>
    <td data-th="Type"><?=$company['type'];?></td>
    <td data-th="Address"><?=$company['address'];?></td>
    <td data-th="Country"><?=$company['country'];?></td>
    <td data-th="Time Zone"><?=$company['timezone'];?></td>
    <td data-th="ID" sorttable_customkey="2"><button id='editCompanyDetails'  class='btn btn-default btn-sm' type='button'  name='companyDetails' data-toggle="modal"data-target="#myModal2" title='Edit details'>
     <i class="fa fa-pencil-square-o" aria-hidden="true"></i></button></td>
<input name="companyid" type="hidden" type="hidden" class="formBlock btn btn-success"  value="<?=$company['id'];?>"/>
  </tr>
    <?php };?>
 </tbody>
<tfoot></tfoot>
</table>

<!-- Modal -->
<div id="myModal2" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
<div class="modal-header">
</div>
<div class="modal-body">
<input id='title' class='form-control formBlock' name='title' value='' type='text' placeholder="Name...">
 <select id='type' class='form-control formBlock' name='type'></select>
 <select id='type' class='form-control formBlock' name='description'></select>
 <input id='address' class='form-control formBlock' name='address' value='' type='text' placeholder="Address">
<select name="country"  id='country' class='form-control formBlock' name='country' value='' type='text' placeholder="Country"></select>
  <select id='timezone' class='form-control formBlock' name="timezone"></select>
<input name="editDetails" id="submit" type="submit" class="formBlock btn btn-success"  value="Modify Data"/>
</div>
</div>
</div>

</form>

1 个答案:

答案 0 :(得分:0)

感谢大家的帮助。我得到了查询以使用以下代码。

//editDetails
if(isset($_POST['editDetails'])){

    // set parameters and execute
    $companyid = $_POST["companyid"];
    $title = $_POST["title"];
    $type = $_POST["type"];
    $description = $_POST["description"];
    $address = $_POST["address"];
    $country = $_POST["country"];
    $timezone = $_POST["timezone"];

    $updatecompany = "UPDATE company SET title = '$title', type='$type', description='$description', address='$address', country='$country', timezone='$timezone' WHERE id='$companyid'";
    mysqli_select_db($db, 'mydb');
    $resultq = mysqli_query($db, $updatecompany);

if(! $resultq ){
 die('Could not update data: ' . mysqli_error($db));
}
$db->close();
  header('Location: ' . $_SERVER['HTTP_REFERER']);
exit;
  }