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

Andrei Zhamoida
1,4632 gold badges21 silver badges32 bronze badges
asked Jan 16, 2014 at 8:34
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
?>
answered Jan 16, 2014 at 8:39
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>";
 }
 }
 }
 ?>
answered Jan 16, 2014 at 8:46

Comments

0

You can simply use

echo "<script>alert('You Successfully Created an Account!')</script>";
Aniket Kulkarni
13k10 gold badges70 silver badges94 bronze badges
answered Jan 16, 2014 at 8:39

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
}
answered Jan 16, 2014 at 8:42

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.