Reputation: 20555
I have the following php code:
<?php
if (isset($_POST['submitLogin'])) {
$password = $_POST['password'] ;
$username = $_POST['username'];
if (invalidChars($username, $password) > 0){
echo '<script type="text/javascript">'
, 'alert(fejl);'
, '</script>';
}
}
function invalidChars($user, $password){
$invalidPattern = "/[^A-Za-z0-9]/";
return preg_match($invalidPattern, $user) + preg_match($invalidPattern, $password);
}
?>
However when then function invalidChars > 0 no alert is displayed.
Can anyone tell me what I'm doing wrong? im rather new to web development
Upvotes: 0
Views: 67
Reputation: 20199
To pass string fejl in double quotes
if (invalidChars($username, $password) > 0){
echo '<script type="text/javascript">' , 'alert("fejl");' , '</script>';
}
Upvotes: 2
Reputation: 41958
Put double quotes around the string to be alerted: alert("fejl")
, otherwise it's just a syntax error. Press F12 in your browser and open the error console to easily spot problems like this.
Upvotes: 0
Reputation: 15229
The objet fejl
you passed in to alert does not exist. This should be causing a javascript error. I think you want to pass in the object "fejl"
which is a string that alert will render.
Upvotes: 2