【发布时间】:2018-06-15 23:35:58
【问题描述】:
你能帮我修复我的代码吗? 该网站只需添加数据、编辑和删除。但是,当我尝试填写字段并单击添加时,它会转到一个空白页面。这是我的代码:
<?php include('server.php'); ?>
<!DOCTYPE html>
<html>
<head>
<title>CRUD: CReate, Update, Delete PHP MySQL</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<form method="post" action="server.php" >
<div class="input-group">
<label>Name</label>
<input type="text" name="name" value="">
</div>
<div class="input-group">
<label>Address</label>
<input type="text" name="address" value="">
</div>
<div class="input-group">
<button class="btn" type="submit" name="save" >Save</button>
</div>
</form>
<?php $results = mysqli_query($db, "SELECT * FROM info"); ?>
<table>
<thead>
<tr>
<th>Name</th>
<th>Address</th>
<th colspan="2">Action</th>
</tr>
</thead>
<?php while ($row = mysqli_fetch_array($results)) { ?>
<tr>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['address']; ?></td>
<td>
<a href="index.php?edit=<?php echo $row['id']; ?>" class="edit_btn" >Edit</a>
</td>
<td>
<a href="server.php?del=<?php echo $row['id']; ?>" class="del_btn">Delete</a>
</td>
</tr>
<?php } ?>
</table>
</body>
</html>
这是 php 代码。
<?php
$name = "";
$address = "";
$id = "";
$update = false;
mysql_connect("localhost", "user", "password");
$db = mysql_select_db("crud");
if (isset($_POST['save'])) {
$name = $_POST['name'];
$address = $_POST['address'];
mysqli_query($db, "INSERT INTO info (name, address) VALUES ('$name', '$address')");
$_SESSION['message'] = "Address saved";
header('location: index.php');
}
$results = mysqli_query($db, "SELECT * FROM info");
?>
当我点击保存按钮时,它完全是空白的。对不起我的英语不好。请帮我解决一下这个。提前谢谢你。
【问题讨论】:
-
我不明白,一旦你使用
mysql_connect和其他你使用mysqli_query。 -
您的表格状态是否发生了变化?任何行添加/删除?
-
我已经尝试使用 $db = mysqli_connect('localhost', 'user', password'', 'crud');但仍然得到相同的结果:(
-
嗨 Shahlin,没有添加任何行。
标签: php html sql phpmyadmin web