我尝试使用表单中的信息更新表格。我有一个在同一个数据库中的表的不同文件中工作。我的版本不会将数据输入表中。我觉得我已经正确地编辑/复制了它,我非常喜欢菜鸟,觉得可能有一个明显的答案,但我无法看到它。我检查过类似的问题,但没有运气。
<?php include "connect.php";?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content= "text/html; charset=UTF-8"/>
<title>Blooming Flowers - Registration</title>
<link rel="stylesheet" href="css/style.css" type="text/css">
</head>
<?php include "header.php"; ?>
<?php include "form.php"; ?>
<body>
<?php include "processform.php" ; ?>
</td>
</tr></table>
<?php include "footer.php"; ?>
</body>
我可以将问题缩小到我的form.php文件或processform.php文件,但不确定他们为什么不工作
form.php的
<td>
<div class="form">
<form action = "<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<fieldset>
<h3>Personal Details</h3><br>
<label>Title:
<select name="titles">
<option value="mr">Mr.</option>
<option value="mrs">Mrs.</option>
<option value="ms">Ms.</option>
<option value="Dr">Dr.</option>
</select></label>
<p>
<label for="firstName"> First Name:</label>
<input type="text" name="user_first" id="user_first" size="40" maxlength="60" required/>
</p>
<p>
<label for="lastName">Last Name:</label>
<input type="text" name="user_last" id="user_last" size="40" maxlength="60" required/>
</p>
<p>
<label for="password"> Password:</label>
<input type="password" name="user_pass" id="user_pass" size="40" maxlength="60" required/>
</p>
<p>
<label for="confirmPass"> Confirm Password:</label>
<input type="password" name="" id="" size="40" maxlength="60" required/>
</p>
</fieldset><!--name fieldset closed-->
<fieldset>
<h3> Delivery Details</h3><br>
<p>
<label for="streetAddress"> Street:</label>
<input type="text" name="user_street" id="user_street" size="40" maxlength="60" required/>
</p>
<p>
<label for="city"> City:</label>
<input type="text" name="user_city" id="user_city" size="40" maxlength="60" required/>
</p>
<p>
<label for="postcode"> Postcode:</label>
<input type="text" name="user_post" id="user_post" size="40" maxlength="60" required/>
</p>
<p>
<label for="email"> E-Mail:</label>
<input type="email" name="user_email" id="user_email" size="40" maxlength="60" required/>
</p>
<p>
<label for="confirmEmail"> Confirm E-Mail:</label>
<input type="email" name="" id="" size="40" maxlength="60" required/>
</p>
</fieldset><!-- fieldset closed-->
<br><input class="link-button-pagemenu" name="submit" type="submit" value="Register">
</form><!--form closed-->
</div><!-- form div closed-->
processform.php
<?php
if (isset($_POST['submit'])){
$user_first= '';
$user_last = '';
$user_pass = '';
$user_street = '';
$user_city = '';
$user_post = '';
$user_email = '';
if (!empty($_POST['user_first'])){
$user_first = $_POST['user_first'];
}
if (!empty($_POST['user_last'])){
$user_last = $_POST['user_last'];
}
if (!empty($_POST['user_pass'])){
$user_pass = $_POST['user_pass'];
}
if (!empty($_POST['user_street'])){
$user_street = $_POST['user_street'];
}
if (!empty($_POST['user_city'])){
$user_city = $_POST['user_city'];
}
if (!empty($_POST['post'])){
$user_post = $_POST['user_post'];
}
if (!empty($_POST['user_email'])){
$user_email = $_POST['user_email'];
}
$query = "insert into flower (user_first, user_last, user_pass, user_street, user_city, user_post, user_email)
values('$user_first', '$user_last', '$user_pass', '$user_street', '$user_city', '$user_post', '$user_email')";
mysqli_query($connect, $query);
}
?>
我的数据库表名为flower并且有 userID(PK), user_first, user_last, user_pass, user_street, user_city, user_post, USER_EMAIL,
答案 0 :(得分:3)
您基本上没有将数据发布到processform.php
文件。在您的操作中使用<?php echo $_SERVER['PHP_SELF']; ?>
会使网页发布到自身,这意味着,它会发布到您的form.php
文件,而不是processform.php
。
更改您的表单操作以使用processform.php
,然后您应该点击查询并将数据导入数据库。
也许你可以去这里看一下全局php变量:
希望这可以帮到你:)