Jump to content
Sign in to follow this  
emeronyr

Searching Php & Mysql

Recommended Posts

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 &quot; - &quot; ** </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².....

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 by slier

Share this post


Link to post
Share on other sites
[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 :)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...