Here is a script I have been working on:
<html><body>
<font face="arial">
<title>Univelt Data</title>
<?php
if (isset($_POST['submit']))
{
if ($submit=="Test")
{ include "IncludeVariables.php";
include "IncludeHiddenForm.php";
include "IncludeHTML.php";
}
elseif ($submit=="Insert into Database")
{ include "IncludeVariables.php";
include "IncludeHiddenForm.php";
include "IncludeInsert.php"; }
else
{ echo "Submit button value not properly defined."; }
}
else
{ include "IncludeForm.php"; }
?>
<form method="post" action="<?php echo $_SERVER[’SCRIPT_NAME’] ?>">
<INPUT TYPE="SUBMIT" NAME="submit" VALUE="Test">
<INPUT TYPE="SUBMIT" NAME="submit" VALUE="Insert into Database">
<p>
The following files are in actuality more complicated; I have cut them down.
IncludeVariables.php:
$title = $_POST['title'];
IncludeHiddenForm.php:
<input type="hidden" name="title" value="<?php echo $title;?>">
IncludeHTML.php:
<?php echo $title; ?>
IncludeInsert.php:
$host = 'localhost';
$user = 'username';
$pw = 'pass';
$db = 'database';
$connect = mysql_connect($host, $user, $pw)
or die ("Could not connect.");
mysql_select_db($db);
$table1 = 'table;
$prod_statement = "INSERT INTO $table1 (title) VALUES('$title')"; echo "Item add";
if(mysql_query($prod_statement, $connect)){
print " successful.<br/>";
}
else { print " failed.<br/>"; }
IncludeForm.php:
What is this book's title?<br>
<input type="text" size="100" name="title" maxlength = "255">
The basic idea is that the form is displayed, information entered, the user pushes "Test" which will validate the form and display the data as it will be formatted for the website. If all goes well, the user can then submit the data to the database.
The issue is that when I have the form submit to itself, the values of the variables do not get included. It works if I submit the values from outside, for example, if I have a "dataform.html" which submits the values to this script, they come through perfectly initially. I've looked all over and tried several variations of self reference, including $SERVER[’PHP_SELF’], $SERVER[’SCRIPT_NAME’], and even simply using the actual name of the script. I also included the hidden form to try to retain the values; but no dice. When I press "Test", I get a blank page, and when I look at the source, I can see that the values are non-existent in the hidden form (i.e. <input type="hidden" name="title" value="">). I've looked all over for a solution to this, but I can't figure out what I'm doing wrong. I'd be grateful for any help you can give me.
None of the input has been sanitized of validated yet; I'm just trying to make it work first.
Thanks,
-kirakira