Hey all,

I need some help with Editing a Table in a Database using php/

Can someone point me in the right way to do this.

Thanks in advance, :)

Dani AI

Generated

: Editing a MySQL table from PHP is the usual CRUD flow β€” fetch the row, render an HTML form prefilled with safe values, validate and sanitize POSTed input, then run a parameterized UPDATE. 's php-datagrid is a quick drop-in CRUD UI if an off-the-shelf admin grid is acceptable; writing the flow below gives finer control over validation, security, and layout.

A minimal, safe pattern using PDO:

<?php
$pdo = new PDO('mysql:host=localhost;dbname=your_db;charset=utf8mb4', 'dbuser', 'dbpass', [
    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
    PDO::ATTR_EMULATE_PREPARES => false,
]);

// assume $id, $name, $email are validated/sanitized
$stmt = $pdo->prepare('UPDATE users SET name = :name, email = :email WHERE id = :id');
$stmt->execute([':name' => $name, ':email' => $email, ':id' => $id]);

if ($stmt->rowCount() > 0) {
    // success
} else {
    // no rows changed (same data or missing id)
}
?>

Notes and troubleshooting: always validate server-side (ids as integers, required fields present), escape form values with htmlspecialchars when re-displaying, use CSRF tokens for forms, and enable PDO exceptions to surface errors. For multi-step updates use transactions. Prepared statements avoid SQL injection β€” see the PHP manual on prepared statements for details: PDO prepared statements.

Recommended Answers

All 3 Replies

Okay Sweet thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.