Yay
01-16-2010, 11:12 AM
Hi there,
I'm having problems with my validation script for a form. Basically, it is not sending any data to the database, and not giving any confirmation messages. It's simply displaying an validation error message first, when nothing has been done with the form. Here's my code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Pyongyang Pair — Database Control Panel</title>
<!-- Stylesheets -->
<link rel="stylesheet" href="style.css" media="screen" />
<!-- JavaScript -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="http://happykittens.co.uk/s2/gta/images/application.js"></script>
<script type="text/javascript" src="js/rounded-corners.js"></script>
<script type="text/javascript" src="js/form-field-tooltip.js"></script>
</head>
<body>
<!-- NAVIGATION -->
<div id="footer_wrap">
<div id="footer">
<div class="link1_wrap open">
<div class="link1_header">Manage</div>
<ul class="up">
<li><a href="records/add.php">Add</a></li>
<li><a href="records/view.php">View</a></li>
<li><a href="records/amend.php">Amend</a></li>
<!-- Change for MAMP (on a Mac), WAMP (on Windows) or LAMP (linux) -->
<li><a href="http://localhost:8888/WAMP/">phpMyAdmin</a></li>
</ul>
</div>
<div class="link2_wrap open">
<div class="link3_header">Guides</div>
<ul class="up">
<li><a href="guides/start.html">General</a></li>
<li><a href="guides/phpmyadmin.html">phpMyAdmin</a></li>
<li><a href="guides/adding.html">Adding Records</a></li>
</ul>
</div>
</div>
</div>
<!-- begin of website -->
<!-- header -->
<div id="wrapper">
<!-- logo -->
<div id="logo"><img src="/tests/a/img/logo.png" alt="CP Logo" /></div>
<!-- welcome message -->
<h2>Welcome to the Database Control Panel</h2>
<!-- content -->
<?php
$con=mysql_connect('localhost', 'root', 'root');
if(!$con)
{
die('connection to the db failed. please contact a sysop');
}
if(isset($_POST['newrecord'])){
/* 2 */
echo
$name ='';
$gigs ='';
$mailing ='';
$mail ='';
$name = $_POST['name'];
$gigs = $_POST['gigs'];
$mailing = $_POST['mailing'];
$mail = $_POST['mail'];
}
if(trim($name)=='')
{
$errmsg ='Please enter the name of the person.';
}
else if(trim($gigs)=='')
{
$errmsg= 'Please enter a number in the gigs field.';
}
else if(trim($mailing)=='')
{
$errmsg= 'Please select a value in the mailing list field';
}
else if(trim($mail)=='')
{
$errmsg= 'Please enter the persons email.';
}
if(isset($errmsg)){
echo $errmsg;
}else{
mysql_select_db("pp", $con);
$name=($_POST['name']);
$gigs=($_POST['gigs']);
$mailing=($_POST['mailing']);
$mail=($_POST['mail']);
$sql="INSERT INTO members (Name,Gigs,Mailing,Mail) VALUES ('$name','$gigs', '$mailing','$mail')";
if (!mysql_query($sql,$con)) {
die('Error: ' . mysql_error());
}
echo "<b>You have successfully entered this record into the database for <em>$name</em>.</b>";
mysql_close($con);
}
?>
<?php
$con =mysql_connect("localhost","root","root");
if (!$con)
{
//if there is no DB fail.
die('connection failed ' . mysql_error());
}
//carry on
else
{
//if there is something in the field sent from the post check it and see if you can add it to the database
if(isset($_POST['sent'])){
}else{
//display the error messages
}
}
//disply the form here
?>
<form action="add.php" name="newrecord" method="post">
<table border="0px solid #555555">
<tr>
<td><h3>Name <h3></td>
<td><input type=xt class="form" name="name" width="650px" maxlength="30" id="name" tooltipText="Add the full name of the new database entrant."></td><br>
</tr>
<tr>
<td><h3>Age <h3></td>
<td><input type=xt class="form" name="name" width="650px" maxlength="3" id="age" tooltipText="Enter the numeric age of the entrant."></td><br>
</tr>
<tr>
<td><h3>Gigs Attended <h3></td>
<td><input type=xt class="form" name="name" width="650px" maxlength="2" id="name" tooltipText="Number of confirmed gigs this entrant has attended. Set at 0 if unsure."></td><br>
</tr>
<img src="lightbulb.png" alt="" class="lightbulb" />
<tr>
<td><h3>Mailing List <h3></td>
<td><input type="checkbox" class="form" name="name" width="650px" maxlength="30" id="name" tooltipText="Did the entrant want to be signed up for the mailing list (newsletters, email notifications)?"></td><br>
</tr>
<tr>
<td><h3>E-mail <h3></td>
<td><input type=xt class="form" name="name" width="650px" maxlength="80" id="name" tooltipText="Enter the given e-mail address here. Triple check this."></td><br>
</tr>
<input type="hidden" name="newrecord" value="1" />
<td><input type="submit" class="submit" value="Add new Record" name="newrecord"></td>
</div>
</table>
</form>
<script type="text/javascript">
var tooltipObj = new DHTMLgoodies_formTooltip();
tooltipObj.setTooltipPosition('left');
tooltipObj.setPageBgColor('#000');
tooltipObj.setCloseMessage('Exit');
tooltipObj.initFormFieldTooltip();
</script>
</body>
</html>
Any help is appreciated.
I'm having problems with my validation script for a form. Basically, it is not sending any data to the database, and not giving any confirmation messages. It's simply displaying an validation error message first, when nothing has been done with the form. Here's my code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Pyongyang Pair — Database Control Panel</title>
<!-- Stylesheets -->
<link rel="stylesheet" href="style.css" media="screen" />
<!-- JavaScript -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="http://happykittens.co.uk/s2/gta/images/application.js"></script>
<script type="text/javascript" src="js/rounded-corners.js"></script>
<script type="text/javascript" src="js/form-field-tooltip.js"></script>
</head>
<body>
<!-- NAVIGATION -->
<div id="footer_wrap">
<div id="footer">
<div class="link1_wrap open">
<div class="link1_header">Manage</div>
<ul class="up">
<li><a href="records/add.php">Add</a></li>
<li><a href="records/view.php">View</a></li>
<li><a href="records/amend.php">Amend</a></li>
<!-- Change for MAMP (on a Mac), WAMP (on Windows) or LAMP (linux) -->
<li><a href="http://localhost:8888/WAMP/">phpMyAdmin</a></li>
</ul>
</div>
<div class="link2_wrap open">
<div class="link3_header">Guides</div>
<ul class="up">
<li><a href="guides/start.html">General</a></li>
<li><a href="guides/phpmyadmin.html">phpMyAdmin</a></li>
<li><a href="guides/adding.html">Adding Records</a></li>
</ul>
</div>
</div>
</div>
<!-- begin of website -->
<!-- header -->
<div id="wrapper">
<!-- logo -->
<div id="logo"><img src="/tests/a/img/logo.png" alt="CP Logo" /></div>
<!-- welcome message -->
<h2>Welcome to the Database Control Panel</h2>
<!-- content -->
<?php
$con=mysql_connect('localhost', 'root', 'root');
if(!$con)
{
die('connection to the db failed. please contact a sysop');
}
if(isset($_POST['newrecord'])){
/* 2 */
echo
$name ='';
$gigs ='';
$mailing ='';
$mail ='';
$name = $_POST['name'];
$gigs = $_POST['gigs'];
$mailing = $_POST['mailing'];
$mail = $_POST['mail'];
}
if(trim($name)=='')
{
$errmsg ='Please enter the name of the person.';
}
else if(trim($gigs)=='')
{
$errmsg= 'Please enter a number in the gigs field.';
}
else if(trim($mailing)=='')
{
$errmsg= 'Please select a value in the mailing list field';
}
else if(trim($mail)=='')
{
$errmsg= 'Please enter the persons email.';
}
if(isset($errmsg)){
echo $errmsg;
}else{
mysql_select_db("pp", $con);
$name=($_POST['name']);
$gigs=($_POST['gigs']);
$mailing=($_POST['mailing']);
$mail=($_POST['mail']);
$sql="INSERT INTO members (Name,Gigs,Mailing,Mail) VALUES ('$name','$gigs', '$mailing','$mail')";
if (!mysql_query($sql,$con)) {
die('Error: ' . mysql_error());
}
echo "<b>You have successfully entered this record into the database for <em>$name</em>.</b>";
mysql_close($con);
}
?>
<?php
$con =mysql_connect("localhost","root","root");
if (!$con)
{
//if there is no DB fail.
die('connection failed ' . mysql_error());
}
//carry on
else
{
//if there is something in the field sent from the post check it and see if you can add it to the database
if(isset($_POST['sent'])){
}else{
//display the error messages
}
}
//disply the form here
?>
<form action="add.php" name="newrecord" method="post">
<table border="0px solid #555555">
<tr>
<td><h3>Name <h3></td>
<td><input type=xt class="form" name="name" width="650px" maxlength="30" id="name" tooltipText="Add the full name of the new database entrant."></td><br>
</tr>
<tr>
<td><h3>Age <h3></td>
<td><input type=xt class="form" name="name" width="650px" maxlength="3" id="age" tooltipText="Enter the numeric age of the entrant."></td><br>
</tr>
<tr>
<td><h3>Gigs Attended <h3></td>
<td><input type=xt class="form" name="name" width="650px" maxlength="2" id="name" tooltipText="Number of confirmed gigs this entrant has attended. Set at 0 if unsure."></td><br>
</tr>
<img src="lightbulb.png" alt="" class="lightbulb" />
<tr>
<td><h3>Mailing List <h3></td>
<td><input type="checkbox" class="form" name="name" width="650px" maxlength="30" id="name" tooltipText="Did the entrant want to be signed up for the mailing list (newsletters, email notifications)?"></td><br>
</tr>
<tr>
<td><h3>E-mail <h3></td>
<td><input type=xt class="form" name="name" width="650px" maxlength="80" id="name" tooltipText="Enter the given e-mail address here. Triple check this."></td><br>
</tr>
<input type="hidden" name="newrecord" value="1" />
<td><input type="submit" class="submit" value="Add new Record" name="newrecord"></td>
</div>
</table>
</form>
<script type="text/javascript">
var tooltipObj = new DHTMLgoodies_formTooltip();
tooltipObj.setTooltipPosition('left');
tooltipObj.setPageBgColor('#000');
tooltipObj.setCloseMessage('Exit');
tooltipObj.initFormFieldTooltip();
</script>
</body>
</html>
Any help is appreciated.