...

View Full Version : Need help with this form processing script



kevinkhan
02-23-2010, 12:07 PM
When i click submit.. A blank page is returned.. I want the same form to be returned and the $message to be displayed on top of the form.. Can anyone tell me what is wrong with this code ??


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Event Promotion</title>


<!--
<script type="text/javascript" src="js/validation.js"></script>
-->

</head>
<body>
<?php
$dbHost = 'xxxx';
$dbName = 'xxxx';
$dbUser = 'xxxx';
$dbPass = 'xxxx';


$conn = mysql_connect($dbHost, $dbUser, $dbPass) or die('Error connecting to mysql'.mysql_error());
mysql_select_db($dbName);


function confirm_query($result_set)
{
if (!$result_set)
{
die("Database query failed " . mysql_error());
}
}

if(isset($_POST['submit']))
{
// echo "hello";
$firstName = mysql_prep($_POST['firstName']);
$lastName = trim(mysql_prep($_POST['lastName']));
$mobile = mysql_prep($_POST['mobile']);
$email = mysql_prep($_POST['email']);
$county = trim(mysql_prep($_POST['county']));
$dateOfBirth = mysql_prep($_POST['date3']."-".$_POST['date2']."-".$_POST['date1']);
$gender = trim(mysql_prep($_POST['gender']));
$events = implode(', ', $_POST['events']);
$comments = trim(mysql_prep($_POST['comments']));


echo $firstName;


$query = "INSERT INTO user
(
firstName,lastName,mobile,email,county,dateOfBirth,gender,comments,events
)
VALUES
(
'{$firstName}','{$lastName}','{$mobile}','{$email}','{$county}','{$dateOfBirth}','{$gender}','{$even ts}','{$comments}'
)";



$result = mysql_query($query, $conn);

confirm_query($result);
if(mysql_affected_rows() ==1)
{
// Success
$message = "Thanks for submitting your details.";
echo "<p class=\"errorMessage\">".$message."</p>";
}
else
{
// Failed
$message = "The page update failed.";
$message .= "<br />". mysql_error();
}


}


?>

<form name="frm" action="index.php" method="POST">
<table width="100%" border="0" cellspacing="2" cellpadding="3" class="mainForm">
<tr>
<td class="normalText" align="left" style="padding:0px 0px 0px 33px">
<table border="0" cellspacing="3" cellpadding="2">
<tr>
<td class="normalHeading" colspan="2" style="padding-bottom:6px">
Join Our Mailing List
<div id="error_msg" class="txtErrorMsg" align="center">&nbsp;</div>
<?php echo "<p>".$message."</p>"?>
</td>
</tr>
<tr>
<td class="normalText" width="30%">First Name</td>
<td><input type="text" name="firstName" id="firstName" class="input1" style="width:195px" maxlength="10"/></td>
</tr>
<tr>
<td class="normalText">Last Name</td>
<td><input type="text" name="lastName" id="lastName" class="input1" style="width:195px" maxlength="10"/></td>
</tr>
<tr>
<td class="normalText">Mobile</td>
<td><input type="text" name="mobile" id="mobile" class="input1" style="width:195px" maxlength="10" onkeypress="return fnIsIntNumber(event,this);"/></td>
</tr>
<tr>
<td class="normalText">E mail</td>
<td><input type="text" name="email" id="email" class="input1" style="width:195px" onblur="IsEmail(this.vlaue)"/></td>
</tr>
<tr>
<td class="normalText">Home Town</td>
<td>
<select name="county" id="county" style="width:197px;height:24px">
<option value="0">--- Select ---</option>
<option value="Antrim">Antrim</option>
<option value=Armagh>Armagh</option>
<option value=Carlow>Carlow</option>
<option value=Cavan>Cavan</option>
<option value=Clare>Clare</option>
<option value=Cork>Cork</option>
<option value=Derry>Derry</option>
<option value=Donegal>Donegal</option>
<option value=Down>Down</option>
<option value=Dublin>Dublin</option>
<option value=Fermanagh>Fermanagh</option>
<option value=Galway>Galway</option>
<option value=Kerry>Kerry</option>
<option value=Kildare>Kildare</option>
<option value=Kilkenny>Kilkenny</option>
<option value=Laois>Laois</option>
<option value=Leitrim>Leitrim</option>
<option value=Limerick>Limerick</option>
<option value=Longford>Longford</option>
<option value=Louth>Louth</option>
<option value=Mayo>Mayo</option>
<option value=Meath>Meath</option>
<option value=Monaghan>Monaghan</option>
<option value=Offaly>Offaly</option>
<option value=Roscommon>Roscommon</option>
<option value=Sligo>Sligo</option>
<option value=Tipperary>Tipperary</option>
<option value=Tyrone>Tyrone</option>
<option value=Waterford>Waterford</option>
<option value=Westmeath>Westmeath</option>
<option value=Wexford>Wexford</option>
<option value=Wicklow>Wicklow</option>
</select>
</td>
</tr>
<tr>
<td class="normalText">Date Of Birth</td>
<td>
<select name="date1" style="width:43px">
<option value=1>1</option><option value=2>2</option><option value=3>3</option><option value=4>4</option><option value=5>5</option><option value=6>6</option><option value=7>7</option><option value=8>8</option><option value=9>9</option><option value=10>10</option><option value=11>11</option><option value=12>12</option><option value=13>13</option><option value=14>14</option><option value=15>15</option><option value=16>16</option><option value=17>17</option><option value=18>18</option><option value=19>19</option><option value=20>20</option><option value=21>21</option><option value=22>22</option><option value=23>23</option><option value=24>24</option><option value=25>25</option><option value=26>26</option><option value=27>27</option><option value=28>28</option><option value=29>29</option><option value=30>30</option><option value=31>31</option>
</select>
<select name="date2" style="width:43px">
<option value=1>1</option><option value=2>2</option><option value=3>3</option><option value=4>4</option><option value=5>5</option><option value=6>6</option><option value=7>7</option><option value=8>8</option><option value=9>9</option><option value=10>10</option><option value=11>11</option><option value=12>12</option>
</select>
<select name="date3" style="width:106px">
<option value=1955>1955</option><option value=1956>1956</option><option value=1957>1957</option><option value=1958>1958</option><option value=1959>1959</option><option value=1960>1960</option><option value=1961>1961</option><option value=1962>1962</option><option value=1963>1963</option><option value=1964>1964</option><option value=1965>1965</option><option value=1966>1966</option><option value=1967>1967</option><option value=1968>1968</option><option value=1969>1969</option><option value=1970>1970</option><option value=1971>1971</option><option value=1972>1972</option><option value=1973>1973</option><option value=1974>1974</option><option value=1975>1975</option><option value=1976>1976</option><option value=1977>1977</option><option value=1978>1978</option><option value=1979>1979</option><option value=1980>1980</option><option value=1981>1981</option><option value=1982>1982</option><option value=1983>1983</option><option value=1984>1984</option><option value=1985>1985</option><option value=1986>1986</option><option value=1987>1987</option><option value=1988>1988</option><option value=1989>1989</option><option value=1990>1990</option><option value=1991>1991</option><option value=1992>1992</option><option value=1993>1993</option><option value=1994>1994</option><option value=1995>1995</option><option value=1996>1996</option><option value=1997>1997</option><option value=1998>1998</option><option value=1999>1999</option><option value=2000>2000</option><option value=2001>2001</option><option value=2002>2002</option><option value=2003>2003</option><option value=2004>2004</option><option value=2005>2005</option><option value=2006>2006</option><option value=2007>2007</option><option value=2008>2008</option><option value=2009>2009</option><option value=2010>2010</option>
</select>
</td>
</tr>
<tr>
<td class="normalText">Gender</td>
<td valign="middle" valign="middle">
<input type="radio" name="gender" id="genderM" value="1" />&nbsp;Male&nbsp;&nbsp;&nbsp;&nbsp;
<input type="radio" name="gender" id="genderFM" value="0" checked/>&nbsp;Female
</td>
</tr>
<tr>
<td class="normalText">Comments</td>
<td>
<textarea name="comments" id="comment" cols="22" rows="3" ></textarea>
</td>
</tr>
<tr>
<td class="normalText" valign="top">Events you<br /> would be <br />interested in</td>
<td valign="middle" align="left" style="margin: 0px">
<table border="0" cellspacing="0" cellpadding="0" style="margin:0px" class="tblEvents">
<tr>
<td><input class="events" type="checkbox" name="events[]" value="Teenage Discos" />&nbsp;&nbsp;Teenage Discos</td>
<td><input class="events" type="checkbox" name="events[]" value="Concerts" />&nbsp;&nbsp;Concerts</td>
</tr>
<tr>
<td><input class="events" type="checkbox" name="events[]" value="Club Nights" />&nbsp;&nbsp;Club Nights</td>
<td><input class="events" type="checkbox" name="events[]" value="70s Nights" />&nbsp;&nbsp;70s Nights</td>
</tr>
<tr>
<td><input class="events" type="checkbox" name="events[]" value="80s Nights" />&nbsp;&nbsp;80s Nights</td>
<td><input class="events" type="checkbox" name="events[]" value="Circuses" />&nbsp;&nbsp;Circuses</td>
</tr>
<tr>
<td><input class="events" type="checkbox" name="events[]" value="Funderland" />&nbsp;&nbsp;Funderland</td>
<td><input class="events" type="checkbox" name="events[]" value="Matches" />&nbsp;&nbsp;Sports Events<br /></td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="normalText">&nbsp;</td>
<td valign="middle"><input class="send" type="image" value='submit' src="images/submit.gif" name="submit" onclick="return validchk();"/></td>
</tr>
</table>
</td>
</tr>
</table>
</form>

</body>
</html>
<?php mysql_close($conn); ?>

abduraooft
02-23-2010, 12:17 PM
If the error reporting is not turned on, do it first, see http://www.codingforums.com/showpost.php?p=617060&postcount=13



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum