Results 1 to 8 of 8

Thread: Create alert box in PHP

  1. #1
    Join Date
    Aug 2007
    Location
    Malaysia
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Create alert box in PHP

    I would like to transform the following php statement in order to get displaying in alert box.

    PHP Code:
    die("The email address '" $_POST['email'] ."' is already registered"); 
    I tried to transform it with print statement but seems like not work.

    PHP Code:
    print "<script type=\"text/javascript\">";
    print 
    "alert('The email address '" $_POST['email'] ."' is already registered')";
    print 
    "</script>"

  2. #2
    Join Date
    May 2006
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    PHP Code:
    print '<script type="text/javascript">';
    print 
    'alert("The email address '$_POST['email'].' is already registered")';
    print 
    '</script>'
    The above works for me. Just used single quotes for print and got rid of the backslashes.

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Better:
    Code:
    ?>
      <script type="text/javascript">
        alert("The email address <?php echo $_POST['email']; ?> is already registered.");
        history.back();
      </script>
    <?php
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Aug 2007
    Location
    Malaysia
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Twey View Post
    Better:
    Code:
    ?>
      <script type="text/javascript">
        alert("The email address <?php echo $_POST['email']; ?> is already registered.");
        history.back();
      </script>
    <?php
    Thanks...my screen can remain in signup page.However,why data still insert into database for twice?

    PHP Code:
    <?php
    //ini_set("include_path", "path/to/language/file");
    include ('dbconn.cfg');

    //global variable
    $tbl_name "member";
    //$table2 = "registered_member";

    //Random confirmation code
    //$confirm_code = md5(uniqid(rand()));

    //This code runs if the form has been submitted
    if (isset($_POST['submit']))
    {

        
    // checks if the email address is alredy registered
        //if (!get_magic_quotes_gpc())
        //{
        //$_POST['email'] = addslashes($_POST['email']);
        //}
        
    $emailcheck $_POST['email'];
        
    $check mysql_query("SELECT email FROM $tbl_name WHERE email = '$emailcheck'") or
            die(
    mysql_error());
        
    $check2 mysql_num_rows($check);

        
    //if the name exists it gives an error
        
    if ($check2 != 0)
        {
    ?>
      <script type="text/javascript">
        alert("The email address <?php echo $_POST['email']; ?> is already registered.");
        history.back();
      </script>
    <?php

            
    //die("The email address '" . $_POST['email'] ."' is already registered");
            //print '<script type="text/javascript">';
            //print 'alert("The email address ' . $_POST['email'] .' is already registered")';
            //print '</script>';

        
    }

        
    // encrypt the password
        
    $pass1 md5($pass1);
        
    //if (!get_magic_quotes_gpc())
        //{[]
        //pass1 = addslashes($pass1);
        //$_POST['member_id'] = addslashes($_POST['member_id']);

        //Insert record to database
        
    $insert mysql_query("INSERT INTO $tbl_name(name,email,password,telephone,address)
                              VALUES ('" 
    $_POST['name'] . "','" $_POST['email'] .
            
    "', '" $_POST['pass1'] . "','" $_POST['tel'] . "','" $_POST['address'] .
            
    "')") or die(mysql_error());


        
    // }

        //if successfully inserted,send confirmation link to email
        
    if ($insert)
        {

            
    //echo "Thank for your registration!";
            //header("Location: http://localhost/www/index.php?frame=thankyou");
            
    $redirectUrl "http://localhost/www/index.php?frame=thankyou";
            print 
    "<script type=\"text/javascript\">";
            print 
    "window.location.href = '$redirectUrl'";
            print 
    "</script>";

            
    /*
            require ("class.phpmailer.php");

            $mail = new PHPMailer();
            $mail->IsSMTP();
            $mail->Host = "localhost";
            $mail->SMTPAuth = true;// turn on SMTP authentication
            $mail->Username = "admin";// SMTP username
            $mail->Password = "itc309";// SMTP password
            //$mail->SetLanguage("en","phpmailer/language");

            //compose mail
            $mail->From = "admin@localhost.com";
            $mail->FromName = "Cinema Admin";
            $mail->AddAddress($_POST['email']);
            $mail->AddReplyTo("admin@localhost.com", "cinema admin");
            $mail->Subject = 'Your confirmation link here';
            $mail->Body = "Your confirmation link\r\n";
            $mail->Body .= "Click on this link to activate your sccount\r\n";
            $mail->Body .= "http://localhost/www/confirm.php?passkey=$confirm_code";


            //send mail
            if (!$mail->Send())
            {
            echo "Message was not sent <p>";
            echo "Mailer Error: " . $mail->ErrorInfo;
            exit;
            }

            echo "Message has been sent";
            }

            //if not found
            else
            {
            echo "Not found your email in our database";
            }

            if your email successfully sent
            if ($sentmail)
            {
            echo "Your confirmation link has been sent to your email address.";
            }*/

        
    }
    }
    ?> 


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>New User Registration</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script language="JavaScript" type="text/JavaScript">
    function formSubmit() 
    {
      window.event.returnValue = false;
     
       if ((!form1.name.value) | (!form1.email.value)| (!form1.pass1.value ) | (!form1.pass2.value) |(!form1.tel.value) | 
           (!form1.address.value)){alert("You did not complete all of the required fields");}
      else if (form1.pass1.value.length < 5 | form1.pass1.value.length >12) 
         {alert("Password must be within 6-20 characters!");form1.pass1.focus()}
      else  if (form1.pass1.value != form1.pass2.value) {alert("Your password does not match");form1.pass2.focus();} 
      else  window.event.returnValue = true;
    }
    </script>
    </head>

    <body bgcolor="#000000">
    <div align="center"></div>
    <table width="80%" height="523" border="0" align="center" bgcolor="#CCCCFF">
      <tr> 
        <td width="2%" rowspan="4">&nbsp;</td>
        <td width="98%" height="58"> <div align="center"><font face="Arial, Helvetica, sans-serif"></font></div></td>
      </tr>
      <tr> 
        <td height="315" bgcolor="#CCCCFF"> 
          <div align="left"> 
            <table width="100%" border="0">
              <tr> 
                <td height="54" bgcolor="#CCCCFF"><font size="+3" face="Arial, Helvetica, sans-serif">Member 
                  Registration</font></td>
              </tr>
              <tr> 
                <td height="20" bgcolor="#CCCCFF"><div align="left"><font face="Arial, Helvetica, sans-serif"><img src="images/line.JPG" width="750" height="4"></font></div></td>
              </tr>
              <tr> 
                <td height="39" bgcolor="#CCCCFF"><font face="Arial, Helvetica, sans-serif"><em><strong>Important 
                  Notice:</strong></em></font> </td>
              </tr>
              <tr> 
                <td bgcolor="#CCCCFF"><font face="Arial, Helvetica, sans-serif">1. 
                  All fields provided must be filled in.</font></td>
              </tr>
              <tr> 
                <td bgcolor="#CCCCFF"><font face="Arial, Helvetica, sans-serif">2. 
                  Please fill in the fields accurately as important details are vital 
                  to access functions such as ticket &nbsp;&nbsp;&nbsp;&nbsp;reservations.</font></td>
              </tr>
              <tr> 
                <td bgcolor="#CCCCFF"><font face="Arial, Helvetica, sans-serif">3. 
                  Please use your email address as user id to login </font></td>
              </tr>
              <tr> 
                <td bgcolor="#CCCCFF"><font face="Arial, Helvetica, sans-serif">4. 
                  Password must be between 6-12 characters and is case sensitive.</font></td>
              </tr>
              
              <tr> 
                <td height="40" bgcolor="#CCCCFF"><div align="left"><font face="Arial, Helvetica, sans-serif"><img src="images/line.JPG" width="750" height="4"></font></div></td>
              </tr>
            </table>
          </div></td>
      </tr>
      <tr>
        <td height="94"><form name="form1" method="post" action="http://localhost/www/index.php?frame=signup">
            <table width="100%" border="0">
              <tr> 
                <td width="25%"><font face="Arial"><strong>Login Details</strong></font></td>
                <td width="4%">&nbsp;</td>
                <td width="71%">&nbsp;</td>
              </tr>
              <tr> 
                <td height="29"><font face="Arial">Email Address</font></td>
                <td width="4%">&nbsp;</td>
                <td><font face="Arial"> 
                  <input name="email" type="text">
                  </font></td>
              </tr>
              <tr> 
                <td height="27"><font face="Arial">Password</font></td>
                <td width="4%">&nbsp;</td>
                <td><font face="Arial"> 
                  <input name="pass1" type="password" maxlength="20">
                  </font></td>
              </tr>
               <tr> 
                <td height="27"><font face="Arial">Confirm Password</font></td>
                <td width="4%">&nbsp;</td>
                <td><font face="Arial"> 
                  <input name="pass2" type="password" id="password6" maxlength="20">
                  </font></td>
              </tr>
              <tr> 
                <td>&nbsp;</td>
                <td width="4%">&nbsp;</td>
                <td>&nbsp;</td>
              </tr>
              <tr> 
                <td><font face="Arial"><strong>Member Details</strong></font></td>
                <td width="4%">&nbsp;</td>
                <td>&nbsp;</td>
              </tr>
              <tr> 
                <td height="30"><font face="Arial">Full Name</font></td>
                <td width="4%">&nbsp;</td>
                <td><font face="Arial"> 
                  <input name="name" type="text" size="40">
                  </font></td>
              </tr>
                      
              <tr> 
                <td height="26"><font face="Arial">Telephone Number</font></td>
                <td width="4%">&nbsp;</td>
                <td><font face="Arial"> 
                  <input name="tel" type="text"  size="20" maxlength="10">
                  (Example: 0123334444, 0323459744)</font></td>
              </tr>
              <tr> 
                <td height="24"><font face="Arial">Address</font></td>
                <td width="4%">&nbsp;</td>
                 <td><label>
                   <textarea name="address" rows="3"></textarea>
                   </label></td>
              </tr>
            
              <tr> 
                <td>&nbsp;</td>
                <td width="4%">&nbsp;</td>
                <td> </tr>
              <tr> 
                <td>&nbsp;</td>
                <td width="4%">&nbsp;</td>
                <td><input type="submit" name="submit" value="Submit" onClick="formSubmit()"> &nbsp;
                    <input name="reset" type="reset" id="Reset2" value="Reset"> 
                </td>
              </tr>
            </table>
            <label></label>
        </form></td>
      </tr>
      <tr> 
        <td height="37">
    <div align="center"></div>
    </td>
      </tr>
    </table>
    </body>
    </html>

  5. #5
    Join Date
    Aug 2007
    Location
    Malaysia
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by devil_vin View Post
    Thanks...my screen can remain in signup page.However,why data still insert into database for twice?

    PHP Code:
    <?php
    //ini_set("include_path", "path/to/language/file");
    include ('dbconn.cfg');

    //global variable
    $tbl_name "member";
    //$table2 = "registered_member";

    //Random confirmation code
    //$confirm_code = md5(uniqid(rand()));

    //This code runs if the form has been submitted
    if (isset($_POST['submit']))
    {

        
    // checks if the email address is alredy registered
        //if (!get_magic_quotes_gpc())
        //{
        //$_POST['email'] = addslashes($_POST['email']);
        //}
        
    $emailcheck $_POST['email'];
        
    $check mysql_query("SELECT email FROM $tbl_name WHERE email = '$emailcheck'") or
            die(
    mysql_error());
        
    $check2 mysql_num_rows($check);

        
    //if the name exists it gives an error
        
    if ($check2 != 0)
        {
    ?>
      <script type="text/javascript">
        alert("The email address <?php echo $_POST['email']; ?> is already registered.");
        history.back();
      </script>
    <?php

            
    //die("The email address '" . $_POST['email'] ."' is already registered");
            //print '<script type="text/javascript">';
            //print 'alert("The email address ' . $_POST['email'] .' is already registered")';
            //print '</script>';

        
    }

        
    // encrypt the password
        
    $pass1 md5($pass1);
        
    //if (!get_magic_quotes_gpc())
        //{[]
        //pass1 = addslashes($pass1);
        //$_POST['member_id'] = addslashes($_POST['member_id']);

        //Insert record to database
        
    $insert mysql_query("INSERT INTO $tbl_name(name,email,password,telephone,address)
                              VALUES ('" 
    $_POST['name'] . "','" $_POST['email'] .
            
    "', '" $_POST['pass1'] . "','" $_POST['tel'] . "','" $_POST['address'] .
            
    "')") or die(mysql_error());


        
    // }

        //if successfully inserted,send confirmation link to email
        
    if ($insert)
        {

            
    //echo "Thank for your registration!";
            //header("Location: http://localhost/www/index.php?frame=thankyou");
            
    $redirectUrl "http://localhost/www/index.php?frame=thankyou";
            print 
    "<script type=\"text/javascript\">";
            print 
    "window.location.href = '$redirectUrl'";
            print 
    "</script>";

            
    /*
            require ("class.phpmailer.php");

            $mail = new PHPMailer();
            $mail->IsSMTP();
            $mail->Host = "localhost";
            $mail->SMTPAuth = true;// turn on SMTP authentication
            $mail->Username = "admin";// SMTP username
            $mail->Password = "itc309";// SMTP password
            //$mail->SetLanguage("en","phpmailer/language");

            //compose mail
            $mail->From = "admin@localhost.com";
            $mail->FromName = "Cinema Admin";
            $mail->AddAddress($_POST['email']);
            $mail->AddReplyTo("admin@localhost.com", "cinema admin");
            $mail->Subject = 'Your confirmation link here';
            $mail->Body = "Your confirmation link\r\n";
            $mail->Body .= "Click on this link to activate your sccount\r\n";
            $mail->Body .= "http://localhost/www/confirm.php?passkey=$confirm_code";


            //send mail
            if (!$mail->Send())
            {
            echo "Message was not sent <p>";
            echo "Mailer Error: " . $mail->ErrorInfo;
            exit;
            }

            echo "Message has been sent";
            }

            //if not found
            else
            {
            echo "Not found your email in our database";
            }

            if your email successfully sent
            if ($sentmail)
            {
            echo "Your confirmation link has been sent to your email address.";
            }*/

        
    }
    }
    ?> 


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>New User Registration</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script language="JavaScript" type="text/JavaScript">
    function formSubmit() 
    {
      window.event.returnValue = false;
     
       if ((!form1.name.value) | (!form1.email.value)| (!form1.pass1.value ) | (!form1.pass2.value) |(!form1.tel.value) | 
           (!form1.address.value)){alert("You did not complete all of the required fields");}
      else if (form1.pass1.value.length < 5 | form1.pass1.value.length >12) 
         {alert("Password must be within 6-20 characters!");form1.pass1.focus()}
      else  if (form1.pass1.value != form1.pass2.value) {alert("Your password does not match");form1.pass2.focus();} 
      else  window.event.returnValue = true;
    }
    </script>
    </head>

    <body bgcolor="#000000">
    <div align="center"></div>
    <table width="80%" height="523" border="0" align="center" bgcolor="#CCCCFF">
      <tr> 
        <td width="2%" rowspan="4">&nbsp;</td>
        <td width="98%" height="58"> <div align="center"><font face="Arial, Helvetica, sans-serif"></font></div></td>
      </tr>
      <tr> 
        <td height="315" bgcolor="#CCCCFF"> 
          <div align="left"> 
            <table width="100%" border="0">
              <tr> 
                <td height="54" bgcolor="#CCCCFF"><font size="+3" face="Arial, Helvetica, sans-serif">Member 
                  Registration</font></td>
              </tr>
              <tr> 
                <td height="20" bgcolor="#CCCCFF"><div align="left"><font face="Arial, Helvetica, sans-serif"><img src="images/line.JPG" width="750" height="4"></font></div></td>
              </tr>
              <tr> 
                <td height="39" bgcolor="#CCCCFF"><font face="Arial, Helvetica, sans-serif"><em><strong>Important 
                  Notice:</strong></em></font> </td>
              </tr>
              <tr> 
                <td bgcolor="#CCCCFF"><font face="Arial, Helvetica, sans-serif">1. 
                  All fields provided must be filled in.</font></td>
              </tr>
              <tr> 
                <td bgcolor="#CCCCFF"><font face="Arial, Helvetica, sans-serif">2. 
                  Please fill in the fields accurately as important details are vital 
                  to access functions such as ticket &nbsp;&nbsp;&nbsp;&nbsp;reservations.</font></td>
              </tr>
              <tr> 
                <td bgcolor="#CCCCFF"><font face="Arial, Helvetica, sans-serif">3. 
                  Please use your email address as user id to login </font></td>
              </tr>
              <tr> 
                <td bgcolor="#CCCCFF"><font face="Arial, Helvetica, sans-serif">4. 
                  Password must be between 6-12 characters and is case sensitive.</font></td>
              </tr>
              
              <tr> 
                <td height="40" bgcolor="#CCCCFF"><div align="left"><font face="Arial, Helvetica, sans-serif"><img src="images/line.JPG" width="750" height="4"></font></div></td>
              </tr>
            </table>
          </div></td>
      </tr>
      <tr>
        <td height="94"><form name="form1" method="post" action="http://localhost/www/index.php?frame=signup">
            <table width="100%" border="0">
              <tr> 
                <td width="25%"><font face="Arial"><strong>Login Details</strong></font></td>
                <td width="4%">&nbsp;</td>
                <td width="71%">&nbsp;</td>
              </tr>
              <tr> 
                <td height="29"><font face="Arial">Email Address</font></td>
                <td width="4%">&nbsp;</td>
                <td><font face="Arial"> 
                  <input name="email" type="text">
                  </font></td>
              </tr>
              <tr> 
                <td height="27"><font face="Arial">Password</font></td>
                <td width="4%">&nbsp;</td>
                <td><font face="Arial"> 
                  <input name="pass1" type="password" maxlength="20">
                  </font></td>
              </tr>
               <tr> 
                <td height="27"><font face="Arial">Confirm Password</font></td>
                <td width="4%">&nbsp;</td>
                <td><font face="Arial"> 
                  <input name="pass2" type="password" id="password6" maxlength="20">
                  </font></td>
              </tr>
              <tr> 
                <td>&nbsp;</td>
                <td width="4%">&nbsp;</td>
                <td>&nbsp;</td>
              </tr>
              <tr> 
                <td><font face="Arial"><strong>Member Details</strong></font></td>
                <td width="4%">&nbsp;</td>
                <td>&nbsp;</td>
              </tr>
              <tr> 
                <td height="30"><font face="Arial">Full Name</font></td>
                <td width="4%">&nbsp;</td>
                <td><font face="Arial"> 
                  <input name="name" type="text" size="40">
                  </font></td>
              </tr>
                      
              <tr> 
                <td height="26"><font face="Arial">Telephone Number</font></td>
                <td width="4%">&nbsp;</td>
                <td><font face="Arial"> 
                  <input name="tel" type="text"  size="20" maxlength="10">
                  (Example: 0123334444, 0323459744)</font></td>
              </tr>
              <tr> 
                <td height="24"><font face="Arial">Address</font></td>
                <td width="4%">&nbsp;</td>
                 <td><label>
                   <textarea name="address" rows="3"></textarea>
                   </label></td>
              </tr>
            
              <tr> 
                <td>&nbsp;</td>
                <td width="4%">&nbsp;</td>
                <td> </tr>
              <tr> 
                <td>&nbsp;</td>
                <td width="4%">&nbsp;</td>
                <td><input type="submit" name="submit" value="Submit" onClick="formSubmit()"> &nbsp;
                    <input name="reset" type="reset" id="Reset2" value="Reset"> 
                </td>
              </tr>
            </table>
            <label></label>
        </form></td>
      </tr>
      <tr> 
        <td height="37">
    <div align="center"></div>
    </td>
      </tr>
    </table>
    </body>
    </html>
    Anybody know what went wrong in this code? The data still insert to database for twice even email address is same...Thanks...

  6. #6
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Yup. 'Cause the PHP code runs first, then the JS.

    Try this:

    PHP Code:
       // checks if the email address is alredy registered
        //if (!get_magic_quotes_gpc())
        //{
        //$_POST['email'] = addslashes($_POST['email']);
        //}
        $emailcheck = $_POST['email'];
        $check = mysql_query("SELECT email FROM $tbl_name WHERE email = '$emailcheck'") or
            die(mysql_error());
        $check2 = mysql_num_rows($check);

        //if the name exists it gives an error
        if ($check2 != 0)
        {
    ?>
      <script type="text/javascript">
        alert("The email address <?php echo $_POST['email']; ?> is already registered.");
        history.back();
      </script>
    <?php
    //THIS CODE IS UNCOMMENTED
    //So that people without JS can still see the message.
            
    die("The email address '" $_POST['email'] ."' is already registered");
    //END
            //print '<script type="text/javascript">';
            //print 'alert("The email address ' . $_POST['email'] .' is already registered")';
            //print '</script>';

        
    }

        
    // encrypt the password
        
    $pass1 md5($pass1);
        
    //if (!get_magic_quotes_gpc())
        //{[]
        //pass1 = addslashes($pass1);
        //$_POST['member_id'] = addslashes($_POST['member_id']);

        //Insert record to database
        
    $insert mysql_query("INSERT INTO $tbl_name(name,email,password,telephone,address)
                              VALUES ('" 
    $_POST['name'] . "','" $_POST['email'] .
            
    "', '" $_POST['pass1'] . "','" $_POST['tel'] . "','" $_POST['address'] .
            
    "')") or die(mysql_error());


        
    // }

        //if successfully inserted,send confirmation link to email
        
    if ($insert)
        {

            
    //echo "Thank for your registration!";
            //header("Location: http://localhost/www/index.php?frame=thankyou");
            
    $redirectUrl "http://localhost/www/index.php?frame=thankyou";
            print 
    "<script type=\"text/javascript\">";
            print 
    "window.location.href = '$redirectUrl'";
            print 
    "</script>";

            
    /*
            require ("class.phpmailer.php");

            $mail = new PHPMailer();
            $mail->IsSMTP();
            $mail->Host = "localhost";
            $mail->SMTPAuth = true;// turn on SMTP authentication
            $mail->Username = "admin";// SMTP username
            $mail->Password = "itc309";// SMTP password
            //$mail->SetLanguage("en","phpmailer/language");

            //compose mail
            $mail->From = "admin@localhost.com";
            $mail->FromName = "Cinema Admin";
            $mail->AddAddress($_POST['email']);
            $mail->AddReplyTo("admin@localhost.com", "cinema admin");
            $mail->Subject = 'Your confirmation link here';
            $mail->Body = "Your confirmation link\r\n";
            $mail->Body .= "Click on this link to activate your sccount\r\n";
            $mail->Body .= "http://localhost/www/confirm.php?passkey=$confirm_code";


            //send mail
            if (!$mail->Send())
            {
            echo "Message was not sent <p>";
            echo "Mailer Error: " . $mail->ErrorInfo;
            exit;
            }

            echo "Message has been sent";
            }

            //if not found
            else
            {
            echo "Not found your email in our database";
            }

            if your email successfully sent
            if ($sentmail)
            {
            echo "Your confirmation link has been sent to your email address.";
            }*/

        
    }
    }
    ?> 


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>New User Registration</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script language="JavaScript" type="text/JavaScript">
    function formSubmit() 
    {
      window.event.returnValue = false;
     
       if ((!form1.name.value) | (!form1.email.value)| (!form1.pass1.value ) | (!form1.pass2.value) |(!form1.tel.value) | 
           (!form1.address.value)){alert("You did not complete all of the required fields");}
      else if (form1.pass1.value.length < 5 | form1.pass1.value.length >12) 
         {alert("Password must be within 6-20 characters!");form1.pass1.focus()}
      else  if (form1.pass1.value != form1.pass2.value) {alert("Your password does not match");form1.pass2.focus();} 
      else  window.event.returnValue = true;
    }
    </script>
    </head>

    <body bgcolor="#000000">
    <div align="center"></div>
    <table width="80%" height="523" border="0" align="center" bgcolor="#CCCCFF">
      <tr> 
        <td width="2%" rowspan="4">&nbsp;</td>
        <td width="98%" height="58"> <div align="center"><font face="Arial, Helvetica, sans-serif"></font></div></td>
      </tr>
      <tr> 
        <td height="315" bgcolor="#CCCCFF"> 
          <div align="left"> 
            <table width="100%" border="0">
              <tr> 
                <td height="54" bgcolor="#CCCCFF"><font size="+3" face="Arial, Helvetica, sans-serif">Member 
                  Registration</font></td>
              </tr>
              <tr> 
                <td height="20" bgcolor="#CCCCFF"><div align="left"><font face="Arial, Helvetica, sans-serif"><img src="images/line.JPG" width="750" height="4"></font></div></td>
              </tr>
              <tr> 
                <td height="39" bgcolor="#CCCCFF"><font face="Arial, Helvetica, sans-serif"><em><strong>Important 
                  Notice:</strong></em></font> </td>
              </tr>
              <tr> 
                <td bgcolor="#CCCCFF"><font face="Arial, Helvetica, sans-serif">1. 
                  All fields provided must be filled in.</font></td>
              </tr>
              <tr> 
                <td bgcolor="#CCCCFF"><font face="Arial, Helvetica, sans-serif">2. 
                  Please fill in the fields accurately as important details are vital 
                  to access functions such as ticket &nbsp;&nbsp;&nbsp;&nbsp;reservations.</font></td>
              </tr>
              <tr> 
                <td bgcolor="#CCCCFF"><font face="Arial, Helvetica, sans-serif">3. 
                  Please use your email address as user id to login </font></td>
              </tr>
              <tr> 
                <td bgcolor="#CCCCFF"><font face="Arial, Helvetica, sans-serif">4. 
                  Password must be between 6-12 characters and is case sensitive.</font></td>
              </tr>
              
              <tr> 
                <td height="40" bgcolor="#CCCCFF"><div align="left"><font face="Arial, Helvetica, sans-serif"><img src="images/line.JPG" width="750" height="4"></font></div></td>
              </tr>
            </table>
          </div></td>
      </tr>
      <tr>
        <td height="94"><form name="form1" method="post" action="http://localhost/www/index.php?frame=signup">
            <table width="100%" border="0">
              <tr> 
                <td width="25%"><font face="Arial"><strong>Login Details</strong></font></td>
                <td width="4%">&nbsp;</td>
                <td width="71%">&nbsp;</td>
              </tr>
              <tr> 
                <td height="29"><font face="Arial">Email Address</font></td>
                <td width="4%">&nbsp;</td>
                <td><font face="Arial"> 
                  <input name="email" type="text">
                  </font></td>
              </tr>
              <tr> 
                <td height="27"><font face="Arial">Password</font></td>
                <td width="4%">&nbsp;</td>
                <td><font face="Arial"> 
                  <input name="pass1" type="password" maxlength="20">
                  </font></td>
              </tr>
               <tr> 
                <td height="27"><font face="Arial">Confirm Password</font></td>
                <td width="4%">&nbsp;</td>
                <td><font face="Arial"> 
                  <input name="pass2" type="password" id="password6" maxlength="20">
                  </font></td>
              </tr>
              <tr> 
                <td>&nbsp;</td>
                <td width="4%">&nbsp;</td>
                <td>&nbsp;</td>
              </tr>
              <tr> 
                <td><font face="Arial"><strong>Member Details</strong></font></td>
                <td width="4%">&nbsp;</td>
                <td>&nbsp;</td>
              </tr>
              <tr> 
                <td height="30"><font face="Arial">Full Name</font></td>
                <td width="4%">&nbsp;</td>
                <td><font face="Arial"> 
                  <input name="name" type="text" size="40">
                  </font></td>
              </tr>
                      
              <tr> 
                <td height="26"><font face="Arial">Telephone Number</font></td>
                <td width="4%">&nbsp;</td>
                <td><font face="Arial"> 
                  <input name="tel" type="text"  size="20" maxlength="10">
                  (Example: 0123334444, 0323459744)</font></td>
              </tr>
              <tr> 
                <td height="24"><font face="Arial">Address</font></td>
                <td width="4%">&nbsp;</td>
                 <td><label>
                   <textarea name="address" rows="3"></textarea>
                   </label></td>
              </tr>
            
              <tr> 
                <td>&nbsp;</td>
                <td width="4%">&nbsp;</td>
                <td> </tr>
              <tr> 
                <td>&nbsp;</td>
                <td width="4%">&nbsp;</td>
                <td><input type="submit" name="submit" value="Submit" onClick="formSubmit()"> &nbsp;
                    <input name="reset" type="reset" id="Reset2" value="Reset"> 
                </td>
              </tr>
            </table>
            <label></label>
        </form></td>
      </tr>
      <tr> 
        <td height="37">
    <div align="center"></div>
    </td>
      </tr>
    </table>
    </body>
    </html>
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  7. #7
    Join Date
    Aug 2007
    Location
    Malaysia
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Wow..Problem fixed.Thanks a lot..

    Quote Originally Posted by tech_support View Post
    Yup. 'Cause the PHP code runs first, then the JS.

    Try this:

    PHP Code:
       // checks if the email address is alredy registered
        //if (!get_magic_quotes_gpc())
        //{
        //$_POST['email'] = addslashes($_POST['email']);
        //}
        $emailcheck = $_POST['email'];
        $check = mysql_query("SELECT email FROM $tbl_name WHERE email = '$emailcheck'") or
            die(mysql_error());
        $check2 = mysql_num_rows($check);

        //if the name exists it gives an error
        if ($check2 != 0)
        {
    ?>
      <script type="text/javascript">
        alert("The email address <?php echo $_POST['email']; ?> is already registered.");
        history.back();
      </script>
    <?php
    //THIS CODE IS UNCOMMENTED
    //So that people without JS can still see the message.
            
    die("The email address '" $_POST['email'] ."' is already registered");
    //END
            //print '<script type="text/javascript">';
            //print 'alert("The email address ' . $_POST['email'] .' is already registered")';
            //print '</script>';

        
    }

        
    // encrypt the password
        
    $pass1 md5($pass1);
        
    //if (!get_magic_quotes_gpc())
        //{[]
        //pass1 = addslashes($pass1);
        //$_POST['member_id'] = addslashes($_POST['member_id']);

        //Insert record to database
        
    $insert mysql_query("INSERT INTO $tbl_name(name,email,password,telephone,address)
                              VALUES ('" 
    $_POST['name'] . "','" $_POST['email'] .
            
    "', '" $_POST['pass1'] . "','" $_POST['tel'] . "','" $_POST['address'] .
            
    "')") or die(mysql_error());


        
    // }

        //if successfully inserted,send confirmation link to email
        
    if ($insert)
        {

            
    //echo "Thank for your registration!";
            //header("Location: http://localhost/www/index.php?frame=thankyou");
            
    $redirectUrl "http://localhost/www/index.php?frame=thankyou";
            print 
    "<script type=\"text/javascript\">";
            print 
    "window.location.href = '$redirectUrl'";
            print 
    "</script>";

            
    /*
            require ("class.phpmailer.php");

            $mail = new PHPMailer();
            $mail->IsSMTP();
            $mail->Host = "localhost";
            $mail->SMTPAuth = true;// turn on SMTP authentication
            $mail->Username = "admin";// SMTP username
            $mail->Password = "itc309";// SMTP password
            //$mail->SetLanguage("en","phpmailer/language");

            //compose mail
            $mail->From = "admin@localhost.com";
            $mail->FromName = "Cinema Admin";
            $mail->AddAddress($_POST['email']);
            $mail->AddReplyTo("admin@localhost.com", "cinema admin");
            $mail->Subject = 'Your confirmation link here';
            $mail->Body = "Your confirmation link\r\n";
            $mail->Body .= "Click on this link to activate your sccount\r\n";
            $mail->Body .= "http://localhost/www/confirm.php?passkey=$confirm_code";


            //send mail
            if (!$mail->Send())
            {
            echo "Message was not sent <p>";
            echo "Mailer Error: " . $mail->ErrorInfo;
            exit;
            }

            echo "Message has been sent";
            }

            //if not found
            else
            {
            echo "Not found your email in our database";
            }

            if your email successfully sent
            if ($sentmail)
            {
            echo "Your confirmation link has been sent to your email address.";
            }*/

        
    }
    }
    ?> 


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>New User Registration</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script language="JavaScript" type="text/JavaScript">
    function formSubmit() 
    {
      window.event.returnValue = false;
     
       if ((!form1.name.value) | (!form1.email.value)| (!form1.pass1.value ) | (!form1.pass2.value) |(!form1.tel.value) | 
           (!form1.address.value)){alert("You did not complete all of the required fields");}
      else if (form1.pass1.value.length < 5 | form1.pass1.value.length >12) 
         {alert("Password must be within 6-20 characters!");form1.pass1.focus()}
      else  if (form1.pass1.value != form1.pass2.value) {alert("Your password does not match");form1.pass2.focus();} 
      else  window.event.returnValue = true;
    }
    </script>
    </head>

    <body bgcolor="#000000">
    <div align="center"></div>
    <table width="80%" height="523" border="0" align="center" bgcolor="#CCCCFF">
      <tr> 
        <td width="2%" rowspan="4">&nbsp;</td>
        <td width="98%" height="58"> <div align="center"><font face="Arial, Helvetica, sans-serif"></font></div></td>
      </tr>
      <tr> 
        <td height="315" bgcolor="#CCCCFF"> 
          <div align="left"> 
            <table width="100%" border="0">
              <tr> 
                <td height="54" bgcolor="#CCCCFF"><font size="+3" face="Arial, Helvetica, sans-serif">Member 
                  Registration</font></td>
              </tr>
              <tr> 
                <td height="20" bgcolor="#CCCCFF"><div align="left"><font face="Arial, Helvetica, sans-serif"><img src="images/line.JPG" width="750" height="4"></font></div></td>
              </tr>
              <tr> 
                <td height="39" bgcolor="#CCCCFF"><font face="Arial, Helvetica, sans-serif"><em><strong>Important 
                  Notice:</strong></em></font> </td>
              </tr>
              <tr> 
                <td bgcolor="#CCCCFF"><font face="Arial, Helvetica, sans-serif">1. 
                  All fields provided must be filled in.</font></td>
              </tr>
              <tr> 
                <td bgcolor="#CCCCFF"><font face="Arial, Helvetica, sans-serif">2. 
                  Please fill in the fields accurately as important details are vital 
                  to access functions such as ticket &nbsp;&nbsp;&nbsp;&nbsp;reservations.</font></td>
              </tr>
              <tr> 
                <td bgcolor="#CCCCFF"><font face="Arial, Helvetica, sans-serif">3. 
                  Please use your email address as user id to login </font></td>
              </tr>
              <tr> 
                <td bgcolor="#CCCCFF"><font face="Arial, Helvetica, sans-serif">4. 
                  Password must be between 6-12 characters and is case sensitive.</font></td>
              </tr>
              
              <tr> 
                <td height="40" bgcolor="#CCCCFF"><div align="left"><font face="Arial, Helvetica, sans-serif"><img src="images/line.JPG" width="750" height="4"></font></div></td>
              </tr>
            </table>
          </div></td>
      </tr>
      <tr>
        <td height="94"><form name="form1" method="post" action="http://localhost/www/index.php?frame=signup">
            <table width="100%" border="0">
              <tr> 
                <td width="25%"><font face="Arial"><strong>Login Details</strong></font></td>
                <td width="4%">&nbsp;</td>
                <td width="71%">&nbsp;</td>
              </tr>
              <tr> 
                <td height="29"><font face="Arial">Email Address</font></td>
                <td width="4%">&nbsp;</td>
                <td><font face="Arial"> 
                  <input name="email" type="text">
                  </font></td>
              </tr>
              <tr> 
                <td height="27"><font face="Arial">Password</font></td>
                <td width="4%">&nbsp;</td>
                <td><font face="Arial"> 
                  <input name="pass1" type="password" maxlength="20">
                  </font></td>
              </tr>
               <tr> 
                <td height="27"><font face="Arial">Confirm Password</font></td>
                <td width="4%">&nbsp;</td>
                <td><font face="Arial"> 
                  <input name="pass2" type="password" id="password6" maxlength="20">
                  </font></td>
              </tr>
              <tr> 
                <td>&nbsp;</td>
                <td width="4%">&nbsp;</td>
                <td>&nbsp;</td>
              </tr>
              <tr> 
                <td><font face="Arial"><strong>Member Details</strong></font></td>
                <td width="4%">&nbsp;</td>
                <td>&nbsp;</td>
              </tr>
              <tr> 
                <td height="30"><font face="Arial">Full Name</font></td>
                <td width="4%">&nbsp;</td>
                <td><font face="Arial"> 
                  <input name="name" type="text" size="40">
                  </font></td>
              </tr>
                      
              <tr> 
                <td height="26"><font face="Arial">Telephone Number</font></td>
                <td width="4%">&nbsp;</td>
                <td><font face="Arial"> 
                  <input name="tel" type="text"  size="20" maxlength="10">
                  (Example: 0123334444, 0323459744)</font></td>
              </tr>
              <tr> 
                <td height="24"><font face="Arial">Address</font></td>
                <td width="4%">&nbsp;</td>
                 <td><label>
                   <textarea name="address" rows="3"></textarea>
                   </label></td>
              </tr>
            
              <tr> 
                <td>&nbsp;</td>
                <td width="4%">&nbsp;</td>
                <td> </tr>
              <tr> 
                <td>&nbsp;</td>
                <td width="4%">&nbsp;</td>
                <td><input type="submit" name="submit" value="Submit" onClick="formSubmit()"> &nbsp;
                    <input name="reset" type="reset" id="Reset2" value="Reset"> 
                </td>
              </tr>
            </table>
            <label></label>
        </form></td>
      </tr>
      <tr> 
        <td height="37">
    <div align="center"></div>
    </td>
      </tr>
    </table>
    </body>
    </html>

  8. #8
    Join Date
    Jul 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default please some one correct mycode Iam trying to click on button but alert is not popping

    <html>
    <head>
    <script>
    function retrieve()
    {
    <?php

    $con=mysql_connect('localhost','root','');
    mysql_select_db('order');
    $ins="INSERT INTO `shirts`(`Name`,`price`,`value`,`total`) VALUES ('$name','$price','$value','$total')";
    $exc=mysql_query($ins);
    if($exc>0)
    {
    echo '<script type="text/javascript">alert("hello!");</script>';
    }
    else
    {
    echo '<script type="text/javascript">alert("bye!");</script>';

    }

    mysql_close($con);

    ?>
    }
    </script>
    <link rel="stylesheet" type="text/css" href="css/main.css"/>

    </head>

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •