2014-01-16 94 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>"; 
     } 
    } 
    } 
    ?>