> For the complete documentation index, see [llms.txt](https://docs.layraweb.com.tr/merhaba/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.layraweb.com.tr/merhaba/php-tarafi/konular/veritabani-islemleri/veri-guncelleme.md).

# Veri Güncelleme

PHP'de veri güncelleme işlemi, var olan verileri güncellemek ve güncellenmiş verileri veritabanına kaydetmek için kullanılır. Veri güncelleme işlemi, öncelikle veritabanına bağlanmak ve verileri almakla başlar.

Veritabanına bağlanmak için öncelikle mysqli\_connect() fonksiyonu kullanılır. Bu fonksiyonun kullanımı aşağıdaki gibidir:

```perl
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

$conn = mysqli_connect($servername, $username, $password, $dbname);
if (!$conn) {
  die("Connection failed: " . mysqli_connect_error());
}
```

Bu örnekte, `mysqli_connect()` fonksiyonu kullanarak `localhost` sunucusuna ve `myDB` veritabanına bağlanılıyor.

Veri güncelleme işlemi için kullanılacak en temel SQL sorgusu `UPDATE` sorgusudur. Bu sorgu, güncelleme işlemini gerçekleştirmek için kullanılır. Sorgu aşağıdaki gibidir:

```sql
UPDATE table_name SET column1=value1,column2=value2,... WHERE some_column=some_value
```

Bu sorguda, `table_name` değişkeni güncellenecek tabloyu, `column1=value1,column2=value2` değişkeni güncellenen sütunları ve değerleri, `WHERE` deyimi ise hangi kaydın güncelleneceğini belirtir.

Aşağıdaki örnekte, `users` tablosunda bulunan `email` sütununda yer alan `johndoe@example.com` değerini `janedoe@example.com` ile değiştireceğiz:

```bash
$sql = "UPDATE users SET email='janedoe@example.com' WHERE email='johndoe@example.com'";

if (mysqli_query($conn, $sql)) {
  echo "Record updated successfully";
} else {
  echo "Error updating record: " . mysqli_error($conn);
}
```

Bu örnekte, `mysqli_query()` fonksiyonu kullanılarak SQL sorgusu çalıştırılır. Ardından, sorgunun başarılı bir şekilde çalıştırıldığı veya bir hata olduğu kontrol edilir.

Veri güncelleme işleminde `WHERE` deyimine dikkat edilmelidir. Eğer `WHERE` deyimi belirtilmezse, tüm kayıtlar güncellenir.

Ayrıca, SQL enjeksiyon saldırılarına karşı koruma için hazırlıklı olunmalıdır. Güncelleme işlemi için kullanıcı girdileri temizlenmeli ve SQL enjeksiyon saldırılarına karşı korumalıdır.

Veritabanı bağlantısı sonlandırıldıktan sonra `mysqli_close()` fonksiyonu kullanılarak bağlantı sonlandırılabilir:

```scss
mysqli_close($conn);
```

Bu şekilde veri güncelleme işlemi PHP'de gerçekleştirilebilir.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.layraweb.com.tr/merhaba/php-tarafi/konular/veritabani-islemleri/veri-guncelleme.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
