2012-10-02 69 views
0

有人可以指出我的方法出錯了。在我的代碼中,我使用名稱'sendme'動態地獲得了一個提交按鈕,一旦出現'sendme'被觸發時,我想回顯消息。因爲我包括如果(isset($ _ POST ['sendme')){......代碼,但因爲它似乎不是有效的代碼。請指出我的理性在這種情況下應該如何改變。感謝您的期待!發出在PHP中動態創建的提交按鈕

<?php 
if(isset($_POST['sendone'])){ 

$Q = $_POST['txt5']; 
$con=mysql_connect('localhost','root') or die ("Server connection failure!"); 
$db=mysql_select_db('db_customer',$con) or die ("Couldn't connect the database"); 
$SQL="SELECT * FROM tbl_customer WHERE name='$Q'"; 
$run=mysql_query($SQL,$con) or die ("SQL Error"); 
$row=mysql_fetch_array($run); 

if($row=="") 
{ 
echo "No records found"; 
} 
else 
{ 
echo "<table border='1'>"; 
echo "<tr><td>"."Name :"."</td>"; 
echo "<td><input type='text' value=".$row['name'].">"."</td>"; 
echo "<td><input type='submit' id='sendme' name='sendme'></td>"; 
echo "</tr>"; 
echo "</table>"; 
} 
} 
else { 
    // here I'm trying to fire the populated submit button and echo cheers! 
if(isset($_POST['sendme'])){ 
echo 'Cheers!'; 
}} 
?> 

回答

1

您不創建表單。將<form action="nameofyourphpscript" method="POST">放在您的<input> s之上,將</form>放在其下面。