Asım Gündüz
Asım Gündüz

Reputation: 1297

Displaying jquery alerts with PHP

Hi I'm new to PHP and everything is very confusing to me. What I'm trying to do and fail is to display an alert on the screen on click of a button on the page.

my Code signInFunction.php:

<?php
if(isset($_POST['signIn'])){
    if(isset($_POST['username']) and isset($_POST['password'])){
        $username = $_POST['username'];
        $password = $_POST['password'];

        ?>
        <script type="text/javascript">alert("test");</script>
        <?php
        echo "username is: ".$username." and password is: ". $password;
    }
    else{
        echo "Please enter username and password";
    }
}
else{
    echo "error button";
}
?>

in the index.php file looks like this:

  <?php include "includes/header.php" ?>
  <?php include "includes/navbar.php" ?>
  <?php include "includes/carousel.php"?> 
  <?php include "includes/marketing.php"?> 
  <?php include "includes/features.php"?>
  <?php include "includes/hidden.php"?>
  <?php include "includes/footer.php" ?>
  <?php include "includes/functions/signinFunction.php"?>

The Problem is that I manage to display the data at the bottom but fail to make the alert appear.. what am I missing?

Upvotes: 0

Views: 67

Answers (2)

Vijay Astound
Vijay Astound

Reputation: 75

echo '<script language="javascript">';
echo 'alert("alert")';
echo '</script>';

Upvotes: -1

Matzy schneider
Matzy schneider

Reputation: 118

<form action="" method="post" >
   <input name='username' type='text' value=''/>
   <input name='password' type='text' value='' />
   <input type='button' name='signIn' value='Sign In' />
</form>
<?php
if(isset($_POST['signIn'])){
    if(isset($_POST['username']) and isset($_POST['password'])){
        $username = $_POST['username'];
        $password = $_POST['password'];

        ?>
        <script type="text/javascript">alert("test");</script>
        <?php
        echo "username is: ".$username." and password is: ". $password;
    }
    else{
        echo "Please enter username and password";
    }
}
else{
    echo "error button";
}
?>

when u click on the sign in button then that alert should appear

Upvotes: 2

Related Questions