简体   繁体   中英

Update MySQL using HTML Form input and php

I have MYSQL incoming data in HTML form inputs at page opening. When I press the update button after changing the information, the update operation is successful, but the data is not updated.

<?php


$servername = "";
$username = "";
$password = "";
$dbname = "";

$baglan = mysqli_connect($servername,$username,$password,$dbname) or die(myslqi_error());


$place = $_POST['n_place'];
$description = $_POST['n_description'];
$latitude = $_POST['lat'];
$longitude = $_POST['long'];
$kayitliyer = $_POST['search_new_places'];
$yetkiliad = $_POST['n_yetkiliad'];
$magazaad = $_POST['n_magazaad'];
$telefon = $_POST['n_telefon'];
$yetkilitelefon = $_POST['y_telefon'];
$derece = $_POST['derece'];
$country = $_POST['country'];


$sql =  "UPDATE tbl_places SET place='$place',description='$description',lat='$latitude', lng='$longitude', kayitliyer='$kayitliyer',
yekiliad='$yetkiliad', magazaad='$magazaad', telefon='$telefon', yetkilitelefon='$yetkilitelefon', derece='$derece' WHERE place_id='$gID' ";



if (mysqli_query($baglan,$sql)) {
  echo '<br/><div class="container"><div class="alert alert-success" role="alert">
              Kayıt Güncelleme <b>Başarılı :-)</b> <a href=javascript:history.back(-1)>Geri Dön</a>
             </div></div> ';
}else {
  echo '<br/><div class="container"><div class="alert alert-danger" role="alert">
              Güncelleme İşlemi <b>Başarız!</b> <a href=javascript:history.back(-1)>Geri Dön</a>
             </div></div>'. mysqli_error($baglan);
}



?>

HTML Page Form SELECT Query.Thanks for your reply. I get the value of "$ gID" from the HTML form page, where I entered the DB data with a SELECT query.UPDATE

  <?php
 //UPDATE ID
   $gID = $_GET["place_id"];

   include ("baglanti.php");

 $sorgu = mysqli_query($baglan,"select * from tbl_places where place_id='$gID'");


  while($goster = mysqli_fetch_array($sorgu)){
  $grupadi = $goster["place"];
  $id = $goster["place_id"];
  $desc = $goster["description"];
  $adres = $goster["kayitliyer"];
  $yetkiliad = $goster["yekiliad"];
  $magazaad = $goster["magazaad"];
  $telefon = $goster["telefon"];
  $yetkilitelefon = $goster["yetkilitelefon"];
  $derece = $goster["derece"];
  $country = $goster["country"];
  $lat =$goster["lat"];
  $long = $goster["lng"];
  }
 ?>
<!DOCTYPE html>
<html lang="tr">
<head>

You should be using PDO for this, for security and code cleaniness. Apart from that, and without more info on where $gID comes from, I'd try removing the single quotes around the value it's compared to, since it probably is an integer and not a string:

$sql =  "... WHERE place_id=$gID";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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