2012-03-24 24 views
1

私のPHPアプリケーションでは、ページを更新せずにdivに検索結果を表示するためにAJAXを使用しています。AJAXを使用してPHPでinput type = "image"が機能しない

はここ..今ここに私search_profile.php

<?php 
session_start(); 
ob_start(); 
include('connection.php'); 
$query_religion="SELECT DISTINCT religion FROM religion_caste_table"; 
$result_religion = mysql_query($query_religion, $con); 
?> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
<title>Untitled Document</title> 
<script type="text/javascript" src="AJAX/religion_caste.js"></script> 
</head> 

<body> 
<div id="search"> 
<table width="650px" border="0" cellspacing="0" cellpadding="0" align="center"> 
<tr> 
<td width="460px"> 
<div id="search_box"> 
    <h2>Search With Filter</h2> 
    <form method="post" action="javascript:search_profile(document.getElementById('search_form'));" 
     id="search_form" name="search_form"> 
    <table cellpadding="0" width="460px" cellspacing="0" border="0" align="center"> 
      <tr> 
      <td width="11px" height="5"/> 
      <td width="100px"/> 
      <td width="11px"/> 
      <td width="100px"/> 
      <td width="11px"/> 
      <td width="100px"/> 
      <td width="11px"/> 
      <td width="100px"/> 
      <td width="12px"/> 
      </tr> 

      <tr> 
      <td align="center" width="11px"/> 
      <td align="center" width="100px"> 
      <label for="search">&nbsp Searching:</label> 
      </td> 
      <td align="center" width="11px"/> 
      <td align="center" colspan="5" width="322" bgcolor=""> 
       <select name="search_gender" id="search_gender" style="width:322px;"> 
        <option value="Female">Bride</option> 
        <option value="Male">Groom</option> 
       </select> 
      </td> 
      <td align="center" width="12"/> 
      </tr> 

      <tr> 
      <td width="11px" height="5px"/> 
      <td width="100px"/> 
      <td width="11px"/> 
      <td width="100px"/> 
      <td width="11px"/> 
      <td width="100px"/> 
      <td width="11px"/> 
      <td width="100px"/> 
      <td width="12px"/> 
      </tr> 

      <tr> 
      <td align="center" width="11px"/> 
      <td align="center" width="100px"> 
      <label for="from_age">&nbsp From:</label> 
      </td> 
      <td align="center" width="11px"/> 
      <td align="center" width="100px"> 
       <select name="from_age" id="from_age" class="dropdown" style="width: 100px"> 
        <option value="18">18</option> 
        <option value="19">19</option> 
        <option value="20">20</option> 
        <option value="21">21</option> 
        <option value="22">22</option> 
        <option value="23">23</option> 
        <option value="24">24</option> 
        <option value="25">25</option> 
        <option value="26">26</option> 
        <option value="27">27</option> 
        <option value="28">28</option> 
        <option value="29">29</option> 
        <option value="30">30</option> 
        <option value="31">31</option> 
        <option value="32">32</option> 
        <option value="33">33</option> 
        <option value="34">34</option> 
        <option value="35">35</option> 
        <option value="36">36</option> 
        <option value="37">37</option> 
       </select> 
      </td> 
      <td align="center" width="11px"/> 
      <td align="center" width="100px"> 
      <label for="to_age">&nbsp To:</label> 
      <td align="center" width="11px"/> 
      <td align="center" width="100px"> 
       <select name="to_age" id="to_age" class="dropdown" style="width: 100px"> 
        <option value="18">18</option> 
        <option value="19">19</option> 
        <option value="20">20</option> 
        <option value="21">21</option> 
        <option value="22">22</option> 
        <option value="23">23</option> 
        <option value="24">24</option> 
        <option value="25">25</option> 
        <option value="26">26</option> 
        <option value="27">27</option> 
        <option value="28">28</option> 
        <option value="29">29</option> 
        <option value="30">30</option> 
        <option value="31">31</option> 
        <option value="32">32</option> 
        <option value="33">33</option> 
        <option value="34">34</option> 
        <option value="35">35</option> 
        <option value="36">36</option> 
        <option value="37">37</option> 
       </select> 
      <td align="center" width="12px"/> 
      </tr> 

      <tr> 
      <td width="11px" height="5px"/> 
      <td width="100px"/> 
      <td width="11px"/> 
      <td width="100px"/> 
      <td width="11px"/> 
      <td width="100px"/> 
      <td width="11px"/> 
      <td width="100px"/> 
      <td width="12px"/> 
      </tr> 

      <tr> 
      <td align="center" width="11px"/> 
      <td align="center" width="100px"> 
      <label for="religion">&nbsp Religion:</label> 
      </td> 
      <td align="center" width="11px"/> 
      <td align="center" width="100px"> 
       <select name="religion" id="religion" class="dropdown" 
       onChange="showcaste(this.value)" style="width: 100px"> 
        <?php 
          while($q_rel_data = mysql_fetch_array($result_religion)) 
          {?> 
          <option value="<?php echo $q_rel_data[0]; ?>"<?php if($row_social[religion] == $q_rel_data[0]) echo ' selected="selected"'; ?>> 
          <?php echo $q_rel_data[0]; ?> 
          </option> 
          <?php }?> 
       </select> 
      </td> 
      <td align="center" width="11px"/> 
      <td align="center" width="100px"> 
      <label for="caste">&nbsp Caste:</label> 
      <td align="center" width="11px"/> 
      <td align="center" width="100px" > 
       <select name="caste" id="caste" class="dropdown" style="width: 100px"> 
       </select> 
      <td align="center" width="12px"/> 
      </tr> 

      <tr> 
      <td width="11px" height="4px"/> 
      <td width="100px"/> 
      <td width="11px"/> 
      <td width="100px"/> 
      <td width="11px"/> 
      <td width="100px"/> 
      <td width="11px"/> 
      <td width="100px"/> 
      <td width="12px"/> 
      </tr> 

      <tr> 
      <td align="center" width="11px"/> 
      <td align="center" width="100px"> 
      <label for="community">&nbsp Comunity:</label> 
      </td> 
      <td align="center" width="11px"/> 
      <td align="center" width="100px"> 
       <select name="community" id="community" class="dropdown" style="width: 100px"> 
          <?php 
          $community=array("Assami","Bengali","Bihari","Gujarati","Marwari","Rajasthani","Tamil","Telugu"); 
          foreach ($community as $value) 
          {?> 
          <option value="<?php echo $value; ?>"<?php if($row_social[community] == $value) echo ' selected="selected"'; ?>><?php echo $value; ?> 
          </option> 
          <?php } ?> 
         </select> 
      </td> 
      <td align="center" width="11px"/> 
      <td align="center" width="100px"> 
      <label for="occupation">&nbsp Occupation:</label> 
      <td align="center" width="11px"/> 
      <td align="center" width="100px"> 
       <select name="occupation" id="occupation" style="width: 100px"> 
          <?php 
          $occupation=array("Doctor","Engineer","Dentist","Civil Service","Military","Police","Govt. Service","Judiciary","Business","Private Job", "IT Professional","Teacher","Faculty","Sportsperson"); 
          foreach ($occupation as $value) 
          {?> 
          <option value="<?php echo $value; ?>"<?php if($row_professional[occupation] == $value) echo ' selected="selected"'; ?>><?php echo $value; ?> 
          </option> 
          <?php } ?> 
         </select>  
      <td align="center" width="12px"/> 
      </tr> 

      <tr> 
      <td width="11px" height="4px"/> 
      <td width="100px"/> 
      <td width="11px"/> 
      <td width="100px"/> 
      <td width="11px"/> 
      <td width="100px"/> 
      <td width="11px"/> 
      <td width="100px"/> 
      <td width="12px"/> 
      </tr> 

      <tr> 
       <td align="center" colspan="9"> 
      <input type="submit" name="Search" value="Search" class="button" style="width: 250px;"/> 
      </td> 
      </tr> 

      <tr> 
      <td width="11px" height="4px"/> 
      <td width="100px"/> 
      <td width="11px"/> 
      <td width="100px"/> 
      <td width="11px"/> 
      <td width="100px"/> 
      <td width="11px"/> 
      <td width="100px"/> 
      <td width="12px"/> 
      </tr> 
    </table> 
    </form> 
</div> 
</td> 
<td width="190px"> 
<div id="search_by_name"> 
<h2>Search By Name</h2> 
    <form method="post" action=""> 
    <table width="190px" cellpadding="0" cellspacing="0" border="0" align="center"> 
     <tr> 
     <td align="center">Enter Name</td> 
     <td align="center"> 
      <input type="text" id="name_to_search" name="name_to_search" class="textfield" 
      style="width: 100px;"/> 
     </td> 
     </tr> 
     <tr> 
     <td colspan="2">&nbsp 
     </td> 
     <tr> 
     <td align="center" colspan="2"> 
      <input type="submit" id="search_pro" name="search_pro" class="button" 
      style="width: 100px;" align="center" /> 
     </td>  
     </tr> 
    </table> 
    </form> 
</div> 
</td> 
</tr> 
<tr> 
<td colspan="2"> 
<div id="search_profile_result"> 
</div> 
</td> 
</tr> 
</table> 
</div> 
</body> 
</html> 

だ私のAJAXのスクリプトが

var http_request = false; 
function makePOSTRequestProfile(url, parameters) { 
http_request = false; 
if (window.XMLHttpRequest) { // Mozilla, Safari,... 
http_request = new XMLHttpRequest(); 
if (http_request.overrideMimeType) { 
// set type accordingly to anticipated content type 
//http_request.overrideMimeType('text/xml'); 
http_request.overrideMimeType('text/html'); 
} 
} else if (window.ActiveXObject) { // IE 
try { 
http_request = new ActiveXObject("Msxml2.XMLHTTP"); 
} catch (e) { 
try { 
http_request = new ActiveXObject("Microsoft.XMLHTTP"); 
} catch (e) {} 
} 
} 
if (!http_request) { 
alert('Cannot create XMLHTTP instance'); 
return false; 
} 

http_request.onreadystatechange = alertSearchContents; 
http_request.open('POST', url, true); 
http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
http_request.setRequestHeader("Content-length", parameters.length); 
http_request.setRequestHeader("Connection", "close"); 
http_request.send(parameters); 
} 

function alertSearchContents() { 
if (http_request.readyState == 4) { 
if (http_request.status == 200) { 
//alert(http_request.responseText); 
result = http_request.responseText; 
document.getElementById('search_profile_result').innerHTML = result; 
} else { 
alert(http_request.status); 
} 
} 
} 

function search_profile(obj) 
{ 

alert("huhu"); 
var poststr = "gender=" + encodeURI(document.getElementById("search_gender").value) + 
"&from_age=" + encodeURI(document.getElementById("from_age").value) + 
"&to_age=" + encodeURI(document.getElementById("to_age").value) + 
"&religion=" + encodeURI(document.getElementById("religion").value) + 
"&caste=" + encodeURI(document.getElementById("caste").value) + 
"&community=" + encodeURI(document.getElementById("community").value) + 
"&occupation=" + encodeURI(document.getElementById("occupation").value); 
alert(poststr); 
makePOSTRequestProfile('search.php', poststr); 
} 

とクエリが取り組まれ、最終的にsearch.phpをAjaxSearchProfile.jsだ

<?php 
include('connection.php'); 
$sex=$_POST['gender']; 
$from_age=$_POST['from_age']; 
$to_age=$_POST['to_age']; 
$religion=$_POST['religion']; 
$caste=$_POST['caste']; 
$community=$_POST['community']; 
$occupation=$_POST['occupation']; 

$sql_search="SELECT t1.username, t1.name, t1.age, t1.dob, t1.propic, t2.religion, t2.caste, t3.education, t3.occupation 
FROM candidate_register_table as t1 
LEFT JOIN candidate_social_table as t2 ON 
t1.username = t2.username and t2.caste = '$caste' and t2.religion ='$religion' and t2.community ='$community' 
LEFT JOIN candidate_professional_table as t3 ON 
t1.username = t3.username and t3.occupation = '$occupation' WHERE t1.sex = '$sex'"; 


$result_search=mysql_query($sql_search,$con); 
if($result_search) 
    { 
     echo "<table border='0' cellspacing='0' cellpadding='0' width='650px' align='center'>"; 
     while($row=mysql_fetch_array($result_search)) 
      { 

      echo "<tr>"; 
      echo "<form method='post' action='profile/exp.php' name='showid' id='showid'>"; 
      echo "<td><input type='hidden' name='pro_username' value='" . $row['username'] . "'/></td>"; 
      echo "<td><input type='image' src='" . $row['propic'] ."' style='width:30px;'/></td>"; 
      echo "<td><FONT COLOR=blue FACE='Geneva, Arial' SIZE=2>" . $row['username'] . " ::" . "</font></td>"; 
      echo "<td><FONT COLOR=blue FACE='Geneva, Arial' SIZE=2>" . $row['name'] . " ::" . "</font></td>"; 
      echo "<td><FONT COLOR=blue FACE='Geneva, Arial' SIZE=2>" . $row['religion'] . " ::" . "</font></td>"; 
      echo "<td><FONT COLOR=blue FACE='Geneva, Arial' SIZE=2>" . $row['caste'] . " ::" . "</font></td>"; 
      echo "<td><FONT COLOR=blue FACE='Geneva, Arial' SIZE=2>" . $row['occupation'] . " ::" . "</font></td>"; 
      echo "<td><input type='submit' name='submit' id='submit'/></td>"; 
      echo "</form>"; 
      echo"</tr>"; 


     } 
     echo "</table>"; 
    } 
else 
    die('Error: ' . mysql_error()); 



?> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
<title>Untitled Document</title> 
</head> 

<body> 
</body> 
</html> 

あなたが見ることができる場合、検索結果はの内部に表示されますsearch_profile.phpの3210あなたが見ることができるように

事実は、検索結果ではsearch.phpに私は結果を印刷していますだけでなく、私はのように振る舞うべきinput type="image"を使用しています、所望の方法として表示されますが、今 されています送信ボタンをクリックすると、input type="hidden"に割り当てられているユーザ名がファイル"profile/exp.php"に送信されます。

しかし、入力タイプ= "hidden"の値は投稿されていないか、blaNK値のみが転記されています。ここ

は、プロファイル/ exp.phpです:

<?php 
session_start(); 
ob_start(); 
$showpro=$_POST['pro_username']; 
echo $showpro; 
?> 

それは結果すなわち、ユーザ名を表示するべきであるが、そのは表示されません。私はその理由を見つけることができません。私は以前この方法を別のアルバムのcretaingアプリケーションで使っていましたが、うまくいきました。私の検索クエリとプロシージャは完璧です。それ以外の場合は結果が表示されませんが、入力タイプ= "イメージ"が機能しない理由はわかりません。同様に私はあなたが見ることができるようにサブミットボタンを試しましたが、そのサブミットボタンも機能していません。

この次の行は、入力タイプ=「画像」と入力タイプ=すなわち、機能していない

更新

$result_search=mysql_query($sql_search,$con); 
if($result_search) 
    { 
     echo "<table border='0' cellspacing='0' cellpadding='0' width='650px' align='center'>"; 
     while($row=mysql_fetch_array($result_search)) 
      { 

      echo "<tr>"; 
      echo "<form method='post' action='profile/exp.php' name='showid' id='showid'>"; 
      echo "<td><input type='hidden' name='pro_username' value='" . $row['username'] . "'/></td>"; 
      echo "<td><input type='image' src='" . $row['propic'] ."' style='width:30px;'/></td>"; 
      echo "<td><FONT COLOR=blue FACE='Geneva, Arial' SIZE=2>" . $row['username'] . " ::" . "</font></td>"; 
      echo "<td><FONT COLOR=blue FACE='Geneva, Arial' SIZE=2>" . $row['name'] . " ::" . "</font></td>"; 
      echo "<td><FONT COLOR=blue FACE='Geneva, Arial' SIZE=2>" . $row['religion'] . " ::" . "</font></td>"; 
      echo "<td><FONT COLOR=blue FACE='Geneva, Arial' SIZE=2>" . $row['caste'] . " ::" . "</font></td>"; 
      echo "<td><FONT COLOR=blue FACE='Geneva, Arial' SIZE=2>" . $row['occupation'] . " ::" . "</font></td>"; 
      echo "<td><input type='submit' name='submit' id='submit'/></td>"; 
      echo "</form>"; 
      echo"</tr>"; 


     } 
     echo "</table>"; 
    } 
else 
    die('Error: ' . mysql_error()); 

答えて

0

は、私は答えを期待し、「提出」、と私はそれを見つけました私は...

私はprobを作成していたタグのすぐ下にタグを追加することで間違ったことをしていました。 タグの下に追加する必要がありました。だから私のコードを次のように変更しました: -

echo "<table border='0' cellspacing='0' cellpadding='0' width='650px' align='center'>"; 
     while($row=mysql_fetch_array($result_search)) 
      { 

      echo "<tr>"; 
      echo "<td>"; 
      echo "<form method='post' action='profile/id.php' name='showid' id='showid'> 
      <input name='pro_username' name='pro_username' type='hidden' value='";echo $row['username']; echo "'/> 
      <input type='image' src='" . $row['propic'] ."' style='width:30px;'/></form></td>"; 
      echo "<td><FONT COLOR=blue FACE='Geneva, Arial' SIZE=2>" . $row['username'] . " ::" . "</font></td>"; 
      echo "<td><FONT COLOR=blue FACE='Geneva, Arial' SIZE=2>" . $row['name'] . " ::" . "</font></td>"; 
      echo "<td><FONT COLOR=blue FACE='Geneva, Arial' SIZE=2>" . $row['religion'] . " ::" . "</font></td>"; 
      echo "<td><FONT COLOR=blue FACE='Geneva, Arial' SIZE=2>" . $row['caste'] . " ::" . "</font></td>"; 
      echo "<td><FONT COLOR=blue FACE='Geneva, Arial' SIZE=2>" . $row['occupation'] . " ::" . "</font></td>"; 
      echo "<td><input type='submit' name='submit' id='submit'/></td>"; 
      echo "</form>"; 
      echo"</tr>"; 


     } 
     echo "</table>"; 
    } 
+0

あなた自身の答えを見つけて投稿していただきありがとうございます。私は、タグの真下にタグを追加することで間違ったことをしていました。タグ "Im stuck now now .. :)の下に追加する必要がありました – bart2puck

関連する問題