emeronyr 0 Report post Posted July 11, 2010 Salam... baru nak berjinak2 dlm membuat sistem dan belajar PHP [b]index.php[/b] <form id="frmCarian" name="frmCarian" method="get" action="prosesCarian.php"> <div align="center"> <p><span class="style2">Sila Taip No Kad Pengenalan : </span> <input name="txtKP" type="text" id="txtKP" size="25" maxlength="12" /> <input name="btnHantar" type="submit" id="btnHantar" value="Hantar" /> </p> <p class="style3">** Sila gunakan nombor kad pengenalan tanpa " - " ** </p> </div> </form> [b]prosesCarian.php[/b] <?php include "inc/dbase.php"; //1.get user input $noIC=$_GET["txtKP"]; //$state=$_POST["txtstate"]; //2. Make SQL query $query = "select * from tkpengunjung WHERE NOKP='$noIC'"; // (tkpengunjung tu - nama table) (NOKP tu-- field dlm table) $result=mysql_query($query) ; echo "$query"; // utk test dbase //3. Count record $count=mysql_num_rows($result); if($count==0) { echo "no record found";} else { //4.pass value to view.php page $row = mysql_fetch_array($result); header("location:viewSearch.php?kp=".$row["NOKP"]); } ?> ada error dioutput [b]http://localhost/ePelawat/prosesCarian.php?txtKP=777777777777&btnHantar=Hantar[/b] select * from tkpengunjung WHERE NOKP='777777777777' Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\ePelawat\prosesCarian.php on line 14 no record found Mintak tlg kawan²..... Quote Share this post Link to post Share on other sites
johnburn 6 Report post Posted July 11, 2010 aku try cam ok je. cuba tukar line 10 dari: [php]$result=mysql_query($query) ;[/php] menjadi: [php]$result=mysql_query($query) or die('Query gagal: ' . mysql_error());[/php] dan tgk ada kuar apa2 error x. Quote Share this post Link to post Share on other sites
slier 28 Report post Posted July 11, 2010 (edited) kod ko ada bug la basically its working tp try pikir katakan ko cuba cr NOKP = '777777777777' yg mana x wujud dalam database $count = mysql_num_rows($result); <---obviously fail cause no result has been found [code] tukar ke mcm ni if($result) { $row = mysql_fetch_array($result); header("location:viewSearch.php?kp=".$row[" NOKP"]); } else { echo "no record found"; } [/code] Edited July 11, 2010 by slier Quote Share this post Link to post Share on other sites
emeronyr 0 Report post Posted July 11, 2010 (edited) tq bro johnburn & slier... problem settel... Edited July 11, 2010 by emeronyr Quote Share this post Link to post Share on other sites
johnburn 6 Report post Posted July 11, 2010 [quote name='slier' date='11 July 2010 - 07:46 PM' timestamp='1278848778' post='1041340'] kod ko ada bug la basically its working tp try pikir katakan ko cuba cr NOKP = '777777777777' yg mana x wujud dalam database $count = mysql_num_rows($result); <---obviously fail cause no result has been found [/quote] kl keadaan mcm tu, sepatutnya mysql_num_rows() akan return 0, sbb bilngn row untuk result set = 0 (bleh try dgn echo $count;) dan septtnya error tu xkuar. kemungkinan ada prob ngan query sbb tu aku cdangkn cmtu pe2 pn TS dh jmpa mslh dia Quote Share this post Link to post Share on other sites