実際にphpで新しいです、私はPHPでページを取得しています。データベースからデータをフェッチしている場所で、自動生成されたテーブルに表示されます。私は2つのボタンも追加しました。 1つはデータベースから特定の行を削除し、もう1つはデータベースから詳細を編集するためのものです。データベースのemail_id列は一意です。したがって、両方の削除編集操作はemail_idによって行います。編集や削除のためのAjax関数の記述方法について教えてください。コードはphp、mysqlの自動生成テーブルの編集と削除の方法
<html>
<head>
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title><!--Dquip--></title>
<link href="http://fonts.googleapis.com/css?family=Abel|Arvo" rel="stylesheet" type="text/css" />
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="jquery.dropotron-1.0.js"></script>
<script type="text/javascript" src="jquery.slidertron-1.0.js"></script>
<style>
label
{
display:inline-block;
width:150px;
margin-right:10px;
text-align:;
}
table,tr,th,td
{
border: 2px solid dodgerblue;
border-collapse: separate;
}
table
{
width:75%;
margin-top: 8%;
}
th,td
{
height: 50px;
}
td
{
text-align:center;
vertical-align: middle;
}
.button
{
width:75px;
height: 25px;
background-color:dodgerblue;
color:white;
border:1px solid transparent;
}
</style>
<center>
<script>
function deleteABC()
{
}
function editABC()
{
}
</script>
</head>
<body>
<h4 align="right"><a href="loginpage.php">Logout</a></h4>
<body>
<div id="wrapper">
<div id="header-wrapper">
<div id="header">
<div id="logo">
<h1><a href="#">..</a></h1>
</div>
</div>
<div id="menu-wrapper">
<ul id="menu">
<li class="current_page_item"><a href="calenderindex.html"><span>Homepage</span></a></li>
<li><span>Blog</span>
<ul>
<li class="first"> <a href="index">About US</a> </li>
<li> <a href="search">Function Area</a> </li>
<li class="last"> <a href="about">Contact US</a> </li>
</ul>
</li>
<li><a href="#"><span>Photos</span></a></li>
<li><a href="#"><span>About</span></a></li>
<li><span>Datas</span>
<ul>
<li class="first"> <a href="index.php">Add Details</a> </li>
<li> <a href="map.php">Map view</a> </li>
<li class="last"> <a href="fetchinghome.php">view Details</a> </li>
</ul>
</li>
<li><a href="contact.php"><span>Contact</span></a></li>
</ul>
<script type="text/javascript">
$('#menu').dropotron();
</script>
</div></br>
<h1><font color="white">Enter the dates to retrieve the data</font></h1></br></br>
<form method="POST" action="fetchinghome.php">
<label>Role ID:</label><input type="text" name="role" placeholder="Enter the starting date">
<input type="submit" id="submit" name="submit" value="Go" class="button">
</form>
<?php
//include "loginpage.php";
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
if(isset($_POST['submit']))
{
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "calender";
$role=$_REQUEST['role'];
$conn = mysqli_connect($servername, $username, $password, $dbname);
if(! $conn)
{
die('Could not connect: ' . mysqli_error());
}
if ($role == 'admin')
{
$sql="SELECT * FROM registration";
}
elseif($role=="M%")
{
$sql="SELECT * FROM registration where reporting_manager='$role' or role='$role'";
}
else
{
$sql="SELECT * FROM registration WHERE role='$role'";
}
// $sql="SELECT * FROM registration where reporting_manager='$role'";
$retval = mysqli_query($conn,$sql);
if(! $retval)
{
die('Could not get data: ' . mysqli_error($conn));
}
$arr;
$i=0;
while($row = mysqli_fetch_assoc($retval))
{
$arr[$i]=$row;
$i++;
/*
echo "<tr><td>";
echo $row[0]."</td><td>";
echo $row[1]."</td><td>";
echo $row[2]."</td><td>";
echo $row[3]."</td><td>";
echo $row[4]."</td>";
echo "</tr>";
*/
}
$str='';
for($i=0;$i<count($arr);$i++)
{
$brn='<input type="button" value="Delete" onClick="deleteABC('.$arr[$i]['email_id'].')">';
$brn1='<input type="button" value="Edit" onClick="editABC('.$arr[$i]['email_id'].')">';
$str=$str . '<tr><td>'. $arr[$i]['name'].'</td><td>'.$arr[$i]['email_id'].'</td><td>'.$arr[$i]['mobile_no'].'</td><td>'.$arr[$i]['address'].'</td><td>'.$arr[$i]['role'].'</td><td>'.$brn.'</td><td>'.$brn1.'</td></tr>';
}
echo "<table id='example' class='display' cellspacing='0' width='100%'>
<tr>
<th>Name</th>
<th>Email</th>
<th>Mobile Number</th>
<th>Address</th>
<th>Role</th>
<th>Delete</th>
<th>Edit</th>
</tr>".$str."</table>";
}
echo "Fetched data successfully\n";
mysqli_close($conn);
}
?>
</body>
</html>
Please help me to write the Ajax function for those.
Thanks in advance
以下の通りです** WARNING **:あなたは、[パラメータ化クエリ]を使用する必要がありmysqli' '使用している場合(http://php.net/manual/en/mysqli.quickstart.prepared -statements.php)と['bind_param'](http://php.net/manual/en/mysqli-stmt.bind-param.php)を使ってクエリにユーザーデータを追加します。 **重大な[SQLインジェクションのバグ](http://bobby-tables.com/)を作成したため、文字列の補間または連結を使用してこれを実行しないでください。 ** '$ _POST'や' $ _GET'データを直接クエリに入れないでください。誰かがあなたのミスを悪用しようとすると、非常に危険です。 – tadman