0

How to put this code in my registration code in my program that if the registration is successful this will pop-up?? I'm new with jquery so i dont know how to do this stuff...help me guys please.

<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>

here is my php 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 "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!";
        }
    }
?>

i want to replace the echo thing into jquery code...anyone know how???

4
  • Well, the easiest solution would be to echo out the jQuery code. Commented Jan 16, 2014 at 8:35
  • @YUNOWORK As well as being pretty much the only solution... Commented Jan 16, 2014 at 8:38
  • 1
    Well, adding code to the DOM with PHP doesnt offer much possibilites.^^ I guess you could work with DOMDocument, but thats too much effort only for a little textbox. Commented Jan 16, 2014 at 8:39
  • In my opinion it's the best solution to use an AJAX call and after succesfull callback show the popup(api.jquery.com/jquery.ajax).. You also could use a $_SESSION Commented Jan 16, 2014 at 8:45

4 Answers 4

1

append jquery function is your php 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 "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
?>
Sign up to request clarification or add additional context in comments.

1 Comment

no problem man, just check it next time, I was going to give this answer but you were first
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>";
       }
    }
    }
    ?>

Comments

0

You can simply use

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

Comments

0

Try to do like this:

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

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.