Error msg cannot showed in php & txt box matching not work

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mmarif4u
    New Member
    • Sep 2006
    • 23

    Error msg cannot showed in php & txt box matching not work

    Hi everyone.

    i make a page that a user input thier icnumber with confirm ic number,
    it saves the data to mysql db with current date and a random access code
    generated automatically, NOW i have some problems facing..
    1: How to match both txt box vlaues that r same or not.Is there php code for it.
    2: I want to put a print button in the code where the code display the page after
    entring the icnumber and after submit.
    3: How to show the error msg if the user do some wrong i put javascript code
    with common.php but only display this: <? =$msg ?> in popup window.


    My coding is :
    [PHP]<?php


    include("db.php ");
    include("common .php");

    if (!isset($_POST['submitok'])):
    // Display the user signup form
    ?>
    <!DOCTYPE html PUBLIC "-//W3C/DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    (I PUT THIS CODE IN HEAD FOR MATCH THE TXT BOX BUT CANT WORKS
    BCOZ IT DISPLAY MAG BUT THE DATA STORED TO THE DB.)

    <script language="JavaS cript"><!--
    function validateForm()
    {
    var okSoFar=true
    with (document.admin )
    {

    if (icnumber.value =="" && okSoFar)
    {
    okSoFar=false
    alert("Please enter IC Number.")
    icnumber.focus( )
    }
    if (cicnumber.valu e=="" && okSoFar)
    {
    okSoFar=false
    alert("Please confirm IC Number.")
    cicnumber.focus ()
    }
    var e1 = icnumber.value
    var e2 = cicnumber.value
    if (!(e1==e2) && okSoFar)
    {
    okSoFar = false
    alert ("IC Numbers does not match. Please re-enter.")
    icnumber.focus( )
    }



    if (okSoFar==true) submitok();
    }
    }
    // --></script>
    <title> Access Code Generator Form </title>
    <meta http-equiv="Content-Type"
    content="text/html; charset=iso-8859-1
    </head>
    <body>

    <h3> Access Code Generator Form </h3>
    <p><font color="orangere d" size="+1"><tt>< b>*</b></tt></font>
    <u>indicates a required field</u></p>
    <form name="admin" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

    <table align="center" border="0" cellpadding="0" cellspacing="5" >

    <tr>
    <td align="right">
    <p>IC Number :</p>
    </td>
    <td>
    <input name="icnumber" type="text" maxlength="100" size="25" />
    <font color="orangere d" size="+1"><tt>< b>*</b></tt></font>
    </td>
    </tr>

    <tr>
    <td align="right">
    <p>Confirm IC Number :</p>
    </td>
    <td>
    <input name="cicnumber " type="text" maxlength="100" size="25" />
    <font color="orangere d" size="+1"><tt>< b>*</b></tt></font>
    </td>
    </tr>



    <tr>
    <td align="right" colspan="2">
    <hr noshade="noshad e" />
    <input type="reset" value="Reset Form" />
    <input type="submit" name="submitok" value="Generate Code" />

    </td>
    </tr>
    </table>
    </form>

    </body>
    </html>


    <?php

    else:
    // Process submission
    dbConnect('db') ;



    // Check for existing user with the ic number
    $sql = "SELECT COUNT(*) FROM m_user WHERE icnumber = '$_POST[icnumber]'";
    $result = mysql_query($sq l);
    if (!$result) {
    error('A database error occurred in processing your '.
    'submission.\\n If this error persists, please '.
    'contact you@example.com .');
    }
    if (mysql_result($ result,0,0)>0) {
    error('A user already exists with your chosen userid.\\n'.
    'Please try another.');
    }

    $random = rand(1000000,99 99999990);


    $sql = "INSERT INTO m_user SET
    icnumber = '$_POST[icnumber]',
    accesscode = ('$random'),
    Actdate = now();
    ";
    if (!mysql_query($ sql))
    error('A database error occurred in processing your '.
    'submission.\\n If this error persists, please '.
    'contact admin@straight-a.com.my .\\n' . mysql_error());

    ?>
    <!DOCTYPE html PUBLIC "-//W3C/DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title> Code Generation Complete </title>
    <meta http-equiv="Content-Type"
    content="text/html; charset=iso-8859-1" />
    </head>
    <body><center >
    <?php
    $con = mysql_connect(" localhost","roo t","adil");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }

    mysql_select_db ("db", $con);

    $result = mysql_query("SE LECT icnumber,access code,actdate FROM m_user where
    icnumber = '$_POST[icnumber]'
    ");

    echo "<table align=Center CELLSPACING='0' BORDERCOLOR='#0 07FFF' BGCOLOR='cornsi lk' border='1'>

    <tr><th colspan=12>User Activation details</th>
    <tr>
    <th>IC Number</th>
    <th>Access Code</th>
    <th>Current Date</th>

    </tr></tr>";while($ro w = mysql_fetch_arr ay($result))
    {
    echo "<tr>";
    echo "<td>" . $row['icnumber'] . "</td>";
    echo "<td>" . $row['accesscode'] . "</td>";
    echo "<td>" . $row['actdate'] . "</td>";

    echo "</tr>";
    }
    echo "</table>";mysql_c lose($con);
    (HERE I WANT PUT PRINT BUTTON CODE, CODE IS IN JAVASCRIPT.)
    ?></strong></a>
    </p>
    </body>
    </html>
    <?php
    endif;

    ?>
    [/PHP]


    Here is my common.php code:
    [PHP]<?php // common.php

    function error($msg) {
    ?>
    <html>
    <head>
    <script language="JavaS cript">
    <!--
    alert("<? =$msg ?> ");
    history.back();
    -->
    </script>
    </head>

    </html>
    <?php
    exit;
    }
    ?>
    [/PHP]

    Plz some body help me on this,
    Thanks.
  • subbukumararaja
    New Member
    • Dec 2006
    • 4

    #2
    For your first question,

    u did that thru JavaScript, then y u r expecting the same in PHP. That u don't need.

    For your third question,
    y u have created a PHP function, instead of Java Script function to display a alert message.

    in the common.php file just remove the <html>,<body> tags and just keep the <script tag>. That also should be inside a ECHO statment.

    then only that code will printed as a PHP code when u r including the file.

    Comment

    • mmarif4u
      New Member
      • Sep 2006
      • 23

      #3
      Thanks for ur reply subbukumararaja
      I want to remove javascript for Q 1 that only php check the validation But
      How .....,When i input some value without confirm it, the data stored in
      the database.

      Other i remove the tags but how to echo the msg plz can explain it
      with common.php code.where to put ECHO statement.

      Comment

      • mmarif4u
        New Member
        • Sep 2006
        • 23

        #4
        Yes I got it subbukumararaja ,
        Thanks for ur help Error msg now ok.
        But others still have....

        If u dont mind can i ask another question Can i insert Date with
        coming 1 month to mysql, have u any idea on this.

        I am working on it may be i will do it.

        but if u have idea plz share it with me.

        Thankss...

        Comment

        • mmarif4u
          New Member
          • Sep 2006
          • 23

          #5
          Hey man i solve the other problem now php code checks the
          two fields for confirmation.
          Only one problem remain where to put the print button code.

          Comment

          • ronverdonk
            Recognized Expert Specialist
            • Jul 2006
            • 4259

            #6
            You can print from within your PHP script. Just place the following statement on your page.
            [php]
            echo '<a href="javascrip t:window.print( );">Print this page</a>';
            [/php]
            If you want to use a button, use an image instead of text.

            Ronald :cool:

            Comment

            • mmarif4u
              New Member
              • Sep 2006
              • 23

              #7
              Thanks ronverdonk its working.

              Now every thing is clear.

              Comment

              Working...