簡體   English   中英

簡單的HTML表單不會為MySQL表增加價值

[英]Simple HTML form not adding value into MySQL table

下面的表格沒有在MySQL表“比賽”的第四個字段中添加點。

我找不到任何錯誤的代碼。 我是否缺少明顯的東西?

echo '<form action="http://www.website.com/folder/file.php" method="post"> 
    <input type="hidden" value="'.$u.'" name="u"> 
    <input type="hidden" value="'.$profile.'" name="profile"> 
    <input type="hidden" value="'.$profileid.'" name="profileid"> 




    <div class="friend2title"><label for="url">Add points:</label></div> 
    <div class="friend2field"><input name="state" type="text" id="state" maxlength="150"></div>




    <div class="addresssubmit"><input name="submit" type="submit" value="Add"></div> 
</form>
';

然后,在http://www.website.com/folder/file.php上

$u = $_POST['u'];
$profile = $_POST['profile'];
$profileid = $_POST['profileid'];

$state = $_POST['state'];





$state = mysql_real_escape_string($state);



mysql_query("INSERT INTO contest VALUES (NULL, 'critic', '$profileid',  '$state', NULL')");

您必須在狀態輸入中聲明具有默認值的value屬性

<input name="state" type="text" id="state" value="' . $state . '" maxlength="150">

另外,您的代碼容易受到SQL注入的攻擊,永遠不要信任來自用戶的字段,這對您的數據庫非常危險。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM