1

to get the values from two tables using unique ID and insert into another single table, this is my code, example: "table1" values and "table2" values copy and insert into "table3", finally delete the original values from old table.

 <?php
ini_set('display_errors', 0);
include 'connection/db_connection.php';
$memberid=$_POST['memberid'];
$query=mysql_query("INSERT INTO existing_member (member_id,member_name,dob,gender,address,city,state,phone,email,height,weight,bmi,bp,medical,image_path,joining_date)
 SELECT member_id,member_name,dob,gender,address,city,state,phone,email,height,weight,bmi,bp,medical,image_path,joining_date FROM member_registration
 WHERE member_id='".$memberid."'" ); 

 /*
$query2=mysql_query("INSERT INTO existing_member (membership_type) SELECT membership_type  FROM membership_details
WHERE member_id='".$memberid."'"); */

 $query2=mysql_query("INSERT INTO existing_member (membership_type)
 SELECT a.membership_type as membership_type FROM membership_details a
INNER JOIN member_registration c ON c.member_id = a.member_id, c.member_name=a.member_name
where a.member_id='".$memberid."'");

if($query2)
{ 
    //$sql=mysql_query("DELETE FROM member_registration WHERE member_id='".$memberid."'");
    //$sql1=mysql_query("delete from membership_details where member_id='".$memberid."'");

    echo "<script>
                alert('Data Deleted Successfully');
                window.location.href='close_member.php';
                </script>"; 
} 
else
{
echo "User Data Already Exist";
}
1
  • 2
    Seems you forgot the question. Commented Dec 23, 2014 at 12:22

1 Answer 1

0

You have a typo in your first query: INSERT INTO existing_membe forgot an r at the end of it.

Also a missing y at here: if($quer and $query2)

NOTE

  • Do not use mysql functions, they are deprecated. Use mysqli or PDO instead.

  • To avoid sql injection attacks, escape your variables what comes from users through GET or POST or use prepared statements.

Sign up to request clarification or add additional context in comments.

1 Comment

now i corrected the errors, how to write code for two table values are copy to insert another single table,

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.