<?php
include("conn.php");
?>
<?php
$id=$_GET['id'];
$name=$_POST['name'];
$fathers_name=$_POST['fathers_name'];
$gotra=$_POST['gotra'];
$image=$_POST['image'];
$village=$_POST['village'];
$company_name=$_POST['company_name'];
$address1=$_POST['address1'];
$address2=$_POST['address2'];
$city=$_POST['city'];
$pincode=$_POST['pincode'];
$mobile1=$_POST['mobile1'];
$mobile2=$_POST['mobile2'];
$village_number=$_POST['village_number'];
if($_POST['add2'])
{
$i=mysql_query("insert into members_data values(NULL,'".$name."','".$fathers_name."','".$gotra."','".$image."','".$village."','".$company_name."','".$address1."','".$address2."','".$city."','".$pincode."','".$mobile1."','".$mobile2."','".$village_number."')");
$res=mysql_query("SELECT id FROM temp_members_data WHERE 'id' = '$id'");
$row=mysql_fetch_array($res);
mysql_query("DELETE FROM temp_members_data WHERE 'id' = '$id'");
}
?>
我需要帮助才能插入1个表并通过单击“添加”按钮从另一个表中删除。它就像在主表中添加并从临时表中删除一样。请通过纠正以上内容来帮助。如果你建议从旧到新,那么请更正上面的代码然后显示我是一个更新的PHP。
表格是这样的:
<form method="post" action="add2.php?id=<?php echo $row['id']?>" name="file" enctype="multipart/form-data">
...............
<input type="submit" name="add2" value="add" />
请帮忙,因为我无法从任何地方获得任何解决方案。
答案 0 :(得分:0)
创建连接:
$conn = new mysqli($servername, $username, $password, $dbname);
准备插入声明:
$sql = "INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('John', 'Doe', 'john@example.com')";
运行你的陈述:
if (mysqli_query($conn, $sql)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
要删除:
sql to delete a record
$sql = "DELETE FROM temp_members_data WHERE id= '".$id."'";
if ($conn->query($sql) === TRUE) {
echo "Record deleted successfully";
} else {
echo "Error deleting record: " . $conn->error;
}
你可以随时:
echo $sql;
你的陈述,以检查你是否以正确的方式放置“”以及你得到了什么声明。
还要关心:
Warning: This extension (mysql) is deprecated as of PHP 5.5.0, and will
be removed in the future. Instead, the MySQLi or PDO_MySQL extension
should be used.
您可以在此处阅读更多内容w3schools.com / SQL Tutorial