PHP更新数据库mysqli表单

时间:2016-04-05 19:07:52

标签: php database forms mysqli html-table

我目前正在尝试编写一个系统,我可以将数据库中的可编辑字段添加到网页上,然后提交信息并更改数据库中的数据。

我已经在文本字段中显示了数据,但我似乎无法使更新功能正常工作......

<?php $mysqli = new mysqli('localhost', 'adwawdaw', 'awdawdaw', 'awdawdaw'); 
     $result = $mysqli->query('SELECT * FROM information WHERE id = 1');
        if (is_object($result)) {
            if ($result->num_rows) {
                while ($row = $result->fetch_assoc()) {
                    $banner = $row['banner'];
                    $embed = $row['embed'];
                    $title = $row['title'];
                    $date = $row['date'];
                    $time = $row['time'];
                    $description = $row['description'];
                    $region = $row['region'];
                    $sponsors = $row['sponsors'];
                }
            }
        }
    ?>

<form method="post" action="edit1.php">
<table>
<br />
<tr>
<td>Banner: </td>
<td><input type="text" name="banner" value="<?php echo htmlspecialchars($banner) ?>"></td>
</tr>
<tr>
<td>Embed: </td>
<td><input type="text" name="embed" value="<?php echo htmlspecialchars($embed) ?>"></td>
</tr>
<tr>
<td>Event Title: </td>
<td><input type="text" name="title" value="<?php echo htmlspecialchars($title) ?>"></td>
</tr>
<tr>
<td>Date: </td>
<td><input type="text" name="date" value="<?php echo htmlspecialchars($date) ?>"></td>
</tr>
<tr>
<td>Time: </td>
<td><input type="text" name="time" value="<?php echo htmlspecialchars($time) ?>"></td>
</tr>
<tr>
<td>Description: </td>
<td><input type="text" name="description" value="<?php echo htmlspecialchars($description) ?>"></td>
</tr>
<tr>
<td>Region: </td>
<td><input type="text" name="region" value="<?php echo htmlspecialchars($region) ?>"></td>
</tr>
<tr>
<td>Sponsors: </td>
<td><input type="text" name="sponsors" value="<?php echo htmlspecialchars($sponsors) ?>"></td>
</tr>
</table>
<input class="button" type="submit" value="Update!">
</form>
<?php 
$banner = $_POST['banner'];
$embed = $row['embed'];
$title = $_POST['title'];
$date = $row['date'];
$time = $row['time'];
$description = $row['description'];
$region = $row['region'];
$sponsors = $row['sponsors'];

$mysqli->query('UPDATE livestreamadmin SET title = $title WHERE id=1');
    ?>

0 个答案:

没有答案