-1

Basically I have a client table and a leadlist for potential leads and I need to transfer the leads to the clients once they have been done, and delete them from the original table with an export button.

I've already tried a few possible things like select from CData ...... and insert into leadlist, but it hasn't worked

My leadselect.php:

$(document).on('click', '.export', function(){
        var user_id = $(this).attr("id");
        if(confirm("Are you sure you want to export this?"))
        {
            $.ajax({
                url:"export.php",
                method:"POST",
                data:{user_id:user_id},
            success:function(data)   

My export.php:

 <<?php

include('db.php');
include("function.php");

insert into leadlist
  select * from CData
 ?

button is defined as

$sub_array[] = '<button type="button" name="export" id="'.$row["id"].'" class="btn btn-warning btn-xs export">Export</button>';

My expected result is for it to export the row of data that I choose to the leadlist and delete it.

Could you please advise me how I can approach this requirement?

4
  • You're not using $_POST['user_id'] in export.php.
    – Barmar
    Commented Jul 3, 2019 at 16:51
  • will that fix it ?
    – murray5567
    Commented Jul 3, 2019 at 16:52
  • Do the leadlist and CData tables have the same columns?
    – Barmar
    Commented Jul 3, 2019 at 16:52
  • ye exactly the same sorry i dont know if this is a stupid question or not im young and me and my friend have our own customer management systems company
    – murray5567
    Commented Jul 3, 2019 at 16:54

1 Answer 1

-3

You need to use $_POST['user_id'] in the queries to insert and delete the appropriate rows for that user.

Use prepared statements to prevent SQL injection when using the parameter.

$insert_stmt = $conn->prepare("INSERT INTO leadlist SELECT * FROM CData WHERE user_id = ?") or die($conn->error);
$insert_stmt->bind_param("i", $_POST['user_id']);
$insert_stmt->execute() or die($insert_stmt->error);
$delete_stmt = $conn->prepare("DELETE FROM CData WHERE user_id = ?") or die($conn->error);
$delete_stmt->bind_param("i", $_POST['user_id']);
$delete_stmt->execute() or die($delete_stmt->error);

Replace user_id in the queries with the actual name of the column that holds the user ID in your table.

DEMO

1
  • Comments are not for extended discussion; this conversation has been moved to chat. Commented Jul 4, 2019 at 1:39

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.