Php 在单击按钮时执行sql查询
我设计了一个表单,表单的值以表格的形式显示。在表格中,我有两列,分别是编辑和删除按钮。我想对id是表格中第一列的按钮执行更新和删除查询。 这是代码Php 在单击按钮时执行sql查询,php,mysql,Php,Mysql,我设计了一个表单,表单的值以表格的形式显示。在表格中,我有两列,分别是编辑和删除按钮。我想对id是表格中第一列的按钮执行更新和删除查询。 这是代码 <?php mysql_connect("localhost","root","")or die("Unable to create to connection"); mysql_select_db("sunil") or die(mysql_error()); if(isset($_REQUEST['submit'])) { $Id=
<?php
mysql_connect("localhost","root","")or die("Unable to create to connection");
mysql_select_db("sunil") or die(mysql_error());
if(isset($_REQUEST['submit']))
{
$Id= $_POST["id"];
$Name1=$_POST["t1"];
$Name2=$_POST["t2"];
$Sex=$_POST["sex"];
$Country=$_POST["Country"];
$Hobby=$_POST["check"];
$Email=$_POST["t3"];
$Pass=$_POST["p1"];
$Repass=$_POST["p2"];
$sql="INSERT INTO registration (Your_id,First_Name,Last_Name,Sex,Country,Hobbies,Email,Password,Repassword) VALUES('$Id','$Name1','$Name2','$Sex','$Country','$Hobby','$Email','$Pass','$Repass')";
mysql_query($sql);
}
$result = mysql_query("SELECT * FROM registration");
print "<table border=1>";
while($row = mysql_fetch_array($result))
{
print "<tr>";
print "<td>".$row['Your_id']."</td>";
print "<td>".$row['First_Name']."</td>";
print "<td>".$row['Last_Name']."</td>";
print "<td>".$row['Sex']."</td>";
print "<td>".$row['Country']."</td>";
print "<td>".$row['Hobbies']."</td>";
print "<td>".$row['Email']."</td>";
echo '<td><input type="submit" value="Edit" onclick="return update()"></td>';
// tell me code of update()
echo '<td><input type="submit" value="Delete" onclick="DELETE FROM registration WHERE Your_id=id"></td>';
// tell me what to use in place of is in this line
print "</tr>";
}
print "</table>";
?>
And here is snap shot
[1]: http://sunilpachlangia.blogspot.in/2013/11/blog-post.html
我给你一个基本的想法,你可以如何做到这一点。比什么是问题?两个查询都不工作….javascript不能运行你的sql查询,你必须使用ajax,这样你可以请求删除查询到另一个具有唯一id的php文件。我没有使用javascript,我的错误在哪里=“从注册中删除,其中您的_id=id”
和onclick=“return update()”
获取唯一的id是什么意思当我编写删除查询时,它会在C:\xampp\htdocs\sunil中出现解析错误:语法错误、意外的“FROM”(T_字符串)
print "<tr>";
print "<td>".$row['Your_id']."</td>";
print "<td>".$row['First_Name']."</td>";
print "<td>".$row['Last_Name']."</td>";
print "<td>".$row['Sex']."</td>";
print "<td>".$row['Country']."</td>";
print "<td>".$row['Hobbies']."</td>";
print "<td>".$row['Email']."</td>";
echo '<td><a href="req=update&id=UNIQUE_ID">edit</a>';
echo '<td><a href="req=delete&id=UNIQUE_ID">delete</a>';
print "</tr>";
if( isset($_GET['req']) ){
switch($_GET['req']){
case 'update':
// Get the Unique ID
// and perform your update query with update form
break;
case 'delete':
// Get the Unique ID
// and perform your delete query
break;
}
}