我有一個會談「process_register.php」註冊用戶的形式。該文件與一個名爲「user」的類進行對話。我不能讓PHP把信息到MySQL
<form method="post" action="process_register.php">
User Name: <input type="text" name="userName" maxlength="32"><br>
Password: <input type="password" name="userPassword" maxlength="32"><br>
<input type="submit">
</form>
process_register.php
<?php
// process_register.php
include('userclass.php');
$newUser = new User;
// Call the registerUser() method, passing in the required variables
$newUser->registerUser($userName, $userPassword);
// If it was an error, the class will kill the script, if not, it will reach this point
$newUser->displayUserInfo();
?>
userclass.php
<?
// process_register.php
class User {
var $userID,
$userName,
$userPassword,
$dbHost,
$dbUser,
$dbName,
$dbPass,
$dbUserTable;
function registerUser($userName, $userPassword) {
// Connect to database
$dbLink = mysql_connect($this->dbHost, $this->dbUser, $this->dbPass);
if(!$dbLink) die("Could not connect to database. " . mysql_error());
// Select database
mysql_select_db($this->dbName);
$query = "insert into $this->dbUserTable values (NULL, \"$userName\", \"$userPassword\")";
$result = mysql_query($query);
// Test to make sure query worked
if(!$result) die("Query didn't work. " . mysql_error());
// Get the user ID
$this->userID = mysql_insert_id();
// Close database connection
mysql_close($dbLink);
// Assign the values to the data members
$this->userName = $userName;
$this->userPassword = $userPassword;
} // End registerUser()
function displayUserInfo() {
echo '<b>User ID: </b>' . $this->userID . '<br>';
echo '<b>User Name: </b>' . $this->userName . '<br>';
echo '<b>User Password: </b>' . $this->userPassword . '<br>';
} // End displayUserInfo()
問題是,當process_register.php呼叫 'displayUserInfo' 它爲新用戶創建一個數據庫中的插槽,但它是空白的。
任何的幫助深表感謝
打開你的錯誤報告,看看有什麼東西顯示 – 2012-01-19 00:48:52
我不知道有錯誤報告:/ – user1082764 2012-01-19 00:58:33