ต้องการทำ ค้นหา แก้ไขข้อมูล และลบข้อมูล คือเราทำค้นหาได้ แก้ไขได้ และลบได้แล้ว แต่คือ พอเราค้นหา เราก้อใส่คำที่ต้องการค้นหาไป
ขอดูคำสั่ง sql ที่ใช้ค้นหา แก้ไข และลบด้วยค่ะ คาดว่าไม่ได้ใส่เงื่อนไข หรือใส่ผิด
Date :
15 ต.ค. 2551 16:24:02
By :
tacomsci
ต้องมีรหัส id อ้างอิงด้วยครับ
เช่น ถ้าลบ
- delete from tablae where id='1'
แก้ไข
- update table set name='xxx' where id='1'
ประมาณนี้ครับ อย่าลืมใส่เงือนไขมันลงไป
www.mylovephp.com
Date :
15 ต.ค. 2551 20:28:22
By :
mylovephp
น่าจะเป็นที่ตัวแปรนะครับกำหนดตัวแปรเงื่อนไขไม่ชัดจน ผลที่ได้ก็ ...
Date :
15 ต.ค. 2551 21:15:59
By :
aprodise
code ค่ะ
----------------edit.html---------------------------
<html>
<body>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874">
<title>:: Edit Data : :</title><BR><BR>
<B><H2><CENTER>¤é¹ËÒ¢éÍÁÙÅ·ÕèµéÍ¡ÒÃá¡éä¢ áÅÐź</CENTER></H2></B>
<div align="right">
<FORM METHOD=POST ACTION="edit1.php">
<table border="0" cellspacing="5" cellpadding="0">
<tr>
<td><B><IMG SRC="http://u3.upload.sanook.com/embed/6b08cb6ba2eb988e58226f33f4bd1f76.gif" WIDTH="32" HEIGHT="32" BORDER="0" ALT="">¤é¹ËÒ¢éÍÁÙÅ</B> :: </td>
<td>
<input type="text" name="search" >
</td>
<td>
<input type="submit" name="Submit" value="¤é¹ËÒ" >
</td>
</tr>
</table>
<!-- -->
<div>
</form>
</head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874">
<body>
<p> </p>
<div align="left">
<h3><a href="mainpage.html"><< MainPage </a> <A HREF="add1.html">ADD</A> <A HREF="edit.html">EDIT</A> DEL</h3> <BR>
<table width="2603" height="56" border="4" cellpadding="5">
<!-- <table border="1" align="center"> -->
<tr>
<td width="142">
<B><div align="center">No.</div></B>
</td>
<td width="142">
<B><div align="center">Servernames</div></B>
</td>
<td width="142">
<B><div align="center">Model </div></B>
</td>
<td width="142">
<B><div align="center">OS</div></B>
</td>
<td width="142">
<B><div align="center">Applications</div></B>
</td>
<td width="142">
<B><div align="center">Functions</div></B>
</td>
<td width="142">
<B><div align="center">CPU</div></B>
</td>
<td width="142">
<B><div align="center">Memory_MB</div></B>
</td>
<td width="142">
<B><div align="center">I.HDD</div></B>
</td>
<td width="142">
<B><div align="center">E.HDD</div></B>
</td>
<td width="142">
<B><div align="center">CPU_Num</div></B>
</td>
<td width="142">
<B><div align="center">HDD_Num</div></B>
</td>
<td width="142">
<B><div align="center">Partition_GB</div></B>
</td>
<td width="142">
<B><div align="center">Raiddisk </div></B>
</td>
<td width="142">
<B><div align="center">IPAddress</div></B>
</td>
<td width="142">
<B><div align="center">Type</div></B>
</td>
<td width="142">
<B><div align="center">Serial_No</div></B>
</td>
<td width="142">
<B><div align="center">Warranty</div></B>
</td>
<td width="142">
<B><div align="center">MA_Type</div></B>
</td>
<td width="142">
<B><div align="center">Purchase_Date</div></B>
</td>
<td width="142">
<B><div align="center">Warranty_Exp</div></B>
</td>
<td width="142">
<B><div align="center">Location</div></B>
</td>
<td width="142">
<B><div align="center">Remark</div></B>
</td>
</tr>
<tr></tr> <tr></tr> <tr></tr> <tr></tr> <tr></tr>
<!-- </table> -->
</table>
</body>
</html>
--------------------------edit1.php--------------------------
<html>
<body>
<CENTER><H3><B>àÅ×Í¡¢éÍÁÙÅ·ÕèµéÍ¡ÒÃá¡éä¢ áÅÐź</B></H3></CENTER><BR><BR>
<div align="left"> <A HREF="edit.html">¡ÅѺ</A> </div>
<form name="form1" method="POST" action="edit2.php">
<?
$host="localhost";
$username="root";
$password="msc";
$db="msc server accessment";
$tb="msc";
mysql_connect( $host,$username,$password)or die ("µÔ´µè͡Ѻ°Ò¹¢éÍÁÙÅ Mysql äÁèä´é ");
mysql_select_db($db) or die("àÅ×Í¡°Ò¹¢éÍÁÙÅäÁèä´é"); /* ·Ó¡ÒÃàÅ×Í¡°Ò¹¢éÍÁÙÅ¡è͹ */
$sql = "select * from $tb where Number like '%$search%' " ;
$db_query=mysql_db_query($db,$sql);
$num_rows=mysql_num_rows($db_query); /* ¹Ñº Reccord ·Õ辺 */
if(empty($num_rows)) /* µÃǨÊͺÇèÒÁÕÍÂÙèËÃ×ÍÂÑ */
{
echo"<center><br>äÁ辺¢éÍÁÙÅ <b>$_POST[search]</b> </center>";
exit();
}
else
{
?>
<div align="center">
<? echo " áÊ´ÃÒ¡Òäé¹ËÒ <b> $_POST[search] </b> ¾º <b> $num_rows </b> Reccord "; ?>
<br>
<table width="2603" height="56" border="4" cellpadding="5">
<!-- <table border="1" align="center"> -->
<tr>
<td width="142">
<div align="center">Edit</div>
</td>
<td width="142">
<div align="center">Delete</div>
</td>
<td width="142">
<div align="center">No</div>
</td>
<td width="142">
<div align="center">Servernames</div>
</td>
<td width="142">
<div align="center">Model</div>
</td>
<td width="142">
<div align="center">OS</div>
</td>
<td width="142">
<div align="center">Applications</div>
</td>
<td width="142">
<div align="center">Functions</div>
</td>
<td width="142">
<div align="center">CPU</div>
</td>
<td width="142">
<div align="center">Memory_MB</div>
</td>
<td width="142">
<div align="center">I_HDD</div>
</td>
<td width="142">
<div align="center">E_HDD</div>
</td>
<td width="142">
<div align="center">CPU_Num</div>
</td>
<td width="142">
<div align="center">HDD_Num</div>
</td>
<td width="142">
<div align="center">Partition_GB</div>
</td>
<td width="142">
<div align="center">RaidDisk</div>
</td>
<td width="142">
<div align="center">IPAddress</div>
</td>
<td width="142">
<div align="center">Type</div>
</td>
<td width="142">
<div align="center">Serial_No</div>
</td>
<td width="142">
<div align="center">Warranty</div>
</td>
<td width="142">
<div align="center">MA_Type</div>
</td>
<td width="142">
<div align="center">Purchase_Date</div>
</td>
<td width="142">
<div align="center">Warranty_Exp</div>
</td>
<td width="142">
<div align="center">Location</div>
</td>
<td width="142">
<div align="center">Remark</div>
</td>
</tr>
<tr></tr> <tr></tr> <tr></tr> <tr></tr> <tr></tr>
<?
$a=0;
while($a < $num_rows)
{
$result = mysql_fetch_array($db_query);
$num=$result[Number];
$servername=$result[Servername];
$model=$result[Model];
$os=$result[Os];
$applications=$result[Application];
$functions=$result[Function_S];
$cpu=$result[Cpu];
$memorymb=$result[Memory_MB];
$memorymb=$result[Memory_MB];
$ihdd=$result[I_HDD];
$ehdd=$result[E_HDD];
$cpunum=$result[Cpu_NUM];
$hddnum=$result[HDD_NUM];
$partitiongb=$result[Partition_GB];
$ipaddress=$result[IPaddress];
$raiddisk=$result[Raiddisk ];
$type=$result[Type];
$serialno=$result[Serial_NO];
$warranty=$result[Warranty];
$matype=$result[MA_TYPE];
$purchasedate=$result[Purchase_DATE];
$warrantyexp=$result[Warranty_EXP];
$location=$result[Location];
$remark=$result[Remark];
?>
<tr>
<td width="4%">
<div align="center"><a href="edit2.php <?echo"$search"; ?>">Edit</a></div>
</td>
<td width="4%">
<div align="center"><a href="delete.php <?echo"$search"; ?>">Delete</a></div>
</td>
<td >
<div align="center"width="142">
<?echo"$num";?></div>
</td>
<td width="142">
<?echo"$servername";?>
</td>
<td width="142">
<?echo"$model";?>
</td>
<td width="142">
<?echo"$os";?>
</td>
<td width="142">
<?echo"$applications";?>
</td>
<td width="142">
<?echo"$functions";?>
</td>
<td width="142">
<?echo"$cpu";?>
</td>
<td width="142">
<?echo"$memorymb";?>
</td>
<td width="142">
<?echo"$ihdd";?>
</td>
<td width="142">
<?echo"$ehdd";?>
</td>
<td width="142">
<?echo"$cpunum";?>
</td>
<td width="142">
<?echo"$hddnum";?>
</td>
<td width="142">
<?echo"$partitiongb";?>
</td>
<td width="142">
<?echo"$raiddisk ";?>
</td>
<td width="142">
<?echo"$ipaddress";?>
</td>
<td width="142">
<?echo"$type";?>
</td>
<td width="142">
<?echo"$serialno";?>
</td>
<td width="142">
<?echo"$warranty";?>
</td>
<td width="142">
<?echo"$matype";?>
</td>
<td width="142">
<?echo"$purchasedate";?>
</td>
<td width="142">
<?echo"$warrantyexp";?>
</td>
<td width="142">
<?echo"$location";?>
</td>
<td width="142">
<?echo"$remark";?>
</td>
</tr>
<tr></tr> <tr></tr> <tr></tr>
<!--///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
<?php
$a++;
}
}
echo"<BR><BR>";
?>
</table>
</form>
</body>
</html>
<?
mysql_close();
?>
-----------------------------edit2.php--------------------------------
<html>
<body>
<B><CENTER><H3>á¡é䢢éÍÁÙÅ</H3></CENTER></B><BR>
<?
$host="localhost";
$username="root";
$password="msc";
$db="msc server accessment";
$tb="msc";
mysql_connect( $host,$username,$password)or die ("µÔ´µè͡Ѻ°Ò¹¢éÍÁÙÅ Mysql äÁèä´é ");
mysql_select_db($db) or die("àÅ×Í¡°Ò¹¢éÍÁÙÅäÁèä´é"); /* ·Ó¡ÒÃàÅ×Í¡°Ò¹¢éÍÁÙÅ¡è͹ */
$sql="Select * From $tb ";
$db_query=mysql_db_query($db,$sql);
$result = mysql_fetch_array($db_query);
$num=$result[Number];
$servername=$result[Servername];
$model=$result[Model];
$os=$result[Os];
$applications=$result[Application];
$functions=$result[Function_S];
$cpu=$result[Cpu];
$memorymb=$result[Memory_MB];
$memorymb=$result[Memory_MB];
$ihdd=$result[I_HDD];
$ehdd=$result[E_HDD];
$cpunum=$result[Cpu_NUM];
$hddnum=$result[HDD_NUM];
$partitiongb=$result[Partition_GB];
$ipaddress=$result[IPaddress];
$raiddisk=$result[Raiddisk];
$type=$result[Type];
$serialno=$result[Serial_NO];
$warranty=$result[Warranty];
$matype=$result[MA_TYPE];
$purchasedate=$result[Purchase_DATE];
$warrantyexp=$result[Warranty_EXP];
$location=$result[Location];
$remark=$result[Remark];
?>
<tr>
<FORM METHOD=POST ACTION="edit3.php">
<div align="center">
<label>Servername </label> <input type="text" name="servername"value="<? echo"$servername";?>">
<label>Model <input type="text" name="model"value="<?echo"$model";?>">
OS <input type="text" name="os"value="<?echo"$os "?>">
Application<input type="text" name="applications"value="<?echo"$applications "?>">
</label>
</div>
<p align="center">
<label> Functions
<input type="text" name="functions"value="<?echo"$functions"?>">
CPU
<input type="text" name="cpu"value="<?echo"$cpu "?>">
</label>
<label>Memory[MB]
<input type="text" name="memorymb"value="<?echo"$memorymb "?>">
</label>
<label>I.HDD
<input type="text" name="ihdd"value="<?echo"$ihdd "?>">
</label>
</p>
<p align="center"value="">
<label>E.HDD
<input type="text" name="ehdd"value="<?echo"$ehdd "?>">
</label>
<label>CPU Num
<input type="text" name="cpunum"value="<?echo"$cpunum "?>">
</label>
<label>HDD Num
<input type="text" name="hddnum"value="<?echo" $hddnum"?>">
</label>
<label>Partition[GB]
<input type="text" name="partitiongb"value="<?echo"$partitiongb "?>">
</label>
</p>
<p align="center"value="">
<label>Raid Disk
<input type="text" name="raiddisk"value="<?echo"$raiddisk"?>">
IP Address
<input type="text" name="ipaddress"value="<?echo" $ipaddress"?>">
Type
<input type="text" name="type"value="<?echo" $type"?>">
Serial No.
<input type="text" name="serialno"value="<?echo" $serialno"?>">
</label>
</p>
<p align="center">Warranty
<input type="text" name="warranty"value="<?echo"$warranty "?>">
MA Type
<input type="text" name="matype"value="<?echo" $matype"?>">
Purchase Date
<input type="text" name="purchasedate"value="<?echo"$purchasedate"?>">
Warranty Exp
<input type="text" name="warrantyexp"value="<?echo"$warrantyexp"?>">
</p>
<p align="center">Location
<input type="text" name="location"value="<?echo"$location "?>">
Remark
<textarea name="remark"cols="35" rows="5"value="<?echo"$remark "?>"></textarea>
</p>
<p align="center"> </p>
<p align="left"> </p>
</div>
<CENTER><INPUT TYPE="submit" name="Submit"value=": Save :"><BR><BR>
<INPUT TYPE="reset" name="Reset" value=": Clear :"></CENTER>
</tr>
<tr></tr> <tr></tr> <tr></tr>
<!--///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
</FORM>
</body>
</html>
<?
mysql_close();
?>
-----------------------edit3.php----------------------------
<html>
<body>
<?
$host="localhost";
$username="root";
$password="msc";
$db="msc server accessment";
$tb="msc";
mysql_connect( $host,$username,$password)or die ("µÔ´µè͡Ѻ°Ò¹¢éÍÁÙÅ Mysql äÁèä´é ");
mysql_select_db($db) or die("àÅ×Í¡°Ò¹¢éÍÁÙÅäÁèä´é"); /* ·Ó¡ÒÃàÅ×Í¡°Ò¹¢éÍÁÙÅ¡è͹ */
$sql="update $tb set Servername = '$_POST[servername]',Model = '$_POST[model]',Os= '$_POST[os]',Application ='$_POST[applications]',Function_S = '$_POST[functions]',Cpu='$_POST[cpu]',Memory_MB='$_POST[memorymb]',I_HDD='$_POST[ihdd]',E_HDD='$_POST[ehdd]',Cpu_NUM='$_POST[cpunum]',HDD_NUM ='$_POST[hddnum]',Partition_GB='$_POST[partitiongb]',Raiddisk='$_POST[raiddisk]',IPaddress='$_POST[ipaddress]',Type='$_POST[type]',Serial_NO='$_POST[serialno]',Warranty='$_POST[warranty]',MA_TYPE='$_POST[matype]',Purchase_DATE='$_POST[purchasedate]',Warranty_EXP='$_POST[warrantyexp]',Location='$_POST[location]',Remark='$_POST[remark]'";
/*,Function_S = '$_POST[functions]',Cpu=,'$_POST[cpu]',Memory_MB='$_POST[memorymb]',I_HDD='$_POST[ihdd]',E_HDD='$_POST[ehdd]',Cpu_NUM='$_POST[cpunum]',HDD_NUM ='$_POST[hddnum]',Partition_GB='$_POST[partitiongb]',Raiddisk='$_POST[raiddisk]',IPaddress='$_POST[ipaddress]',Type='$_POST[type]',Serial_NO='$_POST[serialno]',Warranty='$_POST[warranty]',MA_TYPE='$_POST[matype]',Purchase_DATE='$_POST[purchasedate]',Warranty_EXP='$_POST[warrantyexp]',Location='$_POST[location]',Remark='$_POST[remark]',where Number='$num";*/
//$sql="update $tb set (Servername,Model,Os,Application,Function_S,Cpu,Memory_MB,I_HDD,E_HDD,Cpu_NUM,HDD_NUM,Partition_GB,Raiddisk,IPaddress ,Type,Serial_NO,Warranty,MA_TYPE,Purchase_DATE,Warranty_EXP,Location,Remark) values ('$_POST[servername]','$_POST[model]','$_POST[os]','$_POST[applications]','$_POST[functions]','$_POST[cpu]','$_POST[memorymb]','$_POST[ihdd]','$_POST[ehdd]','$_POST[cpunum]','$_POST[hddnum]','$_POST[partitiongb]','$_POST[raiddisk]','$_POST[ipaddress]','$_POST[type]','$_POST[serialno]','$_POST[warranty]','$_POST[matype]','$_POST[purchasedate]','$_POST[warrantyexp]','$_POST[location]','$_POST[remark]')"or die ("á¡é䢢éÍÁÙÅäÁèä´é¤èÐ ");
$db_query=mysql_db_query($db,$sql);
echo "á¡é䢢éÍÁÙÅ àÃÕºÃéÍÂáÅéÇ";
mysql_close();
?>
<BR><BR>
<CENTER><A HREF="showdata.php">áÊ´¢éÍÁÙÅ·ÑéËÁ´</A></CENTER>
</body>
</html>
--------------------------------------
code เราอาจจะ งงๆ หน่อยน่ะ
Date :
16 ต.ค. 2551 09:44:10
By :
งง
เอางี้ดีกว่า เพิ่มคำสั่ง
echo $sql;
ไว้ใต้คำสั่ง sql ที่่ใช้แล้วบอกมาว่ามันขึ้นว่ายังไง
Date :
16 ต.ค. 2551 14:01:40
By :
tacomsci
มันขึ้น
Select * From msc where Number like '%%'
อ่ะค่ะ
แล้วอีกอย่างนะ
ตอนนี้ตรง Remark อ่ะค่ะมันไม่ขึ้นด้วยค่ะ
Date :
16 ต.ค. 2551 15:54:52
By :
งง
Load balance : Server 05