Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8968297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:26:05+00:00 2026-06-15T17:26:05+00:00

I wonder is it possible to keep the user input inside form field after

  • 0

I wonder is it possible to keep the user input inside form field after form submitted, so that the user can update the entry. I’ve a html registration form [with some JS validation], then a php file to insert data to sql & meanwhile display back the inserted data in a table view. i also include the form’s html code in php file so i can see the form after being submitted. but i couldn’t keep the data in the field after form submitted! here is the form:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <script type="text/javascript">
            <!--
            function validateNum(evt) {
                        var theEvent = evt;
                        var key = theEvent.keyCode || theEvent.which;
                        key = String.fromCharCode( key );
                        var regex = /[0-9]/;

                        if( !regex.test(key) ) {
                            theEvent.returnValue = false;
                            if(theEvent.preventDefault) theEvent.preventDefault();
                        }
                    }       
            function validate(evt){

                if( document.myForm.ic.value == ""){
                    alert( "IC Number cann't be empty!" );
                    document.myForm.ic.focus() ;
                    return false;}
                else if(isNaN( document.myForm.ic.value ) || document.myForm.ic.value.length != 12){
                    evt.preventDefault();

                    alert( "Please provide your correct IC Number!" );
                    document.myForm.ic.focus() ;
                    return false;}
                if( document.myForm.name.value == "") {

                    alert( "Name cann't be empty!" );
                    document.myForm.name.focus() ;
                    return false;
                } 

                if( document.myForm.contact.value == ""){

                    alert( "Contact number cann't be empty!");
                    document.myForm.contact.focus() ;
                    return false;
                    } else if(isNaN( document.myForm.contact.value )) 
                    {
                    evt.preventDefault();

                    alert( "Please provide your correct Contact Number!" );
                    document.myForm.contact.focus() ;
                    return false;

                }
                 if( document.myForm.address.value == "" ){
                    alert( "Please provide your Address!" );
                    document.myForm.address.focus() ;
                    return false;
                }
            }

            //-->
        </script>
    </head>
    <style type="text/css">
        h2 {
            color: #06C;
        }
        body {
            background-color: #FFC;
        }
    </style>

    <body>
        <form name="myForm" method="post" action="insert.php" onsubmit="return(validate(event));">
            <div align="center"><br>
                    <table width="453" border="0">
                        <tr>
                            <th colspan="4" bgcolor="#99FFFF" scope="col">
                                <h3>Workshop Name: PHP! </h3></th>
                        </tr>
                        <tr bgcolor="#99FF99">
                            <td width="142"> IC Number</td>
                            <td width="15"><div align="center">:</div></td>
                            <td colspan="2"><div align="right">
                                    <input
                                        name="ic" type="text" id="ic" maxlength="12" size="45" onkeypress='validateNum(event)'/>
                                </div></td>
                        </tr>
                        <tr bgcolor="#99FFFF">
                            <td>Full Name</td>
                            <td><div align="center">:</div></td>
                            <td colspan="2"><div align="right">
                                    <input
                                        name="name" type="text" id="name" size="45"/>
                                </div></td>
                        </tr>
                        <tr bgcolor="#99FF99">
                            <td>Contact No.</td>
                            <td><div align="center">:</div></td>
                            <td colspan="2"><div align="right">
                                    <input
                                        name="contact" type="text" id="contact" size="45" onkeypress='validateNum(event)' />
                                </div></td>
                        </tr>
                        <tr bgcolor="#99FFFF">
                            <td>Email</td>
                            <td><div align="center">:</div></td>
                            <td colspan="2"><div align="right">
                                    <input
                                        name="mail" type="text" id="mail" size="45"/>
                                </div></td>
                        </tr>
                        <tr bgcolor="#99FF99">
                            <td height="60">Address</td>
                            <td><div align="center">:</div></td>
                            <td colspan="2">
                                <div align="right">
                                    <textarea name="address" id="address" cols="35" rows="3"></textarea>
                                </div>
                            </td>
                        </tr>
                        <tr bgcolor="#99FFFF">
                            <td colspan="2">&nbsp;</td>
                            <td width="231"><input type="reset" value="Clear" /></td>
                            <td width="47"><div align="right">
                                    <input type="submit" value="Submit" />
                                </div></td>
                        </tr>
                    </table>

                    <br>
                        </div>
                        </form>
                     </body>
                 </html>

here is the insert.php file:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <script type="text/javascript">
            <!--
            function validateNum(evt) {
                        var theEvent = evt;
                        var key = theEvent.keyCode || theEvent.which;
                        key = String.fromCharCode( key );
                        var regex = /[0-9]/;

                        if( !regex.test(key) ) {
                            theEvent.returnValue = false;
                            if(theEvent.preventDefault) theEvent.preventDefault();
                        }
                    }       
            function validate(evt){

                if( document.myForm.ic.value == ""){
                    alert( "IC Number cann't be empty!" );
                    document.myForm.ic.focus() ;
                    return false;}
                else if(isNaN( document.myForm.ic.value ) || document.myForm.ic.value.length != 12){
                    evt.preventDefault();

                    alert( "Please provide your correct IC Number!" );
                    document.myForm.ic.focus() ;
                    return false;}
                if( document.myForm.name.value == "") {

                    alert( "Name cann't be empty!" );
                    document.myForm.name.focus() ;
                    return false;
                } 

                if( document.myForm.contact.value == ""){

                    alert( "Contact number cann't be empty!");
                    document.myForm.contact.focus() ;
                    return false;
                    } else if(isNaN( document.myForm.contact.value )) 
                    {
                    evt.preventDefault();

                    alert( "Please provide your correct Contact Number!" );
                    document.myForm.contact.focus() ;
                    return false;

                }
                 if( document.myForm.address.value == "" ){
                    alert( "Please provide your Address!" );
                    document.myForm.address.focus() ;
                    return false;
                }
            }

            //-->
        </script>
    </head>
    <style type="text/css">
        h2 {
            color: #06C;
        }
        body {
            background-color: #FFC;
        }
    </style>

    <body>
        <form name="myForm" method="post" action="update.php" onsubmit="return(validate(event));">
            <div align="center"><br>
                    <table width="453" border="0">
                        <tr>
                            <th colspan="4" bgcolor="#99FFFF" scope="col">
                                <h3>Workshop Name: PHP! </h3></th>
                        </tr>
                        <tr bgcolor="#99FF99">
                            <td width="142"> IC Number</td>
                            <td width="15"><div align="center">:</div></td>
                            <td colspan="2"><div align="right">
                                    <input
                                        name="ic" type="text" id="ic" maxlength="12" size="45" onkeypress='validateNum(event)'/>
                                </div></td>
                        </tr>
                        <tr bgcolor="#99FFFF">
                            <td>Full Name</td>
                            <td><div align="center">:</div></td>
                            <td colspan="2"><div align="right">
                                    <input
                                        name="name" type="text" id="name" size="45"/>
                                </div></td>
                        </tr>
                        <tr bgcolor="#99FF99">
                            <td>Contact No.</td>
                            <td><div align="center">:</div></td>
                            <td colspan="2"><div align="right">
                                    <input
                                        name="contact" type="text" id="contact" size="45" onkeypress='validateNum(event)' />
                                </div></td>
                        </tr>
                        <tr bgcolor="#99FFFF">
                            <td>Email</td>
                            <td><div align="center">:</div></td>
                            <td colspan="2"><div align="right">
                                    <input
                                        name="mail" type="text" id="mail" size="45"/>
                                </div></td>
                        </tr>
                        <tr bgcolor="#99FF99">
                            <td height="60">Address</td>
                            <td><div align="center">:</div></td>
                            <td colspan="2">
                                <div align="right">
                                    <textarea name="address" id="address" cols="35" rows="3"></textarea>
                                </div>
                            </td>
                        </tr>
                        <tr bgcolor="#99FFFF">
                            <td colspan="2">&nbsp;</td>
                            <td width="231"><input type="reset" value="Clear" /></td>
                            <td width="47"><div align="right">
                                    <input type="submit" value="Update" />
                                </div></td>
                        </tr>
                    </table>

                    <br>
                        </div>
                        </form>


                    <br>
                        </div>
                        </form>

                        <div align="center">
                          <?php
                        if (!mysql_connect('localhost', 'root', '')) {

                            echo "Connected";
                        }


                        mysql_select_db("workshop");


// Get values from form
                        $ic = mysql_real_escape_string($_POST['ic']);
                        $name = mysql_real_escape_string($_POST['name']);
                        $contact = mysql_real_escape_string($_POST['contact']);
                        $mail = mysql_real_escape_string($_POST['mail']);
                        $address = mysql_real_escape_string($_POST['address']);

                        if (staff_detail_exist($ic) == "available") {

                            insert_staff_detail($ic, $name, $contact, $mail, $address, $paytype);
                            echo "<p style='text-align:center; color:green;'>" . "Workshop application successful! You will be notified shortly via E-mail after confirmation! Thank You!";
                        } else if (staff_detail_exist($ic) == "exist") {

                            echo "<p style='text-align:center; color:red;'>" . "Record already exists! Please enter another Staff ID. Thank You!" . "</p>";
                        }

                        function insert_staff_detail($ic, $name, $contact, $mail, $address, $paytype) {

                            $sql = "INSERT INTO apply (staffid, staffname, staffno, staffemail, staffaddress, paytype) VALUES ('$ic', '$name', '$contact', '$mail', '$address','$paytype')";
                            mysql_query($sql);
                        }

                        function staff_detail_exist($ic) {

                            $result = null;
                            $sql = "SELECT * FROM apply WHERE staffid = '$ic'";
                            $data = mysql_query($sql);

                            if (mysql_num_rows($data) == 0) {

                                $result = "available";
                            } else {

                                $result = "exist";
                            }

                            return $result;
                        }

                $staffid = $_POST['ic'];

                $con = mysql_connect("localhost", "root", "");
                if (!$con) {
                    die('Could not connect: ' . mysql_error());
                }

                mysql_select_db("workshop", $con);
                $result = mysql_query("SELECT * FROM apply where staffid = '$ic'");

                echo "<table width=400 border=1 cellpadding=0 align=center>";

                while ($row = mysql_fetch_array($result)) {
                    echo "<tr>";
                    echo "<th>Staff/IC Number: </th><td>" . "<center>" . $row['staffid'] . "</center>" . "</td>";
                    echo "</tr>";
                    echo "<th>Name: </th><td>" . "<center>" . $row['staffname'] . "</center>" . "</td>";
                    echo "</tr>";
                    echo "<th>Email: </th><td>" . "<center>" . $row['staffemail'] . "</center>" . "</td>";
                    echo "</tr>";
                    echo "<th>Contact No.: </th><td>" . "<center>" . $row['staffno'] . "</center>" . "</td>";
                    echo "</tr>";
                    echo "<th>Address: </th><td>" . "<center>" . $row['staffaddress'] . "</center>" . "</td>";
                    echo "</tr>";
                }
                echo "</table>";

                mysql_close($con);
 ?>
                    </body>
                </html>

I’ve tried to add like value="<? echo "$row['staffid']"?>" in the form’s field at php file but no luck! I’ve only basic in php. So, any help? thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T17:26:06+00:00Added an answer on June 15, 2026 at 5:26 pm

    thanks all, its finally working 🙂 i’ve used value="<?php echo isset($_POST['myField']) ? $_POST['myField'] : 'myField_db' ?>" inside the input tag. so, its like: <input type="text" name="myField" value="<?php echo isset($_POST['myField']) ? $_POST['myField'] : 'myField_db' ?>" /> where myField is input name & myField_db is the column name from database.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wonder if it's possible to add an Event Listener to a MovieClip that
I wonder if is it possible to run mysql command which can select an
I wonder if it's possible to load jQuery within Opera User JavaScript , so
I wonder is it possible to write a console application that will surf to
After reading this question I started to wonder: is it possible to have a
I wonder if it's possible to keep methods for a Python class in a
I wonder is it possible to keep list of files or folders opened before
I just had an idea that I wonder whether is possible in java. Let's
I wonder if its possible to keep child elements from being animated. like in
I wonder is it possible to get cookies under another domain rather than my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.