1

The aim of my code is to send through two values, the primary key for delete qry purposes and second value for the user confirmation window, i.e. You are about to delete the record with the registration no: E12345.

On hover of the delete button, both values are showing as should be (as shown in image below), but the delete button isnt responding, so i assume its the script section that isnt functioning right, as im unsure how to call both vals, im sure its simple but i have very basic knowledge of javascript..

The code worked as expected before i tried implementing the double value through js, originally only had 'uid'

1
  • 1
    You need to surround the data you're passing to delete_user with quotes. Commented Feb 14, 2017 at 20:39

2 Answers 2

3

You should pass 2 parameters to your JS function.

Also, the reg parameter looks to be a string a should be quoted.

JS:

function delete_user(uid, reg) {
    if (confirm('Please confirm whether to delete the vehicle record with the Registration Number: ' + reg)) {
        window.location.href = '../php/clerk-delete.php?id=' + uid; 
    }
}

PHP:

echo '<a href="javascript:delete_user('.$get_info['VehicleId']. ','.htmlentities(json_encode($get_info['VehicleRegNo'])).')">&nbsp;Delete&nbsp;</a>'
Sign up to request clarification or add additional context in comments.

4 Comments

thanks for the above, i did copy & paste the code, tried both the php & the edit of xss injection, but both showed the same result, instead of coming out as in the image i originally posted, it now shows as 'javascript:delete_user(1,' so i assume its something to do with the quotes? and yes your correct the reg parameter is a string.
what if i call the var's like this: $id = $get_info["VehicleId"]; $reg = $get_info["VehicleRegNo"]; ... would this be easier to call in js?
@CS88 - You are right... I wrapped the output of json_encode with a call to htmlentities which should take care of escaping quote (") character.
Dana, you solved it! The code above worked without a hitch, thank you very much!
0

if you just change the + with , it works:

function delete_user(uid,reg) {
  if (confirm('Please confirm whether to delete the vehicle record with the       Registration Number: ' + reg)){
  window.location.href = '../php/clerk-delete.php?id=' + uid; 
  }
}

and then

echo '<a href="javascript:delete_user('.$get_info['VehicleId']. ','.$get_info['VehicleRegNo']. ')">&nbspDelete&nbsp</a>'

3 Comments

Thanks D.M for the suggestion, i did copy & paste, and the result was the same, the delete button isnt responding when clicked, the values are being shown in the bottom left of my screennlike the image i attached in the post
i think you are parsing variables in the function instead of strings so if you do this echo '<a href="javascript:delete_user("'.$get_info['VehicleId']. '","'.$get_info['VehicleRegNo']. '")">&nbspDelete&nbsp</a>' is gonna work
Created an error stating that the webpage is unable to handle the request, " & ' creating a problem somewhere

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.