2014-01-16 65 views
0

如何将此代码放入我的程序中的注册码中,如果注册成功,将弹出?我与jquery新,所以我不知道如何做这个东西...请帮助我的人请。在php代码中插入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!"; 
     } 
    } 
?> 

我想更换回声事情到jQuery代码...任何人都知道如何???

+0

好,最简单的解决办法是要回显jQuery代码。 –

+0

@YUNOWORK除了几乎是唯一的解决方案... – Ryan

+1

好吧,用PHP向DOM添加代码并不能提供太多的可能性^^我想你可以使用DOMDocument,但是这太多努力只为一个小文本框。 –

回答

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 
?> 
+0

您的缩进是可怕的人! – pythonian29033

+0

@ pythonian29033感谢兄弟 –

+0

没问题的人,下次再检查一下,我打算给出这个答案,但你是第一个 – pythonian29033

0

您可以简单地使用

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

尝试做这样的:

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