2012-02-23 10 views
1

削除する "送信"ボタンを設定することはできません。そうでないと、コードのどの部分が間違っているのかわかりません。送信ボタンは設定されません

値を格納するhidden入力を使用し、TDの

// While it goes through each row (which is selected from another SQL query above, but I won't bother pasting that) 
while ($row = mysql_fetch_array($result)) { 
// Variable is equal to the Request ID (e.g. 10) 
$numb = $row['ReqID']; 

// Echo's the table td rows with each column name in the database 
echo "<tr>"; 
echo "<td class='req' align='center'>".$row['ReqID']."</td>"; 
echo "<td class='req' align='center'>".$row['ModTitle']."</td>"; 
echo "<td class='req' align='center'>".$row['BuildingID']."</td>"; 
echo "<td class='req' align='center'>".$row['RoomID']."</td>"; 
echo "<td class='req' align='center'>".$row['Priority']."</td>"; 
echo "<td class='req' align='center'>".$row['W1']."</td>"; 
echo "<td class='req' align='center'>".$row['P1']."</td>"; 
// Delete button also in a td row, uses the variable "$numb" to set the button name 
echo "<td class='req' align='center'><input type='submit' name='{$numb}' value='Delete'></td>"; 
echo "</tr>"; 

// If the delete button is pressed, delete the row (this query works, we tested it, but the button just doesn't set so it doesn't activate the SQL command) 
if (isset($_POST[$numb])) { 
$result2 = mysql_query("DELETE FROM Request WHERE ReqID = {$numb} LIMIT 1", $connection); 
} 
} 
+1

なぜ{}で$ numbを折り返していますか? –

+2

私は全体が '

'タグを囲んでいると思いますよね? – papaiatis

+0

あなたの質問には関係ありませんが、そのコードは削除された行を表示します...それは意図した動作ですか? – bfavaretto

答えて

1

にデータベースからのデータが含まれているいくつかの列とテーブルの行を想像:

どこか

...上
<form method="post" action="delete.php"> 

少し下...

echo "<td class='req' align='center'><input type='submit' name='submit' value='Delete'>"; 
echo '<input name="hello" type="hidden" value="$numb" /></td>'; 
... 
$number = mysql_real_escape_string($_POST["hello"]); 
$result2 = mysql_query("DELETE FROM Request WHERE ReqID = ".$number." LIMIT 1", $connection); 

下部にある:

</form> 

注:

あなたのアプローチは十分に安全ではありません。私は簡単にDOMを編集し、隠しフィールド(またはボタンの別の名前)に別の値を与えて、データベースから他の要素を削除することができます。これを覚えておいてください。

+0

... ''を' echo'するつもりでしたか? –

+0

ええ、ちょうど私のコードを更新しましたが、どちらか良くはありません。それがIDだけの場合は、データベースから他のものを削除することもできます...アプローチそのものは、私が彼に留意して悪いものです。 – papaiatis

+0

良い点。 +1しました –

関連する問題