Jump to content

Recommended Posts

I want to enter the data back once a user click submit and they haven't fill all data in yet.

How would I do that?

Also, if all fields are enter. It will go to another page instead staying on the same page.

I use:
[code]
<form name="create_form" method="POST" action="<?php echo $PHP_SELF; ?>">
[/code]
This will add data to the database, but if I use like
[code]
<form name="create_form" method="POST" action="anotherPage.php">
[/code]
This will not add data to the database.

Full code:
[code]


<?php include("config3.php"); ?>
<?php

if (isset($_POST['create_form'])) {
    submitData();
}

function submitData() {

if (($_POST["NAME"] == "") or ($_POST["QUESTION"] == "")) {
    echo "
    <script type=\"text/javascript\">
    alert(\"Please input all data.\")
    </script>
    ";
}
mysql_select_db($dbNAME) or die($errCon . mysql_error());

    mysql_query("INSERT INTO $tableNEW
        (name,number,question)
        VALUES('$NAME', '$NUMBER','$QUESTION') ")
    or die($errCon . mysql_error());

} //end function
?>

<form name="create_form" method="POST" action="<?php echo $PHP_SELF; ?>">
<table>
<tr>
    <td align="right">Name:</td>
    <td><input name="NAME" size="25"></td>
</tr>

<tr>
    <td align="right">Number:</td>
    <td><select name="NUMBER">
        <option value="1">1
    <option value="2">2
    <option value="3">3
    <option value="4">4
    <option value="5">5
    <option value="6">6
    <option value="7">7
    <option value="8">8
    <option value="9">9
        </select>
    </td>
</tr>

<tr>
    <td align="right">Question:</td>
    <td>
    <textarea name="QUESTION" rows="10" cols="40"></textarea>
    </td>
</tr>

<tr>
    <td colspan="2" align="center"><input type="submit" value="Submit" name="create_form">
    <input type="reset" value="Reset" name="reset"></td>
</tr>

</table>
</form>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/5715-submit-remember-data/
Share on other sites

it sounds like the variables arnt being passed
i had the same problem once try this

[code]
<?php include("config3.php"); ?>
<?php

if (isset($_POST['create_form'])) {
    submitData();

}

function submitData() {
$NAME=$_POST['NAME'];
$NUMBER=$_POST['NUMBER'];
$QUESTION=$_POST['QUESTION'];

if (($_POST["NAME"] == "") or ($_POST["QUESTION"] == "")) {
    echo "
    <script type=\"text/javascript\">
    alert(\"Please input all data.\")
    </script>
    ";
}
mysql_select_db($dbNAME) or die($errCon . mysql_error());

    mysql_query("INSERT INTO $tableNEW
        (name,number,question)
        VALUES('$NAME', '$NUMBER','$QUESTION') ")
    or die($errCon . mysql_error());

} //end function
?>

<form name="create_form" method="POST" action="<?php echo $PHP_SELF; ?>">
<table>
<tr>
    <td align="right">Name:</td>
    <td><input name="NAME" size="25"></td>
</tr>

<tr>
    <td align="right">Number:</td>
    <td><select name="NUMBER">
        <option value="1">1
    <option value="2">2
    <option value="3">3
    <option value="4">4
    <option value="5">5
    <option value="6">6
    <option value="7">7
    <option value="8">8
    <option value="9">9
        </select>
    </td>
</tr>

<tr>
    <td align="right">Question:</td>
    <td>
    <textarea name="QUESTION" rows="10" cols="40"></textarea>
    </td>
</tr>

<tr>
    <td colspan="2" align="center"><input type="submit" value="Submit" name="create_form">
    <input type="reset" value="Reset" name="reset"></td>
</tr>

</table>
</form>

[/code]

by adding this
$NAME=$_POST['NAME'];
$NUMBER=$_POST['NUMBER'];
$QUESTION=$_POST['QUESTION'];
when you submit the form the php part of the page will grab the variables
Link to comment
https://forums.phpfreaks.com/topic/5715-submit-remember-data/#findComment-20500
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.