在php代码中插入jquery

时间:2014-01-16 08:34:32

标签: javascript php jquery

如何将此代码放入我的程序中的注册码中,如果注册成功,这会弹出?我是jquery的新手,所以我不知道如何做这些事情......请帮助我们。

<script>
$(document).ready(function() {
    // show a dialog box when clicking on a link
    $("#success").on('click', function(e) {
        e.preventDefault();
    $.Zebra_Dialog('<strong>Congratulations </strong>' + 
    'You are now successfully registered!');
    });
 });
</script>

这是我的PHP代码:

<?php
    if(isset($_POST['save'])) {
        $fname = $_POST['fname'];
        $lname = $_POST['lname'];
        $position = $_POST['position'];
        $username = $_POST['username'];
        $password = $_POST['password'];
        $dateregistered = date("Y-m-d H:i:s");
        if (!$_POST['fname'] || !$_POST['lname'] || !$_POST['position'] || !$_POST['username'] || !$_POST['password'] ) {
            echo "You did not complete all of the required fields!";
        } else {
            $query="INSERT INTO users (position, fname, lname, username,password,dateregistered) VALUES ('$position','$fname','$lname','$username','$password',CURRENT_TIMESTAMP) ";
            mysql_query($query);
            if($query)
            echo "You Successfully Created an Account!";
        }
    }
?>

我想将echo事物替换为jquery代码......任何人都知道如何???

4 个答案:

答案 0 :(得分:1)

追加jquery函数是你的php代码

<?php 

if(isset($_POST['save']))
{
   $fname = $_POST['fname'];
   $lname = $_POST['lname'];
   $position = $_POST['position'];
   $username = $_POST['username'];
   $password = $_POST['password'];
   $dateregistered = date("Y-m-d H:i:s");
   if (!$_POST['fname'] || !$_POST['lname'] || !$_POST['position'] || !$_POST['username'] || !$_POST['password'] ) 
   {
      echo "You did not complete all of the required fields!";
   }
   else
   {
      $query="INSERT INTO users (position, fname, lname, username,password,dateregistered)   VALUES ('$position','$fname','$lname','$username','$password',CURRENT_TIMESTAMP) ";
      mysql_query($query);
      if($query){
        echo "You Successfully Created an Account!";
        // append here your jquery code
        ?>
          <script>
             $(document).ready(function() {
                // show a dialog box when clicking on a link

                   $.Zebra_Dialog('<strong>Congratulations </strong>' + 
                      'You are now successfully registered!');

             });
          </script>
         <?php
      }
   }
}
//corrected indentation
?>

答案 1 :(得分:0)

您只需使用

即可
echo "<script>alert('You Successfully Created an Account!')</script>";

答案 2 :(得分:0)

尝试这样做:

if($query)
{
   ?>
      <script>
         $(document).ready(function() {
            $.Zebra_Dialog('<strong>Congratulations </strong>' + 
               'You are now successfully registered!');
         });
      </script>
    <?php
}

答案 3 :(得分:0)

    **Try this code.......**
    <?php 

    if(isset($_POST['save']))
    {
    $fname = $_POST['fname'];
    $lname = $_POST['lname'];
    $position = $_POST['position'];
    $username = $_POST['username'];
    $password = $_POST['password'];
    $dateregistered = date("Y-m-d H:i:s");
    if (!$_POST['fname'] || !$_POST['lname'] || !$_POST['position'] || !$_POST['username'] || !$_POST['password'] ) 
    {
echo "<script>
         $(document).ready(function() {
        $('#success').on('click', function(e) {
            e.preventDefault();
        $.Zebra_Dialog('<strong>Congratulations </strong>' + 
        'You did not complete all of the required fields!');
        });
     });
    </script>";
    }
    else
    {
       $query="INSERT INTO users (position, fname, lname, username,password,dateregistered)   VALUES ('$position','$fname','$lname','$username','$password',CURRENT_TIMESTAMP) ";
       if(mysql_query($query)){
           echo "<script>
         $(document).ready(function() {
        $('#success').on('click', function(e) {
            e.preventDefault();
        $.Zebra_Dialog('<strong>Congratulations </strong>' + 
        'You Successfully Created an Account!');
        });
     });
    </script>";
       }
    }
    }
    ?>