tkw-dienthoai
<html>
<head>
<meta />
<title>ĐIỆN THOẠI - hehe</title>
</head>
<body>
<?php
$db = mysql_connect("localhost", "root", "123456");
if (!db) echo "Không thể kết nối tới CSDL";
mysql_select_db("dienthoai");
if(isset($_POST['madt'])) {
if($_POST['type'] == 'them') {
$sql = "INSERT INTO dienthoai (madt, tendt, tinhnang, gia, hang) VALUES ('{$_POST['madt']}', '{$_POST['tendt']}', '{$_POST['tinhnang']}', '{$_POST['gia']}', '{$_POST['hang']}')";
$query = mysql_query($sql);
if(!$query) {
exit(mysql_error());
}
} elseif($_POST['type'] == 'sua') {
$sql = "UPDATE dienthoai SET tendt='{$_POST['tendt']}', tinhnang='{$_POST['tinhnang']}', gia='{$_POST['gia']}', hang='{$_POST['hang']}' WHERE madt='{$_POST['madt']}'";
$query = mysql_query($sql);
if(!$query) {
exit(mysql_error());
}
}
}
if(isset($_GET['madt']) && $_GET[delete] == true) {
$sql="DELETE FROM dienthoai WHERE madt='{$_GET['madt']}'";
$query = mysql_query($sql);
}
if(isset($_GET['madt'])) {
$sql="SELECT * FROM dienthoai where madt='{$_GET['madt']}'";
$query = mysql_query($sql);
if(!$query) {
exit(mysql_error());
}
$row = mysql_fetch_array($query);
}
?>
<form>
<table>
<tr>
<td><p>Ma dien thoai: </p></td>
<td><input /></td>
</tr>
<tr>
<td><p>Ten dien thoai:</p></td>
<td><input /></td>
</tr>
<tr>
<td><p>Tinh nang: </p></td>
<td><input /></td>
</tr>
<tr>
<td><p>Gia: </p></td>
<td><input /></td>
</tr>
<tr>
<td><p>Hang: </p></td>
<td><select>
<?php
$sql="SELECT DISTINCT hang FROM dienthoai";
$query = mysql_query($sql);
while ($chonhang = mysql_fetch_array($query))
{
if (isset($row['hang']) && $chonhang['hang'] == $row['hang'])
echo '<option>'.$chonhang['hang'].'</option>';
else echo '<option>'.$chonhang['hang'].'</option>';
}
?>
</select></td>
</tr>
<tr>
<td><input />
<input /></td>
<td><input /></td>
</tr>
</table>
</form>
<?php
$sql="SELECT * FROM dienthoai";
$query = mysql_query($sql);
if (mysql_num_rows($query) == 0)
echo "Hien tai chua co CSDL";
else
{
echo '<table><tr><th>Mã ĐT</th>';
echo '<th>Tên ĐT</th>';
echo '<th>Giá</th>';
echo '<th>Hãng</th>';
echo '<th>Sửa</th>';
echo '<th>Delete</th></tr>';
while ($list = mysql_fetch_array($query))
{
echo '<tr><td>'.$list[madt].'</td>';
echo '<td>'.$list[tendt].'</td>';
echo '<td>'.$list[gia].'</td>';
echo '<td>'.$list[hang].'</td>';
echo '<td><a href=dienthoai.php?madt='.$list[madt].'>Edit</a></td>';
echo '<td><a href=dienthoai.php?delete=true&madt='.$list[madt].'>Xoa</a></td></tr>';
}
echo '</table>';
}
?>
</body>
</html>
Bạn đang đọc truyện trên: AzTruyen.Top