Forum Moderators: coopster

Message Too Old, No Replies

Submitting forms

         

doof205

12:32 pm on Dec 20, 2004 (gmt 0)



I'm having a bit of a nightmare getting my website to submit a form to a database. If i have the form on a single page it submits fine and takes me to a page saying its been accepted, thats all good. But, when i put the exact same code into a site which uses a manifest to load various content files into a div box, it doesn't work. The data doesn't reach the database, and it redirects to the home page, even if i miss some data it doesn't

I've been at this for a week now and im still struggling, any help would be so so good. I think the problem lies with the way im testing if the form has been submitted although it works on a single page.

Below is the code for my home page, i am loading .inc files into the main content div box. I've taken some code out so dont worry if theres a missing <head> or something.


<?php
require_once("postback.php"); // for postback function
require_once("initFuns.php") ; // initialise page function
$titles = array(); // create empty array
$files = array();
$menu = "";
initPage("manifest.inc","nav");
if ($indx>0)
$index = getParameter('indx');
else
$index = 0;
$inc = $files[$index];
if (file_exists($inc))
$contents = file_get_contents($inc);
else
$contents = file_get_contents("manifest.inc");
$title = $titles[$index];
?>

<body>

<div id="main">
<h1><?=$title?></h1>
<?
if($index==0)
{
include("home.inc");
}
else{include("signup.inc");}?>

</body>
</html>

Here is the code im loading into the above page's main div box. Its called signup.inc


<?
require_once "connection.php";
require_once "postback.php";
$missingData = false;
if (isset($_POST['submitform']))
{ // check that fields are not empty

$firstN = getParameter("firstN1");

if ( strlen($firstN)> 0 && strlen($secondN)> 0 && strlen($userN)> 0 && strlen($password)> 0
&& strlen($address1)> 0 && strlen($address2)> 0 && strlen($town)> 0 && strlen($postcode)> 0
&& strlen($phone)> 0)
{
$qry = "insert into Account values(\"$firstN\",\"$secondN\",\"$userN\",\"$password\",
\"$address1\",\"$address2\",\"$town\",\"$postcode\",\"$phone\")" ;
$result= mysql_query($qry);
if ($result) {
$id = mysql_insert_id();
}
else {
die('Invalid query: ' . mysql_error());

$id = -1 * mysql_error();
}
header("location:insertOk.php?id=$id");
}
else $missingData = true;

}?>

<head>
<title>Jupiter</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>

<p>Please fill in All fields</p>
<? if ($missingData):?>
<p> Missing Data </p>
<? endif;?>

<form action="<?= $_SERVER['PHP_SELF'];?>" method="post">
<fieldset>
<legend align="left">personal details</legend>

<label for="firstN1">First Name:</label>
<input type="text" name="firstN1" value="" size="20" maxlength="20"/>
<br>
</fieldset>
<input type="submit" name="submitform" value="Register"/>
</form>

Thank you so much for any help!

Lewis.

baze22

4:29 pm on Dec 20, 2004 (gmt 0)

10+ Year Member



In this code:
if ($indx>0) 
$index = getParameter('indx');
else
$index = 0;

Where does the $indx parameter get set? Is that a variable that gets passed to the page? If $indx isn't set then your $index does equal 0 and your signup.inc never gets called after the form is sent and then only your homepage would show up. If it is a parameter, you should pass it as a hidden var on your form. Somthing like:

<input name="indx" type="hidden" value="<?=$index;?>">

baze