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.