这是获取输入的表单。当我按提交按钮页面只是重新加载,没有错误或成功消息。表中也没有插入数据。我的代码有什么问题吗?
<?php
require_once 'classes/user.php';
$obj_user = new User();
if (isset($_POST['reg-btn'])) {
$message = $obj_user->save_user($_POST);
}
?>
<div class="col-md-8">
<h3 class="text-info text-center"><u>এখানে নিবন্ধন করুন</u></h3>
<?php if (isset($message)) {
echo $message;
unset($message);
} ?>
<hr/>
<form class="form-horizontal" role="form" action="" method="post">
<div class="form-group">
<label class="control-label col-md-3" for="first_name">নামের প্রথম অংশ</label>
<div class="col-md-9">
<input type="text" name="first_name" id="first_name" class="form-control">
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3" for="last_name">নামের শেষ অংশ</label>
<div class="col-md-9">
<input type="text" name="last_name" id="last_name" class="form-control">
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3" for="email_address">ইমেইল ঠিকানা</label>
<div class="col-md-9">
<input type="email" name="email_address" id="email" class="form-control">
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3" for="user_name">ইউসারনেম</label>
<div class="col-md-9">
<input type="text" name="user_name" id="last_name" class="form-control">
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3" for="password">পাসওয়ার্ড</label>
<div class="col-md-9">
<input type="password" name="password" id="password" class="form-control">
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3" for="address">ঠিকানা</label>
<div class="col-md-9">
<textarea class="form-control" name="address" id="address"></textarea>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3" for="city">শহর</label>
<div class="col-md-9">
<input type="text" name="city" id="city" class="form-control">
</div>
</div>
<div class="form-group">
<div class="col-md-offset-3 col-md-9">
<input type="submit" name="reg_btn" class="btn btn-success btn-block" value="নিবন্ধন সম্পন্ন">
</div>
</div>
</form>
</div>
这是用户类。我检查了连接,没关系。
<?php
require_once 'db_connect.php';
class User {
private $pdo;
public function __construct() {
$obj_db = new Db_connect();
$this->pdo = $obj_db->pdo;
}
public function save_user($data) {
try {
$query = "INSERT INTO tbl_user(first_name, last_name, email_address, user_name, password, address, city) VALUES(:first_name, :last_name, :email_address, :user_name, :password, :address, :city)";
$stmt = $this->pdo->prepare($query);
$stmt->bindParam(':first_name', $data['first_name'], PDO::PARAM_STR);
$stmt->bindParam(':last_name', $data['last_name'], PDO::PARAM_STR);
$stmt->bindParam(':email_address', $data['email_address'], PDO::PARAM_STR);
$stmt->bindParam(':user_name', $data['user_name'], PDO::PARAM_STR);
$stmt->bindParam(':password', $data['password'], PDO::PARAM_STR);
$stmt->bindParam(':address', $data['address'], PDO::PARAM_STR);
$stmt->bindParam(':city', $data['city'], PDO::PARAM_STR);
$stmt->execute();
$message = "আপনি সফলভাবে নিবন্ধন করেছেন";
return $message;
} catch (PDOException $e) {
echo $e->getMessage();
}
}
}
答案 0 :(得分:0)
您的提交按钮名称为reg_btn
,而您正在查看isset($_POST['reg-btn'])
替换它:
isset($_POST['reg-btn'])
使用:
isset($_POST['reg_btn'])
答案 1 :(得分:0)
Private Sub killProcess()
Dim processWhitelist() As string = {"calc", "notepad", "explorer"}
Dim pathWhitelist() As String = {"C:\Users\G83394\Desktop\Personal", "C:\Program Files", "C:\Windows\System32", "C:"}
For Each proc In Process.GetProcesses
Try
For Each path As String In pathWhitelist
If proc.mainmodule.filename.contains(path) Then
For Each p In processWhitelist
If proc.processname.contains(p) Then
MsgBox(proc.processname & " is found in whitelist.")
end if
Next
Else
MsgBox(proc.processname & " is NOT found in whitelist.")
End If
Next
Catch ex As Exception
End Try
Next
end sub
永远不会触发,因为if (isset($_POST['reg-btn'])) {
未设置。
当怀疑为什么某些东西没有开始尝试取出条件或给它$_POST['reg-btn']
选项以查看它属于哪种情况时。从那里,您可以使用else
查看发送的值等等。
所以在这段代码中你可以做到:
var_dump
这会向您显示名称中包含if (isset($_POST['reg-btn'])) {
$message = $obj_user->save_user($_POST);
} else {
var_dump($_POST);
}
而不是_
。或
-
这将允许您的表单处理,因此您知道//if (isset($_POST['reg-btn'])) {
$message = $obj_user->save_user($_POST);
//}
由于某种原因没有处理。评论出来的路线有点长。