automatic save

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • underscore
    New Member
    • Jul 2007
    • 30

    automatic save

    gud day to all TSD.


    if i run the code below which is HTML combine with php. my problem encoutered in php code. it will automatically save all blank textbox i declare in php to my database using mysql if i will run this page.

    please correct my problem in my code.

    thnx again...

    [code=php]

    <? session_start() ; ?>

    <head>
    <title>My Page</title>
    <style type="text/css">
    <!--
    #Layer1 {
    position:absolu te;
    left:200px;
    top:10px;
    width:816px;
    height:540px;
    z-index:1;
    }
    .style3 {font-family: Arial, Helvetica, sans-serif}
    .style4 {font-family: Arial}
    a:link {
    text-decoration: none;
    }
    a:visited {
    text-decoration: none;
    }
    a:hover {
    text-decoration: none;
    }
    a:active {
    text-decoration: none;
    }
    .style14 {color: #FF0000; font-family: Geneva, Arial, Helvetica, sans-serif; }
    -->
    </style>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>

    <div id="Layer1">
    <table width="808" height="538" border="0" cellpadding="0" cellspacing="0" bordercolor="#2 A1F00">
    <tr>
    <td width="236" height="110"><i mg src="image/Nagano Header.jpg" width="236" height="110" alt="" /></td>
    <td colspan="4"><im g src="image/header.jpg" width="598" height="110" alt="" /></td>
    </tr>
    <tr>
    <td height="22" colspan="5" bordercolor="#0 000FF" bgcolor="#DAE2C 7"><span class="style14" >CREATE YOUR ID</span> </td>
    </tr>

    <form name="form1" method="post" action="registe r.php">

    <tr>
    <td height="42" bgcolor="#F7F7F 7"><div align="right" class="style3"> * First Name </div></td>
    <td width="20" bgcolor="#F7F7F 7">&nbsp;</td>
    <td width="159" bgcolor="#F7F7F 7"><input name="txtfname" type="text" id="txtfname" /></td>
    <td width="48" bgcolor="#F7F7F 7">&nbsp;</td>
    <td width="364" bgcolor="#F7F7F 7"><label></label></td>
    </tr>
    <tr>
    <td height="25" bordercolor="#F 7F3EF" bgcolor="#F7F7F 7"><div align="right">* <span class="style4"> Last Name</span> </div></td>
    <td bordercolor="#F 7F3EF" bgcolor="#F7F7F 7">&nbsp;</td>
    <td bordercolor="#F 7F3EF" bgcolor="#F7F7F 7"><input name="txtlname" type="text" id="txtlname" /></td>
    <td bordercolor="#F 7F3EF" bgcolor="#F7F7F 7">&nbsp;</td>
    <td bordercolor="#F 7F3EF" bgcolor="#F7F7F 7"><label></label></td>
    </tr>
    <tr>
    <td height="36" bordercolor="#F 7F3EF" bgcolor="#F7f7f 7"><div align="right" class="style4"> * Gender </div></td>
    <td bordercolor="#F 7F3EF" bgcolor="#F7F7F 7">&nbsp;</td>
    <td bordercolor="#F 7F3EF" bgcolor="#F7F7F 7"><select name="mnugender " id="mnugender" >
    <option value="0">[Select]</option>
    <option value="1">Male</option>
    <option value="2">Femal e</option>
    </select></td>
    <td bordercolor="#F 7F3EF" bgcolor="#F7F7F 7">&nbsp;</td>
    <td bordercolor="#F 7F3EF" bgcolor="#F7F7F 7"><label></label></td>
    </tr>
    <tr>
    <td height="34" bordercolor="#F 7F3EF" bgcolor="#F7F7F 7"><div align="right">* Log-in ID </div></td>
    <td bordercolor="#F 7F3EF" bgcolor="#F7F7F 7">&nbsp;</td>
    <td bordercolor="#F 7F3EF" bgcolor="#F7F7F 7"><label>
    <input name="txtlogid" type="text" id="txtlogid">
    </label></td>
    <td bordercolor="#F 7F3EF" bgcolor="#F7F7F 7">&nbsp;</td>
    <td bordercolor="#F 7F3EF" bgcolor="#F7F7F 7">&nbsp;</td>
    </tr>
    <tr>
    <td height="34" bordercolor="#F 7F3EF" bgcolor="#F7F7F 7"><div align="right" class="style4"> * Password</div></td>
    <td bordercolor="#F 7F3EF" bgcolor="#F7F7F 7">&nbsp;</td>
    <td bordercolor="#F 7F3EF" bgcolor="#F7F7F 7"><input name="txtpasswo rd" type="password" id="txtpassword " /></td>
    <td bordercolor="#F 7F3EF" bgcolor="#F7F7F 7">&nbsp;</td>
    <td bordercolor="#F 7F3EF" bgcolor="#F7F7F 7">&nbsp;</td>
    </tr>

    <tr>
    <td bordercolor="#F 7F3EF" bgcolor="#F7F7F 7"><div align="right" class="style4"> * Re-type Password </div></td>
    <td bordercolor="#F 7F3EF" bgcolor="#F7F7F 7">&nbsp;</td>
    <td bordercolor="#F 7F3EF" bgcolor="#F7F7F 7"><input name="txtretype pass" type="password" id="txtretypepa ss" /></td>
    <td bordercolor="#F 7F3EF" bgcolor="#F7F7F 7">&nbsp;</td>
    <td bordercolor="#F 7F3EF" bgcolor="#F7F7F 7"><label></label></td>
    </tr>
    <tr>
    <td height="38" bgcolor="#F7F7F 7"><div align="right">< span class="style4"> Birth Date </span></div></td>
    <td bgcolor="#F7F7F 7">&nbsp;</td>
    <td bgcolor="#F7F7F 7"><select name="mnuMonth" id="mnuMonth">
    <option value="0">[Select Month]</option>
    <option value="1">Janua ry</option>
    <option value="2">Febru ary</option>
    <option value="3">March </option>
    <option value="4">April </option>
    <option value="5">May</option>
    // OTHER OPTION VALUES 6-11 GOES HERE
    <option value="12">Dece mber</option>
    </select></td>
    <td bgcolor="#F7F7F 7"><label>
    <select name="txtday" id="txtday">
    <option value="1" selected>1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    // OTHER OPTION VALUES 3-30 GOES HERE
    <option value="31">31</option>
    </select>
    </label></td>
    <td bgcolor="#F7F7F 7"><label>
    <input name="txtyear" type="text" id="txtyear" value="yyyy" size="4">
    </label></td>
    </tr>
    <tr>
    <td height="39" bgcolor="#F7F7F 7"><div align="right" class="style4"> Zip/Postal code </div></td>
    <td bgcolor="#F7F7F 7">&nbsp;</td>
    <td bgcolor="#F7F7F 7"><input name="txtzip" type="text" id="txtzip" /></td>
    <td bgcolor="#F7F7F 7">&nbsp;</td>
    <td bgcolor="#F7F7F 7">&nbsp;</td>
    </tr>
    <tr>
    <td height="27" bgcolor="#F7F7F 7"><div align="right">< span class="style4"> * Email Address</span></div></td>
    <td bgcolor="#F7F7F 7">&nbsp;</td>
    <td bgcolor="#F7F7F 7"><input name="txtemaila dd" type="text" id="txtemailadd " /></td>
    <td bgcolor="#F7F7F 7">&nbsp;</td>
    <td bgcolor="#F7F7F 7">&nbsp;</td>
    </tr>

    <tr>
    <td height="33" bgcolor="#F7F7F 7"><div align="right" class="style4"> User Access Level </div></td>
    <td bgcolor="#F7F7F 7">&nbsp;</td>
    <td bgcolor="#F7F7F 7"><label>
    <select name="mnuAccess " id="mnuAccess" >
    <option value="0">[Select Level]</option>
    <option value="1">Admin istrator</option>
    <option value="2">Limit ed</option>
    </select>
    </label></td>
    <td bgcolor="#F7F7F 7">&nbsp;</td>
    <td bgcolor="#F7F7F 7">&nbsp;</td>
    </tr>
    <tr>
    <td height="19" bgcolor="#F7F7F 7">&nbsp;</td>
    <td bgcolor="#F7F7F 7">&nbsp;</td>
    <td bgcolor="#F7F7F 7"><label></label></td>
    <td bgcolor="#F7F7F 7">&nbsp;</td>
    <td bgcolor="#F7F7F 7">&nbsp;</td>
    </tr>
    <tr>
    <td bgcolor="#F7F7F 7"><a href="index.htm l" target="_parent "></a></td>
    <td bgcolor="#F7F7F 7">&nbsp;</td>
    <td bgcolor="#F7F7F 7"><input name="Submit" type="Submit" class="style4" id="Submit" value=" Submit " onClick="javasc ript:alert('You r form has been submitted')">
    <td bgcolor="#F7F7F 7">&nbsp;</td>
    <td bgcolor="#F7F7F 7">&nbsp;</td>
    </tr>

    <tr>
    <td height="24" colspan="5" bgcolor="#F7F7F 7"><div align="left">
    <blockquote>
    <blockquote>
    <blockquote>
    <blockquote>
    <blockquote>
    <blockquote>
    <p><a href="index.htm l" target="_parent "><strong>B ACK TO HOME PAGE </strong></a></p>
    </blockquote>
    </blockquote>
    </blockquote>
    </blockquote>
    </blockquote>
    </blockquote>
    </div></td>
    </tr>
    <tr>
    <td bgcolor="#F7F7F 7"><div align="right" class="style4"> <a href="index.htm l" target="_parent "></a></div></td>
    <td bgcolor="#F7F7F 7">&nbsp;</td>
    <td bgcolor="#F7F7F 7"><a href="index.htm l" target="_parent "></a></td>
    <td bgcolor="#F7F7F 7">&nbsp;</td>
    <td bgcolor="#F7F7F 7"><label></label></td>
    </tr>
    </table>

    </div>
    </body>
    </html>

    <?php

    if (isset($_POST["Submit"]))

    include'package/connect.inc.php ';
    mysql_select_db ('database');

    $user_sql = "INSERT INTO userpass(loginI d,fname,lname,g ender,password, repassword,bdat e,zip,emailadd, accesslevel,reg date,reghours)
    values('". $_POST["txtlogid"] ."','". $_POST["txtfname"] ."','". $_POST["txtlname"] ."',
    '". $_POST["mnugender"] ."','". $_POST["txtpasswor d"] ."',
    '". $_POST["txtretypep ass"]."','". $_POST["mnuMonth"]."-". $_POST["txtday"]."-". $_POST["txtyear"]."',
    '". $_POST["txtzip"]."',
    '". $_POST["txtemailad d"]."','". $_POST["mnuAccess"]."',
    '". date("F j, Y, g:i a")."','". date("H:i:s A")."')";
    $result = mysql_query($us er_sql);

    }
    ?>
    [/code]
    Last edited by ak1dnar; Sep 18 '07, 04:44 AM. Reason: Added CODE=php tags and Removed Some HTML contents
  • ak1dnar
    Recognized Expert Top Contributor
    • Jan 2007
    • 1584

    #2
    I had to remove some Html contents from the above code, because forum software doesn't support for that much of lines of code tags on a single attempt.
    And I've added some comments on the removed sections and the
    [code=php] tags too to the code listening. Thanks a lot.

    Comment

    • underscore
      New Member
      • Jul 2007
      • 30

      #3
      Originally posted by ajaxrand
      I had to remove some Html contents from the above code, because forum software doesn't support for that much of lines of code tags on a single attempt.
      And I've added some comments on the removed sections and the
      [code=php] tags too to the code listening. Thanks a lot.

      the result mr .jax still d same when i run this page it will automatically save a blank in my database.?

      thnx

      Comment

      • code green
        Recognized Expert Top Contributor
        • Mar 2007
        • 1726

        #4
        the result mr .jax still d same when i run this page it will automatically save a blank in my database.?
        NO! ajaxrand did not try to help you, he tried to help the rest of us by removing chunks of code not relevant to the problem.
        There is still far too much code.
        What is the problem and where is it occuring?
        Last edited by ak1dnar; Sep 18 '07, 01:20 PM. Reason: Replaced "Alaxrand" with the correct one - LOL

        Comment

        • ak1dnar
          Recognized Expert Top Contributor
          • Jan 2007
          • 1584

          #5
          @underscore

          Is this mysql_query() is running when you loading the page for the very first time?

          @code green
          Please don't use "Alaxrand" again, Its too ugly. ;)

          Comment

          • code green
            Recognized Expert Top Contributor
            • Mar 2007
            • 1726

            #6
            Ajaxrand - Sorry slip of the fingers. 'l' and 'j' are only two keys apart.
            underscore - You can get around this problem by employing basic techniques that should always be used.
            I am referring to verifying POST data, especially before inserting into a database.
            If you had placed these checks in the script it would help you greatly towards identifying the underlying problem,
            which I still can't see by the way.

            Comment

            • ak1dnar
              Recognized Expert Top Contributor
              • Jan 2007
              • 1584

              #7
              First turn on the Error reporting. There are some instruction how to do that on the top of the php forum home page.
              Why I am saying this, I didn't see the the opening "{" bracket for the "if" condition but closing bracket is there as the last line.

              Comment

              • underscore
                New Member
                • Jul 2007
                • 30

                #8
                Originally posted by ajaxrand
                @underscore

                Is this mysql_query() is running when you loading the page for the very first time?

                @code green
                Please don't use "Alaxrand" again, Its too ugly. ;)

                yes sir! when i run the page the mysql was already runing. is thr wrong with it?

                Comment

                • underscore
                  New Member
                  • Jul 2007
                  • 30

                  #9
                  Originally posted by code green
                  NO! ajaxrand did not try to help you, he tried to help the rest of us by removing chunks of code not relevant to the problem.
                  There is still far too much code.
                  What is the problem and where is it occuring?
                  ok sir. my problem is if i run those PHP code it will automatically save to mysql database. in the PHP at the buttom.

                  Comment

                  • code green
                    Recognized Expert Top Contributor
                    • Mar 2007
                    • 1726

                    #10
                    Well you do have an if statement that controls nothing [PHP]if (isset($_POST["Submit"]))

                    include'package/connect.inc.php ';
                    mysql_select_db ('database');[/PHP]Looks like you are missing a brace after the if statement

                    Comment

                    • underscore
                      New Member
                      • Jul 2007
                      • 30

                      #11
                      Originally posted by code green
                      Well you do have an if statement that controls nothing [PHP]if (isset($_POST["Submit"]))

                      include'package/connect.inc.php ';
                      mysql_select_db ('database');[/PHP]Looks like you are missing a brace after the if statement
                      ok in my code that is pair ( { } ) in if statement. but the same it will automatically save.

                      Comment

                      • code green
                        Recognized Expert Top Contributor
                        • Mar 2007
                        • 1726

                        #12
                        ok in my code that is pair ( { } ) in if statement. but the same it will automatically save.
                        If the $_POST["Submit"] button has been clicked you will write to the database.
                        If you are writing to the database without clicking then your php code is wrong.
                        Can you show the true version (please leave out the HTML)

                        Comment

                        • underscore
                          New Member
                          • Jul 2007
                          • 30

                          #13
                          Originally posted by code green
                          If the $_POST["Submit"] button has been clicked you will write to the database.
                          If you are writing to the database without clicking then your php code is wrong.
                          Can you show the true version (please leave out the HTML)
                          this is the php code:

                          <?php

                          if (isset($_POST["Submit"]))
                          {
                          include'package/connect.inc.php ';
                          mysql_select_db ('database');

                          $user_sql = "INSERT INTO userpass(loginI d,fname,lname,g ender,password, repassword,bdat e,zip,emailadd, accesslevel,reg date,reghours)
                          values('". $_POST["txtlogid"] ."','". $_POST["txtfname"] ."','". $_POST["txtlname"] ."',
                          '". $_POST["mnugender"] ."','". $_POST["txtpasswor d"] ."',
                          '". $_POST["txtretypep ass"]."','". $_POST["mnuMonth"]."-". $_POST["txtday"]."-". $_POST["txtyear"]."',
                          '". $_POST["txtzip"]."',
                          '". $_POST["txtemailad d"]."','". $_POST["mnuAccess"]."',
                          '". date("F j, Y, g:i a")."','". date("H:i:s A")."')";
                          $result = mysql_query($us er_sql);

                          }
                          ?>

                          Comment

                          • code green
                            Recognized Expert Top Contributor
                            • Mar 2007
                            • 1726

                            #14
                            ok sir. my problem is if i run those PHP code it will automatically save to mysql database. in the PHP at the buttom
                            If below is the correct opening of the php code
                            [PHP]if (isset($_POST["Submit"]))
                            {[/PHP]And this is the correct HTML for the submit button
                            [HTML]"><input name="Submit" type="Submit" [/HTML]
                            Then what we seem to be missing now is a closing form tag [HTML]</form>[/HTML]

                            Comment

                            Working...