-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

3

2 Answers 2

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>'`
Sign up to request clarification or add additional context in comments.

1 Comment

That won't work. You are sending raw php to the user.
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>';

Comments

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.