-2

So, I want to show a js alert to the user if they exist in a table called paymentindue. The table has a custom message column. I want the alert to show the custom message. I am using PHP to handle sql queries

    <?php 
include 'dbconn.php';
$name = $_SESSION['name'];
$email = $_SESSION['email'];

$sql = "SELECT * FROM users where email='$email' AND username = '$name'";
        $result = mysqli_query($conn, $sql);
        if (mysqli_num_rows($result) > 0){
            echo '<script>alert("<?php Custom message goes here?>")</script>';
        }
?>

But the problem is that I get the alert instead of the custom message

2 Answers2

0

You need to split your echo into two strings and a php variable to make this work.

$your_custom_message = 'Your message here'
echo '<script>alert("' . $your_custom_message . '")</script>'`
anatolhiman
  • 1,762
  • 2
  • 14
  • 23
0

It looks like you are trying to send php code to the user, which doesn't work. Instead, just compose the message in your script if needed.

$message = "something you compose here";
echo '<script>alert("'. $message .'")</script>';
mankowitz
  • 1,864
  • 1
  • 14
  • 32