我真的不知道這是怎麼回事,我一直在我的腦子裏花了兩個小時。我所要做的就是從表單中的兩個字段獲取信息並將其插入到數據庫中。我知道我的腳本非常基本,非常不安全,但我只是在學習......它不會在生產網站上使用。它讓我提交數據,並輸出「謝謝你,你已經註冊了...」,但它永遠不會將它插入到數據庫中。我已經加倍檢查了所有的連接設置等等。我很無能。在這個PHP腳本沒有錯誤,但沒有填寫SQL數據庫
我的代碼如下:
<?php
mysql_connect("localhost", "USERNAME", "PASSWORD") or die(mysql_error());
mysql_select_db("DATABASE_NAME") or die(mysql_error());
if (isset($_POST['submit'])) {
mysql_query("INSERT INTO members (username, password) VALUES ('".$_POST['myusername']."', '".$_POST['mypassword']."')") or die(mysql_error());
}
?>
<html>
<body>
<h1>Registered</h1>
<p>Thank you, you have registered - you may now login</a>.</p>
</body>
</html>
編輯:
這裏是表單代碼:
<table id="mytable" cellspacing="0">
<FORM name="form1" ACTION="register.php" METHOD=get>
<tr>
<th scope="col" class="ttopl">User Name:</th>
<th scope="col" class="ttopl"><input name="myusername" type="text" size"20"></input> </th>
</tr>
<tr>
<th scope="col" class="ttopl">Password:</th>
<th scope="col" class="ttopl"><input name="mypassword" type="text" size"20"></input> </hd>
</tr>
<tr>
<th scope="col" class="ttopl"></th>
<th scope="col" class="ttopl"><input type="submit" value="Register" class="loginButton">
裏面是否'如果(isset'在所有執行塊? (如果你不確定,試着在那裏添加'echo')並閱讀這樣的內容http://php.net/manual/en/security.database.sql-injection.php。 – Vyktor
你確定你有error_reporting轉到最大?刪除isset以進行調試 – mario
請發送您的表單代碼請 –