0

I have an image link in PHP that passes a variable to a script in a different file (functions.js), which is:

"img src=\"images/del.jpg\" onclick='delete_user_program(".$row1['program_name'].")' onmouseover=\"this.style.cursor='pointer'\" /"      

The script is:

   function delete_user_program(program_name){

    var confirmed = confirm("Are you sure;");
    if (confirmed == true){
        var str="./delete_user_program.php?p1="+program_name;
        window.location=str; 
    }
}     

I try to pass "p1".

Then the delete_user_program.php is:

<?php
    session_start();
    include("connect_db.php"); 
    $con = $_SESSION['connection'];


    $select_query ="SELECT * FROM user_program WHERE program_name='".$_GET['p1']."'";
    $result=@mysqli_query($con,$select_query) or die('Error, query failed');
    $num_result=mysqli_num_rows($result);


    if($num_result>0) {

        //some code
    }


 else {
        echo '<html><script language="javascript">alert("Program not exist.");</script></html>';

When calling delete_user_program.php I get the error that p1 is undefined and the message "Program not exist.". Any tips? Thanks in advance.

2 Answers2

0

You should use ajax.

$(document).ready(function(){
    function delete_user_program(program_name){

        $.get("./delete_user_program.php",
        {
          p1: program_name
        },
        function(data,status){
            alert("Data: " + data + "\nStatus: " + status);
        });
    }
});
0
<?php
  // file A.php
  echo 'A';
?>


<?php
  // file B.php;
  $a = file_get_contents('A.php');
  // thats synchron 
  echo $a;
?>
mtizziani
  • 956
  • 10
  • 23
  • While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value. – Donald Duck Mar 17 '17 at 18:55