Jump to content


Photo

submit & remember data


  • Please log in to reply
1 reply to this topic

#1 vietboy505

vietboy505
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 24 March 2006 - 09:03 PM

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:
<form name="create_form" method="POST" action="<?php echo $PHP_SELF; ?>">
This will add data to the database, but if I use like
<form name="create_form" method="POST" action="anotherPage.php">
This will not add data to the database.

Full 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>


#2 shortj75

shortj75
  • Members
  • PipPipPip
  • Advanced Member
  • 118 posts
  • LocationPort Huron,mi

Posted 25 March 2006 - 07:48 AM

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

<?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>


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

The Short One

hopfully this helps if it doesn't sorry
i won't write the code for you!!! you don't learn that way




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users