Jump to content
Sign in to follow this  
sueirna

Carian-Update In Php

Recommended Posts

tlg sedara/i, betulkan saya silap kat mana...saya ada 3 file (carian.php-->kemaskini.php ---kemaskinichk.php)
kat carian tak de masalah..bila cari record dia akan display record[Nama]..tapi bila nak klik Nama sepatutnya dia akan masuk pada page kemaskini.php dan display maklumat sedia ada dlm db dalam bentuk form...tapi malangnya dia tak display apa2 pun...

carian.php

[quote]
<?php

if(isset($_POST['submit'])){
if(isset($_GET['go'])){

$name=$_POST['name'];

//connect to the database
$db=mysql_connect (localhost, root, xxx) or die ('I cannot connect to the database because: ' . mysql_error());

//-select the database to use
$mydb=mysql_select_db(peperiksaan);

//-query the database table
$sql="SELECT Nama, Namajab, bandar FROM pengawas WHERE Nama LIKE '%" . $name . "%' OR KP LIKE '%" . $name ."%'";

//-run the query against the mysql query function
$result=mysql_query($sql);

//-count results

$numrows=mysql_num_rows($result);

echo "<p>" .$numrows . " rekod pengawas yang dijumpai melalui carian " . stripslashes($name) . "</p>";

//-create while loop and loop through result set
while($row=mysql_fetch_array($result)){

$Nama =$row['Nama'];
$Namajab=$row['Namajab'];
$alamat=$row['alamat'];
$bandar=$row['bandar'];

//-display the result of the array

echo "<ul>\n";
echo "<li>" . "<a href=\"kemaskini.php?id=$Nama\">" .$Nama . " " . $Namajab . "</a></li>\n";
echo "</ul>";
}
}
else{
echo "<p>Sila masukkan Nama Pengawas </p>";
}
}
?>

[/quote]

kemaskini.php

[quote]

?php

mysql_connect("localhost","root","xxx");
mysql_select_db("peperiksaan");
$mydb=mysql_select_db("pengawas");

//connect to the database
$db=mysql_connect (localhost, root, xxx) or die ('I cannot connect to the database because: ' . mysql_error());
$mydb=mysql_select_db(pengawas);


/* EDIT RECORD */
// if the 'id' variable is set in the URL, we know that we need to edit a record
if (isset($_GET['id'])) {

// make sure the 'id' in the URL is valid
if (isset($_GET['id'])) {
// get variables from the URL/form
$id = $_POST['id'];



}}
$sql="SELECT * FROM pengawas";
$result=mysql_query($sql);
$row=mysql_fetch_array($result) or die ('Error: '.mysql_error ());
while($row=mysql_fetch_assoc($result));

$id = $row['id'];
$Nama = $row['Nama'];
$KP = $row['KP'];
$Jawatan = $row['Jawatan'];
$Gred = $row['Gred'];
$Peranan = $row['Peranan'];
$Namajab = $row['Namajab'];
$alamat = $row['alamat'];
$alamat1 = $row['alamat1'];
$alamat2 = $row['alamat2'];
$Tlantik = $row['Tlantik'];
$Tsah = $row['Tsah'];
$poskod = $row['poskod'];
$bandar = $row['bandar'];
$notel = $row['notel'];
$nofax = $row['nofax'];
$nohp1 = $row['nohp1'];



?>

<form action="kemaskinichk.php" method="post" name="form1" class="style1" id="form1">

[/quote]

[quote]?php

mysql_connect("localhost","root","xxx");
mysql_select_db("peperiksaan");
$mydb=mysql_select_db("pengawas");

//connect to the database
$db=mysql_connect (localhost, root, xxx) or die ('I cannot connect to the database because: ' . mysql_error());
$mydb=mysql_select_db(pengawas);


/* EDIT RECORD */
// if the 'id' variable is set in the URL, we know that we need to edit a record
if (isset($_GET['id'])) {

// make sure the 'id' in the URL is valid
if (isset($_GET['id'])) {
// get variables from the URL/form
$id = $_POST['id'];



}}
$sql="SELECT * FROM pengawas";
$result=mysql_query($sql);
$row=mysql_fetch_array($result) or die ('Error: '.mysql_error ());
while($row=mysql_fetch_assoc($result));

$id = $row['id'];
$Nama = $row['Nama'];
$KP = $row['KP'];
$Jawatan = $row['Jawatan'];
$Gred = $row['Gred'];
$Peranan = $row['Peranan'];
$Namajab = $row['Namajab'];
$alamat = $row['alamat'];
$alamat1 = $row['alamat1'];
$alamat2 = $row['alamat2'];
$Tlantik = $row['Tlantik'];
$Tsah = $row['Tsah'];
$poskod = $row['poskod'];
$bandar = $row['bandar'];
$notel = $row['notel'];
$nofax = $row['nofax'];
$nohp1 = $row['nohp1'];



?>

<form action="kemaskinichk.php" method="post" name="form1" class="style1" id="form1">
[/quote]

[quote]
<input name="nama" type="text" class="color" id="name" value="<?php echo $Nama; ?>" size="40" />
[/quote] Edited by sueirna

Share this post


Link to post
Share on other sites
Salam...

[quote]
[color="#8B0000"][b]$Id=$row['id'];[/b][/color]
$Nama =$row['Nama'];
$Namajab=$row['Namajab'];
$alamat=$row['alamat'];
$bandar=$row['bandar'];

//-display the result of the array

echo "<ul>\n";
echo "<li>" . "<a href=\"kemaskini.php?id=[color="#8B0000"][b]$Id[/b][/color]\">" .$Nama . " " . $Namajab . "</a></li>\n";
echo "</ul>";[/quote]

tambah dan tukar yg berkenaan..

Silapnye sebab ko send variable dlm bentuk text, tapi kat page kemaskini ko nak retrieve guna id(integer)..

kat form kemaskini tu, query sql tu patut ada where clause

[quote]$sql="SELECT * FROM pengawas[color="#8B0000"][b] where id=$id[/b][/color]";[/quote]

Lebih kurang mcm tu la kot..

Kalo x betul pun atleast ko bleh la dpt idea mcmane nak repair k..

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...