insert record from temp table to new table and also delete from temp table

Anil
<?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.

fsn

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to insert into a table from temp table?

From Dev

IF statement from a temp table

From Dev

bulk insert into temp table from a text file

From Dev

insert data from xml column into temp table

From Dev

How to insert data into temp table from a string

From Dev

MySQL Temp table Insert

From Dev

Insert into a Temp Table in a CTE

From Dev

SQL insert #TEMP table

From Dev

Temp table not dropping from DB

From Dev

Returning values from a temp table if another temp table returns no rows

From Dev

Returning values from a temp table if another temp table returns no rows

From Dev

Copy from one temp table to another temp table on condition base?

From Dev

Save return values from INSERT...RETURNING into temp table (PostgreSQL)

From Dev

Insert into temp table from stored procedure causes error

From Dev

How To Delete Rows From Temp Table With EntityDelete In CFSCRIPT

From Dev

Insert data from a table to a temporary table, and then select from the temp table specific rows

From Dev

Add new column to temp table based on values from a column

From Dev

Data from several temp tables to be consolidated in one temp table

From Dev

Data from several temp tables to be consolidated in one temp table

From Dev

Select from two temp tables into another temp table

From Dev

insert duplicate rows in temp table

From Java

Insert Data Into Temp Table with Query

From Dev

Insert result into temp table mariadb

From Dev

Insert Variable Into Temp Table Field

From Dev

insert duplicate rows in temp table

From Dev

Insert query results into temp table

From Dev

Informix - Delete temp table if exists

From Dev

TRUNCATE and INSERT from temporary table versus INSERT into non-temp table and RENAME

From Dev

mysql update table if record not in temp table

Related Related

  1. 1

    How to insert into a table from temp table?

  2. 2

    IF statement from a temp table

  3. 3

    bulk insert into temp table from a text file

  4. 4

    insert data from xml column into temp table

  5. 5

    How to insert data into temp table from a string

  6. 6

    MySQL Temp table Insert

  7. 7

    Insert into a Temp Table in a CTE

  8. 8

    SQL insert #TEMP table

  9. 9

    Temp table not dropping from DB

  10. 10

    Returning values from a temp table if another temp table returns no rows

  11. 11

    Returning values from a temp table if another temp table returns no rows

  12. 12

    Copy from one temp table to another temp table on condition base?

  13. 13

    Save return values from INSERT...RETURNING into temp table (PostgreSQL)

  14. 14

    Insert into temp table from stored procedure causes error

  15. 15

    How To Delete Rows From Temp Table With EntityDelete In CFSCRIPT

  16. 16

    Insert data from a table to a temporary table, and then select from the temp table specific rows

  17. 17

    Add new column to temp table based on values from a column

  18. 18

    Data from several temp tables to be consolidated in one temp table

  19. 19

    Data from several temp tables to be consolidated in one temp table

  20. 20

    Select from two temp tables into another temp table

  21. 21

    insert duplicate rows in temp table

  22. 22

    Insert Data Into Temp Table with Query

  23. 23

    Insert result into temp table mariadb

  24. 24

    Insert Variable Into Temp Table Field

  25. 25

    insert duplicate rows in temp table

  26. 26

    Insert query results into temp table

  27. 27

    Informix - Delete temp table if exists

  28. 28

    TRUNCATE and INSERT from temporary table versus INSERT into non-temp table and RENAME

  29. 29

    mysql update table if record not in temp table

HotTag

Archive