Reputation: 277
I want to display the PHP variable in sweet alert but unable to find the solution, I went through the documentations of sweet alert 2 but couldn't find anything. Can anyone help me?
here's my code
$name = "xyz";
//sweetalert code
echo "<script>";
echo 'setTimeout(function () { swal("Greetings $name!","Thank you for adding your business details.<br>Our admin team will review the same and will publish shortly..!","success");';
echo '}, 100);</script>';
Upvotes: 1
Views: 5504
Reputation: 135
You need to concatenate it, try to use the following:
echo 'setTimeout(function () { swal("Greetings"'.$name.'"!","Thank you for adding your business details.<br>Our admin team will review the same and will publish shortly..!","success");';
Upvotes: 0
Reputation: 13303
Just need to switch the quotes:
echo "setTimeout(function () { swal('Greetings $name!','Thank you for adding your business details.<br>Our admin team will review the same and will publish shortly..!','success');'";
Or, another option, concatenate variables within string:
echo 'setTimeout(function () { swal("Greetings ' . $name . '!","Thank you for adding your business details.<br>Our admin team will review the same and will publish shortly..!","success");';
When you include a variable inside echo, you need to use "
Know difference between "
and '
another SO Answer
Upvotes: 2