Jump to content

Archived

This topic is now archived and is closed to further replies.

vietboy505

submit & remember data

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]

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

×

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.