Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
<?php
    include('functions.php');
    $id = $_GET['id'];

$query = "SELECT * FROM `listtap` WHERE `id` = '$id'; ";
    if(count(fetchAll($query)) > 0)
    {
        foreach(fetchAll($query) as $row)
       {
$id=$row['id'];
$name=$row['name'];
$taxno=$row['taxno'];
$noc=$row['noc'];
$c=$row['c'];
$date=$row['date'];    
    $query = "INSERT INTO `approvedtap` (`id`, `name`, `taxno`, `noc`,`c`,`date`,`message`,`status`) VALUES ('$id','$name','$taxno','$noc','$c','$date','rejected','unread') ;";
}
        $query .= "DELETE FROM `listtap` WHERE `listtap`.`id` = '$id';";       
 if(performQuery($query)){
            echo "Account has been rejected.";header("location:homeelectricity.php");
        }else{
            echo "Unknown error occured. Please try again.";
        }
}		
?>


What I have tried:

i need to select data and insert into another data and delete from there
Posted
Updated 29-Oct-19 9:52am
Comments
Richard Deeming 29-Oct-19 15:48pm    
REPOST
You have already posted this question.
Unknown error same code is running with another table[^]

1 solution

PHP
$query = "INSERT INTO `approvedtap` (`id`, `name`, `taxno`, `noc`,`c`,`date`,`message`,`status`) VALUES ('$id','$name','$taxno','$noc','$c','$date','rejected','unread') ;";

Not necessary a solution to your question, but another problem you have.
Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input a name like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability, and the crash is the least of the problems, a malicious user input and it is promoted to SQL commands with all credentials.
SQL injection - Wikipedia[^]
SQL Injection[^]
SQL Injection Attacks by Example[^]
PHP: SQL Injection - Manual[^]
SQL Injection Prevention Cheat Sheet - OWASP[^]
How can I explain SQL injection without technical jargon? - Information Security Stack Exchange[^]
 
Share this answer
 
Comments
Member 14636305 29-Oct-19 23:24pm    
Dear sir can you send me the exact code with needed modification
Member 14636305 29-Oct-19 23:37pm    
Dear sir
Can you change something and post it for me

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900