I can update name but how do I update lastname from the input statement below?
I have multiple row in mysql table
need help with the code
Please HELP!!! Thanks alot in advance
I have multiple row in mysql table
need help with the code
Please HELP!!! Thanks alot in advance
VB.NET:
<?php
$host = "localhost"; // Host name
$username = "username"; // Mysql username
$password = ""; // Mysql password
$db_name = "test"; // Database name
$tbl_name = "test_mysql"; // Table name
// Connect to server and select databse.
$db = new PDO('mysql:host=' . $host . ';dbname=' . $db_name, $username, $password);
// If there is an update, process it.
if (isset($_POST['submit'], $_POST['name']) && is_array($_POST['name'])) {
$stmt = $db->prepare("UPDATE `$tbl_name` SET `name`=:name WHERE id=:id");
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
$stmt->bindParam(':name', $name, PDO::PARAM_STR);
foreach ($_POST['name'] as $id => $name) {
$stmt->execute();
}
echo '<h1>Updated the records.</h1>';
}
// Print the form.
echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF']) . '" method="post">';
foreach ($db->query("SELECT `id`, `name`, `lastname` FROM `$tbl_name` ORDER BY `name`") as $row) {
echo '<input type="text" name="name[' . (int)$row['id'] . ']" value="'
. htmlspecialchars($row['name']) . '" /><input type="text" lastname="lastname[' . (int)$row['id'] . ']" value="'
. htmlspecialchars($row['lastname']) . '" /><br />';;
}
echo '<input type="submit" name="submit" value="Update" /></form>';
?>