简体   繁体   English

如何使用 PHP 和 MySQL 向服务器发送数据

[英]How to send data to server using PHP and MySQL

Here is my edit page code and the moment user clicks on edit he will be redirected to this page and its still working but after editing content when I click on update button nothing is happening even though it was perfectly working before and now I have tried everything but this button is not updating my data and not even responding at all:这是我的编辑页面代码,当用户单击编辑时,他将被重定向到此页面并且它仍然可以工作,但是在我单击更新按钮编辑内容之后,即使它之前完美工作,也没有发生任何事情,现在我已经尝试了一切但是这个按钮没有更新我的数据,甚至根本没有响应:

<?php

$eid = $_GET['id'];

$con = mysqli_connect("localhost","root","","news") or die("Connection Failed!");
$sql = "SELECT * From content where pid = {$eid}";
$result = mysqli_query($con, $sql) or die("Query Failed!");

$t = mysqli_fetch_assoc($result);

?>

<html>
  <head>
    <title>Edit</title>
  </head>
  <link rel="stylesheet" href="bootstrap\css\bootstrap.min.css">
<body>

<!-- PHP: Sending updated data to server -->
<?php
$article = '';
if(isset($_POST['button'])){
  $article = isset($_POST['edit-box']) ? $_POST['edit-box'] : ''; //here you will get value of textarea

  $sql1 = "UPDATE content SET article = '{$article}' WHERE pid = $eid";
  $result1 = mysqli_query($con, $sql1);

    if($result1){
      header('Location: http://localhost/preply/news-site');
    }else{
      echo "Query Failed!";
    }
}
?>

<!-- HTML -->
<div class="container mt-2">
  <h1><?php echo $t['title'] ?></h1>
  <textarea type="text" name="edit-box" id="edit-box" class="w-75 p-3 mt-3 h-75">
      <?php echo $t['article'] ?>
  </textarea>
  <button name="button" class="btn btn-primary mb-4">Update</button>
</div>

</body>
</html>

The problem here is I am not adding my button inside form so that why it is not working I edited this in following way and now its perfectly working:这里的问题是我没有在表单中添加我的按钮,所以为什么它不工作我以以下方式编辑它,现在它完美工作:

<!-- HTML -->
<form method="POST" action="">
  <div class="container mt-2">
      <h1><?php echo $t['title'] ?></h1>
      <textarea type="text" name="edit-box" id="edit-box" class="w-75 p-3 mt-3 h-75">
          <?php echo $t['article'] ?>
      </textarea>
      <!-- <button name="button" class="btn btn-primary mb-4">Update</button> -->
      <input type="submit" name="button" class="btn btn-primary mb-4" value="Update">
    </div>
</form>

change update button ---更改更新按钮 ---

<input type="submit" name="button" class="btn btn-primary mb-4" value="Update">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM