کلا کد برنامه من این هست.ابتدا یه فرم html که داده رو میگیره:
کد HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Language" content="en-us" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled 1</title>
<style type="text/css">
.style1 {
font-size: x-large;
}
</style>
</head>
<body>
<p class="style1"><strong>Insert</strong></p>
<form method="post" action="test.php">
username: <input name="user1" style="height: 22px" /><br />
password: <input name="pass1" /><br />
<input name="Reset1" type="reset" value="reset" />
<input name="Submit1" type="submit" value="submit" /></form>
</body>
</html>
=============
فایل بعد کار insert رو انجام میده:
نام فایل: test.php
<html>
<head>
<meta http-equiv="Content-Language" content="php; charset=utf-8" />
<meta http-equiv="Content-Type" content="php; charset=utf-8" />
<body>
<?php
$db=mysql_connect("127.0.0.1","root","");
mysql_select_db('mydb',$db);
$query="SELECT * FROM users";
$result=mysql_query($query,$db);
$num=mysql_num_rows($result);
//***************INSERT*****************
$user1=htmlspecialchars($_POST['user1']);
$pass1=htmlspecialchars($_POST['pass1']);
$query="insert into users(username,password) value ('".$user1."','".$pass1."')";
$result=mysql_query($query);
mysql_close();
print('<p><a href="insert.htm"> Insert Again</a></p><p><a target="_blank" href="db.php"> Show Data</a></p>');
?>
</body>
</head>
</html>
======================
این فایل هم اطلاعات ذخیره شده رو نمایش میده.فقط برای هر رکورد یک چک باکس قرار دادم که اگر کاربر خواست چند رکورد رو حذف کنه ، جلوی هر رکورد تیک میزنه و در آخر برای انجام عملیات حذف دکمه submit پایین جدول رو میزنه.
نام فایل: db3.php
<html>
<body>
<?php
$db=mysql_connect("127.0.0.1","root","");
if($db)
print("Connection Sucsessful!");
else
print("Connection Failed!");
mysql_select_db('mydb',$db);
$query="SELECT * FROM users";
$result=mysql_query($query,$db);
$num=mysql_num_rows($result);
//********************************************
echo "<form method='post' action='delete.php'>";
echo "<table border=1>";
for ($i=0;$i<$num;$i++)
{
$row=mysql_fetch_array($result);
echo "<tr><td>".($i+1)."</td>";
echo "<td>".@mysql_result($result,$i,0)."</td>";
echo "<td>".@mysql_result($result,$i,1)."</td>";
print('<td><input name="'.$i.'" type="checkbox" /></td></tr>');
}
echo "</table>";
echo "<input name='Submit1' type='submit' value='submit' /></form>";
//number of rows:
echo "Rows number:".mysql_affected_rows($db);
//end
//delete
mysql_query("delete from users where username='100'");
//
?>
</body>
</html>
برای انجام کار delete هم این فایل وجود داره که داده های ورودیش رو از فایل قبلی (همون رکوردهای تیک خورده) میگیره.
نام فایل: delete.php
<html>
<body>
<?php
$db=mysql_connect("127.0.0.1","root","");
/*
if($db)
print("Connection Sucsessful!");
else
print("Connection Failed!");
*/
mysql_select_db('mydb',$db);
$query="SELECT * FROM users";
$result=mysql_query($query,$db);
$num=mysql_num_rows($result);
//********************************************
for($i=0;$i<$num;$i++)
{
if(!empty($_POST[$i]))
{
mysql_query("delete from users where username=".@mysql_result($result,$i,0)."");
echo @mysql_result($result,$i,0)." Delete.<br>";
}
}
?>
</body>
</html>
این تمام یه برنامه بود که نوشتمش
ممنون