PHP관련 질문이요...급해요...
글쓴이: chur_ry / 작성시간: 월, 2005/12/05 - 4:30오전
APM을 통해 간단하 검색 페이지를 만들고 있습니다.
컴 사양은 젠투, Apach 2, PHP 5, Mysql 4 입니다.
search.php의 코드를 적어 놨구요, 웹의 검색 페이지에서 search를 하게 되면 그냥 원래 페이지로 돌아오게 됩니다. 검색이 안되는 것이지요.. 이것 말고, 그냥 디비 전부를 보여주는 페이지(allentries.php)는 제대로 작동 합니다 id, spot, cog, cog_definition 전부 출력됩니다만... more info로 링크된 페이지(view.php)는 먹통이네요.. 원래대로 라면, $id로 검색이 되어야 하는데.. 물론 디비와 연동 되는 것은 확인 했구요.. view.php에서 $id를 못 읽어 드리는 건 가요?? search.php에서는 $searchstring, $searchtype을 못 읽는 거구요??
에휴.. 초보는 힘들답니다...ㅜㅜ
어디를 어떡게 고쳐야 하나요...
아래는 allentries.php 하면 나오는 페이지 결과 일부 입니다..
A01010104 Os000129_01 [Z] Kinesin-like protein more info
A01010105 Os000147_01 [B] Histone H2B more info
A01010106 Os000153_01 [X] A Unnamed protein more info
search.php <?php include ("include/header.inc"); include ("include/dbconnect.inc"); if(isset($searchstring)) { $sql = "SELECT * FROM $table WHERE $searchtype LIKE '%$searchstring%' "; $result = mysql_query($sql, $db); $resultsnumber = mysql_numrows($result); echo("<table width=80% border=0>"); echo("search result: $resultsnumber"); $sw = "2"; while($myrow = mysql_fetch_array($result)) { $Spot = $myrow["Spot"]; $id = $myrow["id"]; $COG = $myrow["COG"]; if($sw == "1") { $color = "#ffffff"; $alternate = "2"; } else { $color = "#efefef"; $sw = "1"; } echo(" <tr bgcolor=$color> <td>$Spot</td> <td>$COG</td> <td><a href='view.php?id=$id'>more info</a></td> "); } echo(" </tr> </tr><td colspan=4> </td></tr> <tr> <td colspan=4 align=center> <a href='az_index.php'>ordered</a> or <a href='$PHP_SELF'>search again</a> </td> </tr> </table> "); } else { ?> <form method="post" action="search.php"> <table border="0" cellspacing="2" width="380"> <tr> <td><h1>Spot</h1></td> <td><b>using</b></td> </tr> <tr> <td valign="top"> <input type="text" name="searchstring" size="35"> </td> <td> <input type="radio" name="searchtype" value="Spot" checked>Spot<br> <input type="radio" name="searchtype" value="Oligo">Oligo<br> </td> </tr> <tr> <td align=center> <input type="submit" value="search"> </td> <td> </td> </tr> </table> </form> <?php } include ("include/footer.inc"); ?> allentries.php <?php include ("include/header.inc"); include("include/dbconnect.inc"); $result = mysql_query("SELECT * FROM $table ORDER BY Spot", $db); echo("<table width=100% cellpadding=2 cellspacing=1 border=0>"); $sw = "2"; while($row = mysql_fetch_array($result)) { $id = $row["id"]; $Spot = $row["Spot"]; $Oligo = $row["Oligo"]; $COG = $row["COG"]; $COG_definition = $row["COG_definition"]; if($sw == "1") { $color = "#ffffff"; $sw = "2"; } else { $color = "#efefef"; $sw = "1"; } echo(" <tr bgcolor=$color> <td>$Spot</td> <td>$Oligo</td> <td>$COG</td> <td>$COG_definition</td> <td><a href='view.php?id=$id'>more info</a></td> </tr> "); } echo("</table>"); include ("include/footer.inc"); ?> view.php <?php include ("include/header.inc"); include ("include/dbconnect.inc"); if($id) { $result = mysql_query("SELECT * FROM $table WHERE id='$id';",$db); $links = mysql_fetch_array($result); $id = $links["id"]; $Spot = $links["Spot"]; $Oligo = $links["Oligo"]; $COG = $links["COG"]; $COG_definition = $links["COG_definition"]; echo(" <table border='0' cellspacing='1' cellpadding='1'> <tr> <td bgcolor='#003366'> <font color='#ffffff'>Spot</font> </td> <td>$Spot</td> </tr> <table border='0' cellspacing='1' cellpadding='1'> <tr> <td bgcolor='#003366'> <font color='#ffffff'>Oligo</font> </td> <td>$Oligo</td> </tr> <tr> <td bgcolor='#003366'> <font color='#ffffff'>COG</font> </td> <td>$COG</td> </tr> <tr> <td bgcolor='#003366'> <font color='#ffffff'>COG_Definition</font> </td> <td>$COG_definition</td> </tr> </table> "); } else { echo(" <script> alert('USE Spot ID'); location = 'index.php' </script> "); exit; } include ("include/footer.inc"); ?>
Forums:
php.ini의 셋팅에서 globals_register나 register
php.ini의 셋팅에서 globals_register나 register_globals의 옵션이 off라면 위의 search.php에서
if(isset($searchString)) {...
구문은 항상 거짓이 됩니다. 왜냐하면 $searchString가 전역변수로 취급되지 않기 때문입니다.
위의 셋팅과 관계없이 동작하려면 위의 구문을
if(isset($_POST['searchString'])) {...
로 변경해보세요.
$_POST는 post로 넘어온 값들을 연관배열로 갖습니다.
나머지 다른 searchType이라던가도 위와 같이 바꿔주면 되겠네요..
$id도 마찬가지로 이 값이 post로 넘어왔다면 $_POST['id']로 get으로 넘어왔다면 $_GET['id']로 바꿔주세요.
이렇게 항상 $_POST와 $_GET으로 값을 받아주는 것은 좋은습관입니다. 이러면 설정값에 상관없이 항상 동작하지요.
혹은 위의 스크립트를 모두 고치기가 벅차다면
foreach($_POST(or $_GET) as $key => $value) {
${$key} = $value;
}
등을 사용해서 마치 전역변수인 것처럼 변수명을 치환해주는 방법도 있으나, 권장하진 않습니다.
--->
데비안 & 우분투로 대동단결!
감사합니다..
새벽에 올린 글에 이리 빨리 답도 달아주시고..
잘 해결했습니다.
감사합니다.
신석철 입니다.
댓글 달기