Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    moving data from one table to another

    I am new to php, mysql, I have 2 tables (table1 and table2) and wish to move data from table1 to table2 with after inserting the required parameter in the form field and clicking submit button in form. It then opens a fresh page named "register.php after the code has been executed.

    I am having problem with this code as it fails to execute. Please help me in resolving this problem.
    here is the form:
    Code:
    <form action="discharge.php" method="post"> 
            <p>INSERT STUDENT'S REGISTRATION NUMBER
              <input type="text" name="reg_number" value="">
            </p>
            <p>
              <input type="submit" value="Submit"> 
                            </p>
    	  </form>

    and
    here is my discharge.php code:

    Code:
    <?php
        //session_start();
        include('connect.php');
    
        // username and password sent from form 
        $reg_number=$_POST["reg_number"];
    
        $sql="INSERT INTO table2 (reg_number, surname,first_name, othername, gender) 
        SELECT reg_number, surname,first_name, othername, gender FROM table1 WHERE reg_number='$reg_number'";
    
        DELETE * FROM table1 WHERE reg_number='$reg_number'";
        $result=mysql_query($sql);
        if(!$result)
    	{
          header ("location:register.php");
         } 
       
    
        ?>

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,028
    Thanks
    2
    Thanked 315 Times in 307 Posts
    It's generally a bad design to move data between tables when the status of that data changes. A simpler approach would be to have a status column in the table that you update a value in to indicate what state the data is at.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #3
    New to the CF scene
    Join Date
    Jun 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am confuse with the whole thing, I have read it before that one could do it it like this. But is there anything that i didn't get right in the code. Thanks for your time.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •