PDA

View Full Version : building job posting and email to employer - not going into database


nanny
05-31-2009, 05:23 AM
Hi I am wondering if I am totally on the wrong path with this:
I am testing locally but am wanting to have users post jobs - have them show - jobseeker can view listing and email their details.
I have everything working really well. I have a table in mysql for listing and one for apply:

CREATE TABLE `apply` (
`applyID` int(11) NOT NULL auto_increment,
`listingID` int(11) default NULL,
`name` varchar(80) default NULL,
`skills` text,
`other` varchar(120) default NULL,
`applytel` varchar(20) default NULL,
`applytel2` varchar(20) default NULL,
`contactemail` varchar(50) default NULL,
`contactemail2` varchar(50) default NULL,
`ip` varchar(15) default NULL,
`applydate` date default NULL,
PRIMARY KEY (`applyID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

CREATE TABLE `listing` (
`listingID` int(11) NOT NULL auto_increment,
`inv_name` varchar(50) default NULL,
`inv_company` varchar(40) default NULL,
`inv_addr1` varchar(50) default NULL,
`inv_addr2` varchar(50) default NULL,
`inv_state` varchar(180) default NULL,
`inv_zip` varchar(15) default NULL,
`inv_country` varchar(15) default NULL,
`classcatid` varchar(80) default NULL,
`industryid` varchar(80) default NULL,
`classDescription` varchar(500) default NULL,
`tel` varchar(20) default NULL,
`contactphone2` varchar(20) default NULL,
`contactfax` varchar(20) default NULL,
`email` varchar(50) default NULL,
`email2` varchar(50) default NULL,
`contactwebsite` varchar(80) default NULL,
`adscreation_date` date default NULL,
`expires` date default NULL,
`ip` varchar(15) default NULL,
`status` enum('active','notactive') default 'notactive',
`title` varchar(80) default NULL,
`contact_how` varchar(15) default NULL,
PRIMARY KEY (`listingID`),
FULLTEXT KEY `inv_company` (`inv_company`,`inv_addr1`,`inv_state`,`inv_countr y`,`classcatid`,`industryid`,`classDescription`,`t itle`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=26 ;

nanny
05-31-2009, 05:26 AM
So the listingID is a foreign field in the apply table.
My email for the apply and going into the database is:

<?php
session_start();
$_SESSION['applyID'] = $_POST['applyID'];
?>
<?php
if (array_key_exists('send', $_POST)) {
//mail processing script
$id = $_GET['listingID'];
$tel2 = $_POST['applytel2'];
$other = $_POST['other'];
$applydate = date("Y-m-d"); ;
$to = $row_contactbus['email']; // use your own email address
$subject = 'Job Application From In Salon Spa';
$name = trim($_POST['name']);
if (empty($name)) {
$missing['name'] = 'Please give your name';
}
$email = $_POST['contactemail'];
$_POST['contactemail'] = trim($_POST['contactemail']);
if (empty($_POST['contactemail'])) {
$missing['contactemail'] = 'Please enter your email address';
}
else {
$pattern = '^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$';
if (!eregi($pattern, trim($_POST['contactemail']))) {
$missing['contactemail'] = 'Please enter a valid email address';
}
}
$tel = trim($_POST['applytel']);
if (empty($tel)) {
$missing['applytel'] = 'Please give your telephone number';
}
$messageBody = trim($_POST['skills']);
if (empty($messageBody)) {
$missing['skills'] = 'Please enter your skills';
}
else {
if (!empty($messageBody)) {
$type = '/(%0A|%0D|\n+|\r+)(content-type:|to:|cc:|bcc:|MIME-Version:|Content-Transfer-Encoding:)/i';
if (preg_match($type, trim($_POST['skills']))) {
$missing['skills'] = 'Sorry you can not place that for a message';
}
}
}
if (!isset($missing)) {


$message = "Name: $name\n\n";
$message .= "Email: $email\n\n";
$message .= "Telephone: $tel\n\n";
$message .= "Skills: $messageBody\n\n";


$message = wordwrap($message, 70);
$additionalHeaders = 'From: In Salon Spa Contact Form<info@insalonspa.com>';
if (!empty($email)) {
$additionalHeaders .= "\r\nReply-To: $email";
}
$mailSent = mail($to, $subject, $message, $headers);
if ($mailSent) {
$insert = "INSERT INTO apply (name, applytel, applytel2, contactemail, skills, other, applydate, listingID) VALUES ('$namel', '$tel', '$tel2', '$email', '$messageBody', '$applydate', '$id')";
mysql_query($insert);
$_SESSION['applyID'] = mysql_insert_id();
header ("Location: thank_you.php");

}
unset($missing);
}
}
?>
The reason I have a session is a conditional thank you. Should I try and insert before mail send?

Thanks...

davidj
05-31-2009, 08:34 AM
i would have the email last.

i would also check that the insert actually happened before you send the mail. This is where your exception handling come into play.

Nanny

You are coding competently to an advanced level.

You really should be moving on to an OOP level

nanny
06-08-2009, 03:36 AM
Hi Davidj
I removed the email sending bit of code and have tried to get the details to go into the database but it won't and I am not getting the session to work either. Do you have any ideas?
Thanks haven't looked at OOP.

nanny
06-12-2009, 06:07 AM
Hi I changed the mail to last and realised I had the wrong name for the input button. That is why the session wouldn't work. Now it is great!