I’m having trouble with this input form that saves to my database. It is connecting to the database, but it is not saving the data properly. Is it something I am doing wrong?
Here is the code:
[php]<?php
/*
require_once(‘general.php’);
require_once(‘db/db_connection.php’);
if (isset($_POST['submitBtn'])) {
$name = (isset($_POST['name'])) ? htmlentities($_POST['name']) : '' ;
$comment = (isset($_POST['comment'])) ? htmlentities($_POST['comment']) : '' ;
$location = (isset($_POST['location'])) ? htmlentities($_POST['location']) : '' ;
$state = (isset($_POST['state'])) ? htmlentities($_POST['state']) : '' ;
$discipline = (isset($_POST['discipline'])) ? htmlentities($_POST['discipline']) : '' ;
$website = (isset($_POST['website'])) ? htmlentities(str_replace('http://','',$_POST['website'])) : '' ;
$email = (isset($_POST['email'])) ? htmlentities($_POST['email']) : '' ;
$actDate = date("Y-m-d H:i:s");
//Minimum name and comment length.
if ((strlen($name) > 2) && (strlen($comment) > 5)){
$sql = "INSERT INTO distributor (name,text,insertdate,location,state,discipline,web,email) VALUES (";
$sql .= "'".$name."','".$comment."','".$actDate."','".$location."','".$state."','".$discipline."','".$website."','".$email."')";
$MyDb->f_ExecuteSql($sql);
}
header("Location: http://safepathproducts.com/mail/thank-you.php");
}
else {
?>
First Name
Last Name
Phone 10 Digits
Company Name
Website
Email
(firstname,lastname,insertdate,phone,companyname,email,web,text) VALUES
*/
require_once(‘general.php’);
require_once(‘db/db_connection.php’);
if (isset($_POST['submitBtn'])) {
$firstname = (isset($_POST['firstname'])) ? htmlentities($_POST['firstname']) : '' ;
$lastname = (isset($_POST['lastname'])) ? htmlentities($_POST['lastname']) : '' ;
$phone = (isset($_POST['phone'])) ? htmlentities($_POST['phone']) : '' ;
$companyname = (isset($_POST['companyname'])) ? htmlentities($_POST['companyname']) : '' ;
$phone = (isset($_POST['phone'])) ? htmlentities($_POST['phone']) : '' ;
$email = (isset($_POST['email'])) ? htmlentities($_POST['email']) : '' ;
$web = (isset($_POST['web'])) ? htmlentities(str_replace('http://','',$_POST['web'])) : '' ;
$comment = (isset($_POST['comment'])) ? htmlentities($_POST['comment']) : '' ;
$actDate = date("Y-m-d H:i:s");
//Minimum name and comment length.
if ((strlen($name) > 2) && (strlen($comment) > 5)){
$sql = "INSERT INTO distributor (firstname,lastname,text,insertdate,phone,companyname,email,web) VALUES (";
$sql .= "'".$firstname."','".$lastname."','".$comment."','".$actDate."','".$phone."','".$companyname."','".$email."','".$web."')";
$MyDb->f_ExecuteSql($sql);
}
header("Location: index.php");
}
else {
?>
SafePath Products E-Mail Subscription Manager -- Subscribe<link rel="stylesheet" type="text/css" href="newsletter-css.css" media="screen" />
<link rel="stylesheet" type="text/css" href="login_panel/css/slide.css" media="screen" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<!-- PNG FIX for IE6 -->
<!-- http://24ways.org/2007/supersleight-transparent-png-in-ie6 -->
<!--[if lte IE 6]>
<script type="text/javascript" src="login_panel/js/pngfix/supersleight-min.js"></script>
<![endif]-->
<script src="login_panel/js/slide.js" type="text/javascript"></script>
Blahblahahblah
<div class="container">
<div id="formbody"> (firstname,lastname,insertdate,phone,companyname,email,web,text) VALUES (";
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="gbook" id="gbook">
<table align="center">
<tr><th>First Name:</th><td><input name="name" type="text" size="42" /></td></tr>
<tr><th>Last Name:</th><td><input name="lastname" type="text" size="42" /></td></tr>
<tr><th>Phone:</th><td><input name="phone" type="text" size="42" /></td></tr>
<tr><th>Company Name:</th><td><input name="companyname" type="text" size="42" /></td></tr>
<tr><th>Email:</th><td><input name="email" type="text" size="42" /></td></tr>
<tr><th>Web:</th><td><input name="web" type="text" size="42"/></td></tr>
<tr><th>Text:</th><td><textarea name="comment" cols=32 rows=6></textarea></td></tr>
<tr><td colspan="2" align="center"><br/><input class="text" type="submit" name="submitBtn" value="Submit" /></td></tr>
</table>
</form>
</div>
</div>
<?php } ?> [/php]
And then here is the SQL table:
CREATE TABLE `distributor` (
`id` int(11) NOT NULL auto_increment,
`firstname` varchar(100) default NULL,
`lastname` varchar(100) default NULL,
`insertdate` datetime default NULL,
`phone` varchar(10) default NULL,
`companyname` varchar(100) default NULL,
`email` varchar(100) default NULL,
`web` varchar(100) default NULL,
`text` text,
PRIMARY KEY (`id`)
);
Can anyone help me out with this?