嘿傢伙我以前有類似的問題,但我颳了這個主意。現在基本上我的系統允許我的用戶在那裏輸入數據到數據庫中,如果他們提交數據,數據就會存入數據庫。現在出於某種原因,數據不會去,我與我存儲在我的else語句中的回聲,這是「回聲」稍後再試「;」將值插入數據庫不起作用?
現在我已回到數據庫中,並查看所有文件和有正確的名稱,並將它們放入查詢中,但沒有任何內容存入數據庫。現在你可能會想,在我的代碼中,上面的文件connect.inc.php是什麼,它基本上是一個連接到服務器的php腳本。
這裏是我的代碼的請求看看謝謝:)
<?php
//require 'core.inc.php';
include 'connect.inc.php';
if(isset($_POST['Username'])&& isset($_POST['Password']) && isset($_POST['PasswordAgain'])&& isset($_POST['Firstname'])&& isset($_POST['Lastname'])){
$username = $_POST['Username'];
$password = $_POST['Password'];
$password_again = $_POST['PasswordAgain'];
$Firstname = $_POST['Firstname'];
$password_hash = md5($password);
$Lastname = $_POST['Lastname'];
if(!empty($username)&& !empty($password) && !empty($password_again) && !empty($Firstname) && !empty($Lastname)){
if ($password !== $password_again) {
echo "passwords do not match";
}
else{
$query = "SELECT username FROM members WHERE username = '$username'";
$query_run = mysql_query($query);
if(mysql_num_rows($query_run)==1){
echo "The username ". $username ." is taken";
}else{
$query = "INSERT INTO members VALUES ('','Firstname','Lastname','Username','Password')";
if ($query_run = mysql_query($query)){
echo "Well done";
}else{
echo "Sorry we couldn't register at this time. Please try again later thank you";
}
}
}
}
else{
echo "Please fill in all the details thank you ";
}
}
?>
<form action="join.inc.php" method="post">
Username: <input type="text" name="Username" value="<?php echo $username; ?>" /><br />
Password: <input type="password" name="Password" /><br />
Password Again: <input type="password" name="PasswordAgain" /><br />
FirstName: <input type="text" name ="Firstname" value="<?php echo $Lastname; ?>" /><br />
LastName: <input type="text" name ="Lastname" value="<?php echo $Firstname ?>" /><br />
<input type="submit" value="SUBMIT" />
</form>
連接腳本
當您遇到此問題時,通常會將查詢字符串回顯到頁面。您不想在生產環境中這樣做,但在開發過程中,您可以快速查看要發送到數據庫的內容。 – 2012-03-14 05:58:36