I am trying to make a registration page with around 10 details. But in no way am I able to update the database with those details. I have followed every procedure i found on every site including * but still whenever i submit my form nothing happens. Like when i press the submit button it goes to another page and the address bar shows everything correctly but yet i don't know why there is no change in the database. I am new to JSP and Netbeans, so i am not really aware of all the things. I used this as my guide http://www.studytonight.com/servlet/registration-form-example-in-servlet.php P.S. I am new to JSP and netbeans, so i am not aware of a lot of things. Thanks in advance.
我正在尝试制作一个包含大约10个细节的注册页面。但我绝不能用这些细节更新数据库。我已经按照我在每个网站上找到的每个程序,包括*,但是每当我提交表单时,都没有任何反应。就像当我按下提交按钮时,它会转到另一个页面,地址栏会正确显示所有内容,但我不知道为什么数据库中没有任何更改。我是JSP和Netbeans的新手,所以我并不是真的了解所有的事情。我用这个作为我的向导http://www.studytonight.com/servlet/registration-form-example-in-servlet.php P.S.我是JSP和netbeans的新手,所以我不知道很多东西。提前致谢。
1 个解决方案
#1
-1
First Create a class like this
首先创建一个这样的类
class DBController {
private $host = "Your IP";
private $user = "User Name";
private $password = "Password";
private $database = "Your Database";
function connectDB() {
$conn = mysql_connect($this->host,$this->user,$this->password);
return $conn;
}
function insertQuery($query) {
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
} else {
return $result;
}
}
}
?>
Create a text box
创建一个文本框
<input type="text" class="" name="patfirstname" value="<?php if(isset($_POST['patfirstname'])) echo $_POST['patfirstname']; ?>">
And a submit button
并提交按钮
<input type="submit" name="submit" value="Submit" />
And in the same registration form create a post PHP function
并在相同的注册表单中创建一个后PHP函数
<?php
if(isset($_POST['submit'])== "POST")
{
require_once("dbcontroller.php");
$db_handle = new DBController();
$query = "INSERT INTO new_table ( Name ) VALUES ( '" . $_POST["patfirstname"] . "');";
$result = $db_handle->insertQuery($query);
}
?>
Hope this helps..
希望这可以帮助..
#1
-1
First Create a class like this
首先创建一个这样的类
class DBController {
private $host = "Your IP";
private $user = "User Name";
private $password = "Password";
private $database = "Your Database";
function connectDB() {
$conn = mysql_connect($this->host,$this->user,$this->password);
return $conn;
}
function insertQuery($query) {
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
} else {
return $result;
}
}
}
?>
Create a text box
创建一个文本框
<input type="text" class="" name="patfirstname" value="<?php if(isset($_POST['patfirstname'])) echo $_POST['patfirstname']; ?>">
And a submit button
并提交按钮
<input type="submit" name="submit" value="Submit" />
And in the same registration form create a post PHP function
并在相同的注册表单中创建一个后PHP函数
<?php
if(isset($_POST['submit'])== "POST")
{
require_once("dbcontroller.php");
$db_handle = new DBController();
$query = "INSERT INTO new_table ( Name ) VALUES ( '" . $_POST["patfirstname"] . "');";
$result = $db_handle->insertQuery($query);
}
?>
Hope this helps..
希望这可以帮助..