<?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'");
}
?>
I need help in inserting in 1 table and deleting from another table by clicking just add button. Its like adding in main table and deleting from the temp table. Please Help by correcting the above. If you suggest to move from old to new then please correct the code above and then show as I am a fresher in php.
the form is like this:
<form method="post" action="add2.php?id=<?php echo $row['id']?>" name="file" enctype="multipart/form-data">
...............
<input type="submit" name="add2" value="add" />
Please help as I am not getting any solution from anywhere.
Create connection:
$conn = new mysqli($servername, $username, $password, $dbname);
Prepare insert statement:
$sql = "INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('John', 'Doe', '[email protected]')";
Run your statement:
if (mysqli_query($conn, $sql)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
To delete:
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;
}
You can always:
echo $sql;
your statements to check if u have put "" in a correct way and what statement are you getting.
Also care that :
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.
You can read more here w3schools.com / SQL Tutorial
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments