...

View Full Version : Using fetch and insert statement help



PRodgers4284
02-17-2008, 04:51 PM
Im am trying to fetch a field from a table and populate the input form with the value. I have two tables called employers and jobs, and i need the username field in the form to be populated with the username from the employers table and then insert the value in the table jobs, i have the following code then inserts in the information in to the jobs table but it doesnt insert the username from the employers table, everything else insert fine, just not the username value.

Can anyone help me



$account = mysql_fetch_array(mysql_query("SELECT * FROM employers WHERE username='" . $_SESSION["username"] . "'"));


//Then, only run the query if there were no errors (if $error_stat still equals 0)
if ($error_stat == 0) {
mysql_query("INSERT INTO jobs (username, jobtitle, jobcatergory, joblocation, employmenttype, salary, date, educationallevel, description) VALUES ('$username', '$jobtitle', '$jobcatergory', '$joblocation', '$employmenttype', '$salary', '$date', '$educationallevel', '$description')");
echo "<h3>Registration Successful!</h3>";
echo "<p>Thankyou, <b>$username</b>,registration was successful</p>";
echo "<p>login.</p>";
echo "<a href=\"index2.php\">Login</a>";

}
}


//Then, for the form, only show it if 1) the form hasn't been submitted yet OR 2) there is an error
if (!isset($_POST['submit']) || $error_stat == 1) {



?>

<form method="post" class="addform" action="">
<fieldset>
<label for="cvtitle">Add a Job</label><fieldset>
<p align="right">&nbsp;</p>
</fieldset>
<label for="username">Username:</label>
<input readonly name="username" type="text" id="username"/><br />
</fieldset>

<hr class="hr_blue"/>

<fieldset>
<label for="jobtitle">Job Title:</label>
<input name="jobtitle" type="text" id="jobtitle" value="<?php echo $_POST['jobtitle']; ?>"/>
<span class="redboldtxt"><?php echo "$jobtitle_message";?></fieldset></span>


<fieldset>
<label for="jobcatergory">Job Catergory:</label><p></p>
<select name="jobcatergory">
<option value="Please Select">Please Select</option>
<?php
$jobcatergory_opts = array(
"Accountancy and Finance",
"Banking and Insurance",
"Construction",
"Customer Service",
"Engineering",
"Management",
"Hotel and Catering",
"Information Technology",
"Legal",
"Marketing",
"Medical",
"Retail",
"Sales",
"Secretarial",
"Transport and Distribution",
"Working from home",
);
foreach($jobcatergory_opts as $opt){
$selected = $_POST['jobcatergory'] == $opt ? " selected=true":"";
print "<option value=\"{$opt}\"{$selected}>{$opt}</option>";
}
?>
</select>
<span class="redboldtxt"><?php echo "$jobcatergory_message";?><?php echo $error['jobcatergory']; ?></span></fieldset>

<fieldset>
<label for="joblocation">Location:</label>
<p></p>
<select name="joblocation">
<option value="Please Select">Please Select</option>
<?php
$joblocation_opts = array(
"Co.Antrim",
"Co.Armagh",
"Co.Down",
"Co.Fermanagh",
"Co.Londonderry",
"Co.Tyrone",
);
foreach($joblocation_opts as $opt){
$selected = $_POST['joblocation'] == $opt ? " selected=true":"";
print "<option value=\"{$opt}\"{$selected}>{$opt}</option>";
}
?>
</select>
<span class="redboldtxt"><?php echo "$joblocation_message";?><?php echo $error['joblocation']; ?></span></fieldset>


<fieldset>
<label for="employmenttype">Job Type:</label><p></p>
<select name="employmenttype">
<option value="Please Select">Please Select</option>
<?php
$employmenttype_opts = array(
"permanent fulltime",
"permanent parttime",
"temporary fulltime",
"temporary parttime",
);
foreach($employmenttype_opts as $opt){
$selected = $_POST['employmenttype'] == $opt ? " selected=true":"";
print "<option value=\"{$opt}\"{$selected}>{$opt}</option>";
}
?>
</select>
<span class="redboldtxt"><?php echo "$employmenttype_message";?><?php echo $error['employmenttype']; ?></span></fieldset>


<fieldset>
<label for="salary">Salary:</label>
<input name="salary" type="text" id="salary" value="<?php echo $_POST['salary']; ?>"/>
<span class="redboldtxt"><?php echo "$salary_message";?></span></fieldset>

<fieldset>
<label for="date">Closing Date:</label>
<input name="date" type="text" id="date" value="<?php echo $_POST['date']; ?>"/>
<span class="redboldtxt"><?php echo "$date_message";?></span></fieldset>


<fieldset>
<label for="educationallevel">Qualification Level Required:</label><p></p>
<select name="educationallevel">
<option value="Please Select">Please Select</option>
<?php
$educationallevel_opts = array(
"GCSE",
"A-Level",
"Third Level Certification",
"Third Level Diploma",
"Third Level Degree",
"Post Graduate Qualification",
"Masters",
"PHD",
"Professional Qualification",
"Part Professional Qualification",
"Trade Qualification",
);
foreach($educationallevel_opts as $opt){
$selected = $_POST['educationallevel'] == $opt ? " selected=true":"";
print "<option value=\"{$opt}\"{$selected}>{$opt}</option>";
}
?>
</select>
<span class="redboldtxt"><?php echo "$educationallevel_message";?><?php echo $error['educationallevel']; ?></span></fieldset>

<hr class="hr_blue"/>

<fieldset>
Job Description -<br />
</fieldset>

<fieldset>
<textarea rows="2" name="description" cols="20"><?php echo $account["description"]; ?></textarea><p></p>
<span class="redboldtxt"><?php echo "$description_message";?></span></fieldset>

<p></p>
<fieldset>
<p class="submit"><input type="submit" name="submit" value="Add Job" />

</fieldset>
</form>

_Aerospace_Eng_
02-17-2008, 05:58 PM
Are you using session_start(); at the top of the page?

PRodgers4284
02-17-2008, 06:04 PM
Are you using session_start(); at the top of the page?


Thanks for the reply, yeah i have session_start(); at the top of the page.

_Aerospace_Eng_
02-17-2008, 10:10 PM
Hmm you still seem to have an extra curly bracket. Its the one I pointed out from before.

PRodgers4284
02-17-2008, 10:20 PM
Hmm you still seem to have an extra curly bracket. Its the one I pointed out from before.

I have removed the bracket but im getting an error "Parse error: syntax error, unexpected $end" it says the error is on the last line of the script.

Heres the full script, i cant find the error anywhere


<?php
session_start();
if(!isset($_SESSION['username'])){
header("Location: index2.php");
}
include("database.php");
include("loginemployer.php");
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Jobs4U</title>


<!--CSS Stylesheet -->
<link rel="stylesheet" type="text/css" href="./css/main.css" />
<link rel="stylesheet" type="text/css" href="./css/registerform.css" />
</head>

<body style="margin-left:1px;margin-right:1px;margin-bottom:0px;margin-top:0px;">

<!--Main Container -->
<div id="container">

<!--Main Header -->
<div id="header" style="width: 988px; height: 154px">
&nbsp;
</div>


<!-- Navigation Menu -->
<div id="nav_menu">
<div class="link_container" style="width: 852px; height: 32px">
<a href="Index.php" class="main_nav">home</a><span class="link_separator">::</span>
<a href="page.htm" class="main_nav">products</a><span class="link_separator">::</span>
<a href="page.htm" class="main_nav">services</a><span class="link_separator">::</span>
<a href="page.htm" class="main_nav">about us</a><span class="link_separator">::</span>
<a href="page.htm" class="main_nav">contact</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="text" name="search0" maxlength="30" size="30" >&nbsp;&nbsp;
<a href="page.htm" class="main_nav">Quick Search&gt;&gt;&gt;</a></div>
</div>

<!-- Container (left) -->
<div id="body">
<div id="body-left-panel" style="width: 654px; height: 981px">
<div style="padding:10px;">

<!-- Left container 1(Top) -->
<div class="box_upper_partviewdetails">
<img src="img/box_up-left_edge.png" alt="" class="align-left"/>
<img src="img/box_up-right_edge.png" alt="" class="align-right"/>
<span class="box_header">:: Add a Job</span></div>

<!--(Middle) -->
<div class="box_middle_partaddjob">
<div class="pad_15tah">

<!--Register Form -->


<?php
$error_stat = 0;
$jobtitle_message = '';
$jobcatergory_message = '';
$joblocation_message = '';
$employmenttype_message = '';
$salary_message = '';
$date_message = '';
$educationallevel_message = '';
$description_message = '';

if (isset($_POST['submit'])) {

$jobtitle = $_POST['jobtitle'];
$jobcatergory = $_POST['jobcatergory'];
$joblocation = $_POST['joblocation'];
$employmenttype= ($_POST['employmenttype']);
$salary = $_POST['salary'];
$date = $_POST['date'];
$educationallevel = $_POST['educationallevel'];
$description = $_POST['description'];



//Error checking



// Job Title check)
if (!$jobtitle) {
//Set the error_stat to 1, which means that an error has occurred
$error_stat = 1;

//Set the message to tell the user to enter a username
$jobtitle_message = '*Please enter a job title*';
}

else if (ctype_digit($jobtitle)) {
$error_stat = 1;
$jobtitle_message .= '*Invalid Job Title*';
}

else if ( preg_match( '/\W/', $jobtitle)){
$error_stat = 1;
$jobtitle_message = '*Invalid jobtitle, letters only, no spaces*';

}

$jobtitle = $_POST['jobtitle'];
$jobtitle = trim($jobtitle);

if (strlen($jobtitle) > 30){
$error_stat = 1;
$jobtitle_message = '*Job Title must be 20 characters or less*';
}






// Job Catergory Check)
if ($jobcatergory == 'Please Select'){
//Set the error_stat to 1, which means that an error has occurred
$error_stat = 1;
$jobcatergory_message = '*Please select a Job Catergory*';
}





// Job Location Check)
if ($joblocation == 'Please Select'){
//Set the error_stat to 1, which means that an error has occurred
$error_stat = 1;
$joblocation_message = '*Please select a Job location*';
}


// Employment Type Check)
if ($employmenttype == 'Please Select'){
//Set the error_stat to 1, which means that an error has occurred
$error_stat = 1;
$employmenttype_message = '*Please select Employment type*';
}





// Salary check)
if (!$salary) {
//Set the error_stat to 1, which means that an error has occurred
$error_stat = 1;

//Set the message to tell the user to enter a username
$salary_message = '*Please enter job salary*';
}

else if (!ctype_digit($salary)) {
$error_stat = 1;
$salary_message .= '*Invalid salary*';
}




//Date check)
if (empty($date)) {
//Set the error_stat to 1, which means that an error has occurred
$error_stat = 1;

//Set the message to tell the user to enter a dob
$date_message = '*Please enter job closing date*';
}

//Check the format and explode into $parts
elseif (!ereg("^([0-9]{2})/([0-9]{2})/([0-9]{4})$",
$date, $parts)){
$error_stat = 1;

//Set the message to tell the user the date is invalid
$date_message = '*Invalid date, must be DD/MM/YYYY format*';
}

elseif (!checkdate($parts[2],$parts[1],$parts[3]))
{
$error_stat = 1;

//Set the message to tell the date is invalid for the month entered
$dob_message = '*Invalid dob, month must be between 1-12*';
}

elseif (intval($parts[3]) < 2008 ||
intval($parts[3]) > intval(date("Y")))
{

$error_stat = 1;

//Set the message to tell the user the date is invalid for the year entered
$dob_message = '*Invalid dob, year must 2008 onwards*';
}


// Job Title check)
if (!$description) {
//Set the error_stat to 1, which means that an error has occurred
$error_stat = 1;

//Set the message to tell the user to enter a username
$description_message = '*Please enter a job description*';
}

$description = $_POST['description'];
$description = trim($description);

if (strlen($description) > 150){
$error_stat = 1;
$description_message = '*Job Title must be 150 characters or less*';
} $account = mysql_fetch_array(mysql_query("SELECT * FROM employers WHERE username='" . $_SESSION["username"] . "'"));



//Then, only run the query if there were no errors (if $error_stat still equals 0)
if ($error_stat == 0) {
mysql_query("INSERT INTO jobs (username, jobtitle, jobcatergory, joblocation, employmenttype, salary, date, educationallevel, description) VALUES ('$username', '$jobtitle', '$jobcatergory', '$joblocation', '$employmenttype', '$salary', '$date', '$educationallevel', '$description')");
echo "<h3>Registration Successful!</h3>";
echo "<p>Thankyou, <b>$username</b>,registration was successful</p>";
echo "<p>login.</p>";
echo "<a href=\"index2.php\">Login</a>";

}



//Then, for the form, only show it if 1) the form hasn't been submitted yet OR 2) there is an error
if (!isset($_POST['submit']) || $error_stat == 1) {



?>

<form method="post" class="addform" action="">
<fieldset>
<label for="cvtitle">Add a Job</label><fieldset>
<p align="right">&nbsp;</p>
</fieldset>
<label for="username">Username:</label>
<input readonly name="username" type="text" id="username" value="<?php echo $_POST['username']; ?>"/>
</fieldset>

<hr class="hr_blue"/>

<fieldset>
<label for="jobtitle">Job Title:</label>
<input name="jobtitle" type="text" id="jobtitle" value="<?php echo $_POST['jobtitle']; ?>"/>
<span class="redboldtxt"><?php echo "$jobtitle_message";?></fieldset></span>


<fieldset>
<label for="jobcatergory">Job Catergory:</label><p></p>
<select name="jobcatergory">
<option value="Please Select">Please Select</option>
<?php
$jobcatergory_opts = array(
"Accountancy and Finance",
"Banking and Insurance",
"Construction",
"Customer Service",
"Engineering",
"Management",
"Hotel and Catering",
"Information Technology",
"Legal",
"Marketing",
"Medical",
"Retail",
"Sales",
"Secretarial",
"Transport and Distribution",
"Working from home",
);
foreach($jobcatergory_opts as $opt){
$selected = $_POST['jobcatergory'] == $opt ? " selected=true":"";
print "<option value=\"{$opt}\"{$selected}>{$opt}</option>";
}
?>
</select>
<span class="redboldtxt"><?php echo "$jobcatergory_message";?><?php echo $error['jobcatergory']; ?></span></fieldset>

<fieldset>
<label for="joblocation">Location:</label>
<p></p>
<select name="joblocation">
<option value="Please Select">Please Select</option>
<?php
$joblocation_opts = array(
"Co.Antrim",
"Co.Armagh",
"Co.Down",
"Co.Fermanagh",
"Co.Londonderry",
"Co.Tyrone",
);
foreach($joblocation_opts as $opt){
$selected = $_POST['joblocation'] == $opt ? " selected=true":"";
print "<option value=\"{$opt}\"{$selected}>{$opt}</option>";
}
?>
</select>
<span class="redboldtxt"><?php echo "$joblocation_message";?><?php echo $error['joblocation']; ?></span></fieldset>


<fieldset>
<label for="employmenttype">Job Type:</label><p></p>
<select name="employmenttype">
<option value="Please Select">Please Select</option>
<?php
$employmenttype_opts = array(
"permanent fulltime",
"permanent parttime",
"temporary fulltime",
"temporary parttime",
);
foreach($employmenttype_opts as $opt){
$selected = $_POST['employmenttype'] == $opt ? " selected=true":"";
print "<option value=\"{$opt}\"{$selected}>{$opt}</option>";
}
?>
</select>
<span class="redboldtxt"><?php echo "$employmenttype_message";?><?php echo $error['employmenttype']; ?></span></fieldset>


<fieldset>
<label for="salary">Salary:</label>
<input name="salary" type="text" id="salary" value="<?php echo $_POST['salary']; ?>"/>
<span class="redboldtxt"><?php echo "$salary_message";?></span></fieldset>

<fieldset>
<label for="date">Closing Date:</label>
<input name="date" type="text" id="date" value="<?php echo $_POST['date']; ?>"/>
<span class="redboldtxt"><?php echo "$date_message";?></span></fieldset>


<fieldset>
<label for="educationallevel">Qualification Level Required:</label><p></p>
<select name="educationallevel">
<option value="Please Select">Please Select</option>
<?php
$educationallevel_opts = array(
"GCSE",
"A-Level",
"Third Level Certification",
"Third Level Diploma",
"Third Level Degree",
"Post Graduate Qualification",
"Masters",
"PHD",
"Professional Qualification",
"Part Professional Qualification",
"Trade Qualification",
);
foreach($educationallevel_opts as $opt){
$selected = $_POST['educationallevel'] == $opt ? " selected=true":"";
print "<option value=\"{$opt}\"{$selected}>{$opt}</option>";
}
?>
</select>
<span class="redboldtxt"><?php echo "$educationallevel_message";?><?php echo $error['educationallevel']; ?></span></fieldset>

<hr class="hr_blue"/>

<fieldset>
Job Description -<br />
</fieldset>

<fieldset>
<textarea rows="2" name="description" cols="20"><?php echo $account["description"]; ?></textarea><p></p>
<span class="redboldtxt"><?php echo "$description_message";?></span></fieldset>

<p></p>
<fieldset>
<p class="submit"><input type="submit" name="submit" value="Add Job" />

</fieldset>
</form>
<?php
}
?>
</div>
</div>



<!-- (bottom) -->
<div class="box_lower_part">
<img src="img/box_low-left_edge.png" alt="" class="align-left"/>
<img src="img/box_low-right_edge.png" alt="" class="align-right"/>
</div>

<!--Left Container 2 (Top) -->
</div>
</div>
<p>

<!--Right Panel 1 -->
</p>
<div id="body-right-panel" style="width: 333px; height: 981px">
<div style="padding:10px;">


<!--Top -->
<div class="box_upper_part">
<img src="img/box_up-left_edge_dark.png" alt="" class="align-left"/>
<img src="img/box_up-right_edge_dark.png" alt="" class="align-right"/>
<span class="box_header">Employer Login</span></div>


<!--Middle -->
<div class="box_middle_part">
<div style="padding:5px;">
<ul class="img_red">


<!--Login -->
<?php displayLoginemployer(); ?>
<p><br /></p>
</div>
</div>


<!-- (bottom) -->
<div class="box_lower_part">
<img src="img/box_low-left_edge_dark.png" alt="" class="align-left"/>
<img src="img/box_low-right_edge_dark.png" alt="" class="align-right"/>
</div>


<!--Right Panel 2 (top) -->
<div class="box_upper_part" style="width: 313px; height: 29px">
<img src="img/box_up-left_edge_dark_nodot.png" alt="" class="align-left"/>
<img src="img/box_up-right_edge_dark.png" alt="" class="align-right"/>
<span class="box_header">:: Resource Centre</span>
</div>


<!--Middle -->
<div class="box_middle_part">
<div style="padding:10px;">
<div align="center">
<table border="0" width="65&#37;" id="table12" cellspacing="0" cellpadding="0" bgcolor="#E7E6E4">
<tr>
<td>
<img border="0" src="images/cv.gif" width="221" height="23"></td>
</tr>
<tr>
<td><p>&nbsp;</p>
<p><span class="navyboldtxt">CV Advice</span>. </p>
<p>&nbsp;- <a href="cvadvice.php">How to create a CV</a> </p>
<p>&nbsp;- <a href="cvreferences.php">CV References</a> </p>
<p>&nbsp;</p>
</td>
</tr>
</table>
<table border="0" width="65%" id="table13" cellspacing="0" cellpadding="0" bgcolor="#E7E6E4">
<tr>
<td>
<img border="0" src="images/interview.gif" width="221" height="23">
</td>
</tr>
<tr>
<td>&nbsp;<p><span class="navyboldtxt">
Interview Advice</span> - </p>
<p>&nbsp;&nbsp;- <a href="interviewadvice.php">Interview tips</a> </p>
<p>&nbsp;</p><p>&nbsp;</td>
</tr>
</table>
</div>
</div>
</div>


<!-- (bottom) -->
<div class="box_lower_part" style="width: 313px; height: 22px">
<img src="img/box_low-left_edge_dark.png" alt="" class="align-left"/>
<img src="img/box_low-right_edge_dark.png" alt="" class="align-right"/>
</div>
</div>
</div>
</div>


<!-- Footer -->
<div id="footer">
<div id="footer_designby" style="width: 987px; height: 30px">
<div class="designedby">Designed by
<a href="">Philip Rodgers</a></div>
</div>
</div>
</div>

</body>
</html>

bazz
02-18-2008, 12:04 AM
well if you look at your post where the text becomes black - about 1/2 way down the window - you may see that you have used a closing tag for php instead of an opening tag? is this the cause?

bazz

PRodgers4284
02-18-2008, 10:19 AM
well if you look at your post where the text becomes black - about 1/2 way down the window - you may see that you have used a closing tag for php instead of an opening tag? is this the cause?

bazz

Bazz where u referring to this piece of code


// Educational Level Check)
if ($educationallevel == 'Please Select'){
//Set the error_stat to 1, which means that an error has occurred
$error_stat = 1;
$educationallevel_message = '*Please select Educational level required*';
}


That should not of been in the code, my mistake, it still gives out the parse error.

my code:


<?php
session_start();
if(!isset($_SESSION['username'])){
header("Location: index2.php");
}
include("database.php");
include("loginemployer.php");
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Jobs4U</title>


<!--CSS Stylesheet -->
<link rel="stylesheet" type="text/css" href="./css/main.css" />
<link rel="stylesheet" type="text/css" href="./css/registerform.css" />
</head>

<body style="margin-left:1px;margin-right:1px;margin-bottom:0px;margin-top:0px;">

<!--Main Container -->
<div id="container">

<!--Main Header -->
<div id="header" style="width: 988px; height: 154px">
&nbsp;
</div>


<!-- Navigation Menu -->
<div id="nav_menu">
<div class="link_container" style="width: 852px; height: 32px">
<a href="Index.php" class="main_nav">home</a><span class="link_separator">::</span>
<a href="page.htm" class="main_nav">products</a><span class="link_separator">::</span>
<a href="page.htm" class="main_nav">services</a><span class="link_separator">::</span>
<a href="page.htm" class="main_nav">about us</a><span class="link_separator">::</span>
<a href="page.htm" class="main_nav">contact</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="text" name="search0" maxlength="30" size="30" >&nbsp;&nbsp;
<a href="page.htm" class="main_nav">Quick Search&gt;&gt;&gt;</a></div>
</div>

<!-- Container (left) -->
<div id="body">
<div id="body-left-panel" style="width: 654px; height: 981px">
<div style="padding:10px;">

<!-- Left container 1(Top) -->
<div class="box_upper_partviewdetails">
<img src="img/box_up-left_edge.png" alt="" class="align-left"/>
<img src="img/box_up-right_edge.png" alt="" class="align-right"/>
<span class="box_header">:: Add a Job</span></div>

<!--(Middle) -->
<div class="box_middle_partaddjob">
<div class="pad_15tah">

<!--Register Form -->


<?php
$error_stat = 0;
$jobtitle_message = '';
$jobcatergory_message = '';
$joblocation_message = '';
$employmenttype_message = '';
$salary_message = '';
$date_message = '';
$educationallevel_message = '';
$description_message = '';

if (isset($_POST['submit'])) {

$jobtitle = $_POST['jobtitle'];
$jobcatergory = $_POST['jobcatergory'];
$joblocation = $_POST['joblocation'];
$employmenttype= ($_POST['employmenttype']);
$salary = $_POST['salary'];
$date = $_POST['date'];
$educationallevel = $_POST['educationallevel'];
$description = $_POST['description'];



//Error checking



// Job Title check)
if (!$jobtitle) {
//Set the error_stat to 1, which means that an error has occurred
$error_stat = 1;

//Set the message to tell the user to enter a username
$jobtitle_message = '*Please enter a job title*';
}

else if (ctype_digit($jobtitle)) {
$error_stat = 1;
$jobtitle_message .= '*Invalid Job Title*';
}

else if ( preg_match( '/\W/', $jobtitle)){
$error_stat = 1;
$jobtitle_message = '*Invalid jobtitle, letters only, no spaces*';

}

$jobtitle = $_POST['jobtitle'];
$jobtitle = trim($jobtitle);

if (strlen($jobtitle) > 30){
$error_stat = 1;
$jobtitle_message = '*Job Title must be 20 characters or less*';
}






// Job Catergory Check)
if ($jobcatergory == 'Please Select'){
//Set the error_stat to 1, which means that an error has occurred
$error_stat = 1;
$jobcatergory_message = '*Please select a Job Catergory*';
}





// Job Location Check)
if ($joblocation == 'Please Select'){
//Set the error_stat to 1, which means that an error has occurred
$error_stat = 1;
$joblocation_message = '*Please select a Job location*';
}


// Employment Type Check)
if ($employmenttype == 'Please Select'){
//Set the error_stat to 1, which means that an error has occurred
$error_stat = 1;
$employmenttype_message = '*Please select Employment type*';
}





// Salary check)
if (!$salary) {
//Set the error_stat to 1, which means that an error has occurred
$error_stat = 1;

//Set the message to tell the user to enter a username
$salary_message = '*Please enter job salary*';
}

else if (!ctype_digit($salary)) {
$error_stat = 1;
$salary_message .= '*Invalid salary*';
}




//Date check)
if (empty($date)) {
//Set the error_stat to 1, which means that an error has occurred
$error_stat = 1;

//Set the message to tell the user to enter a dob
$date_message = '*Please enter job closing date*';
}

//Check the format and explode into $parts
elseif (!ereg("^([0-9]{2})/([0-9]{2})/([0-9]{4})$",
$date, $parts)){
$error_stat = 1;

//Set the message to tell the user the date is invalid
$date_message = '*Invalid date, must be DD/MM/YYYY format*';
}

elseif (!checkdate($parts[2],$parts[1],$parts[3]))
{
$error_stat = 1;

//Set the message to tell the date is invalid for the month entered
$dob_message = '*Invalid dob, month must be between 1-12*';
}

elseif (intval($parts[3]) < 2008 ||
intval($parts[3]) > intval(date("Y")))
{

$error_stat = 1;

//Set the message to tell the user the date is invalid for the year entered
$dob_message = '*Invalid dob, year must 2008 onwards*';
}


// Job Title check)
if (!$description) {
//Set the error_stat to 1, which means that an error has occurred
$error_stat = 1;

//Set the message to tell the user to enter a username
$description_message = '*Please enter a job description*';
}

$description = $_POST['description'];
$description = trim($description);

if (strlen($description) > 150){
$error_stat = 1;
$description_message = '*Job Title must be 150 characters or less*';
}




// Educational Level Check)
if ($educationallevel == 'Please Select'){
//Set the error_stat to 1, which means that an error has occurred
$error_stat = 1;
$educationallevel_message = '*Please select Educational level required*';
}



$account = mysql_fetch_array(mysql_query("SELECT * FROM employers WHERE username='" . $_SESSION["username"] . "'"));



//Then, only run the query if there were no errors (if $error_stat still equals 0)
if ($error_stat == 0) {
mysql_query("INSERT INTO jobs (username, jobtitle, jobcatergory, joblocation, employmenttype, salary, date, educationallevel, description) VALUES ('$username', '$jobtitle', '$jobcatergory', '$joblocation', '$employmenttype', '$salary', '$date', '$educationallevel', '$description')");
echo "<h3>Registration Successful!</h3>";
echo "<p>Thankyou, <b>$username</b>,registration was successful</p>";
echo "<p>login.</p>";
echo "<a href=\"index2.php\">Login</a>";

}



//Then, for the form, only show it if 1) the form hasn't been submitted yet OR 2) there is an error
if (!isset($_POST['submit']) || $error_stat == 1) {



?>

<form method="post" class="addform" action="">
<fieldset>
<label for="cvtitle">Add a Job</label><fieldset>
<p align="right">&nbsp;</p>
</fieldset>
<label for="username">Username:</label>
<input readonly name="username" type="text" id="username" value="<?php echo $_POST['username']; ?>"/>
</fieldset>

<hr class="hr_blue"/>

<fieldset>
<label for="jobtitle">Job Title:</label>
<input name="jobtitle" type="text" id="jobtitle" value="<?php echo $_POST['jobtitle']; ?>"/>
<span class="redboldtxt"><?php echo "$jobtitle_message";?></fieldset></span>


<fieldset>
<label for="jobcatergory">Job Catergory:</label><p></p>
<select name="jobcatergory">
<option value="Please Select">Please Select</option>
<?php
$jobcatergory_opts = array(
"Accountancy and Finance",
"Banking and Insurance",
"Construction",
"Customer Service",
"Engineering",
"Management",
"Hotel and Catering",
"Information Technology",
"Legal",
"Marketing",
"Medical",
"Retail",
"Sales",
"Secretarial",
"Transport and Distribution",
"Working from home",
);
foreach($jobcatergory_opts as $opt){
$selected = $_POST['jobcatergory'] == $opt ? " selected=true":"";
print "<option value=\"{$opt}\"{$selected}>{$opt}</option>";
}
?>
</select>
<span class="redboldtxt"><?php echo "$jobcatergory_message";?><?php echo $error['jobcatergory']; ?></span></fieldset>

<fieldset>
<label for="joblocation">Location:</label>
<p></p>
<select name="joblocation">
<option value="Please Select">Please Select</option>
<?php
$joblocation_opts = array(
"Co.Antrim",
"Co.Armagh",
"Co.Down",
"Co.Fermanagh",
"Co.Londonderry",
"Co.Tyrone",
);
foreach($joblocation_opts as $opt){
$selected = $_POST['joblocation'] == $opt ? " selected=true":"";
print "<option value=\"{$opt}\"{$selected}>{$opt}</option>";
}
?>
</select>
<span class="redboldtxt"><?php echo "$joblocation_message";?><?php echo $error['joblocation']; ?></span></fieldset>


<fieldset>
<label for="employmenttype">Job Type:</label><p></p>
<select name="employmenttype">
<option value="Please Select">Please Select</option>
<?php
$employmenttype_opts = array(
"permanent fulltime",
"permanent parttime",
"temporary fulltime",
"temporary parttime",
);
foreach($employmenttype_opts as $opt){
$selected = $_POST['employmenttype'] == $opt ? " selected=true":"";
print "<option value=\"{$opt}\"{$selected}>{$opt}</option>";
}
?>
</select>
<span class="redboldtxt"><?php echo "$employmenttype_message";?><?php echo $error['employmenttype']; ?></span></fieldset>


<fieldset>
<label for="salary">Salary:</label>
<input name="salary" type="text" id="salary" value="<?php echo $_POST['salary']; ?>"/>
<span class="redboldtxt"><?php echo "$salary_message";?></span></fieldset>

<fieldset>
<label for="date">Closing Date:</label>
<input name="date" type="text" id="date" value="<?php echo $_POST['date']; ?>"/>
<span class="redboldtxt"><?php echo "$date_message";?></span></fieldset>


<fieldset>
<label for="educationallevel">Qualification Level Required:</label><p></p>
<select name="educationallevel">
<option value="Please Select">Please Select</option>
<?php
$educationallevel_opts = array(
"GCSE",
"A-Level",
"Third Level Certification",
"Third Level Diploma",
"Third Level Degree",
"Post Graduate Qualification",
"Masters",
"PHD",
"Professional Qualification",
"Part Professional Qualification",
"Trade Qualification",
);
foreach($educationallevel_opts as $opt){
$selected = $_POST['educationallevel'] == $opt ? " selected=true":"";
print "<option value=\"{$opt}\"{$selected}>{$opt}</option>";
}
?>
</select>
<span class="redboldtxt"><?php echo "$educationallevel_message";?><?php echo $error['educationallevel']; ?></span></fieldset>

<hr class="hr_blue"/>

<fieldset>
Job Description -<br />
</fieldset>

<fieldset>
<textarea rows="2" name="description" cols="20"><?php echo $account["description"]; ?></textarea><p></p>
<span class="redboldtxt"><?php echo "$description_message";?></span></fieldset>

<p></p>
<fieldset>
<p class="submit"><input type="submit" name="submit" value="Add Job" />

</fieldset>
</form>
<?php
}
?>
</div>
</div>



<!-- (bottom) -->
<div class="box_lower_part">
<img src="img/box_low-left_edge.png" alt="" class="align-left"/>
<img src="img/box_low-right_edge.png" alt="" class="align-right"/>
</div>

<!--Left Container 2 (Top) -->
</div>
</div>
<p>

<!--Right Panel 1 -->
</p>
<div id="body-right-panel" style="width: 333px; height: 981px">
<div style="padding:10px;">


<!--Top -->
<div class="box_upper_part">
<img src="img/box_up-left_edge_dark.png" alt="" class="align-left"/>
<img src="img/box_up-right_edge_dark.png" alt="" class="align-right"/>
<span class="box_header">Employer Login</span></div>


<!--Middle -->
<div class="box_middle_part">
<div style="padding:5px;">
<ul class="img_red">


<!--Login -->
<?php displayLoginemployer(); ?>
<p><br /></p>
</div>
</div>


<!-- (bottom) -->
<div class="box_lower_part">
<img src="img/box_low-left_edge_dark.png" alt="" class="align-left"/>
<img src="img/box_low-right_edge_dark.png" alt="" class="align-right"/>
</div>


<!--Right Panel 2 (top) -->
<div class="box_upper_part" style="width: 313px; height: 29px">
<img src="img/box_up-left_edge_dark_nodot.png" alt="" class="align-left"/>
<img src="img/box_up-right_edge_dark.png" alt="" class="align-right"/>
<span class="box_header">:: Resource Centre</span>
</div>


<!--Middle -->
<div class="box_middle_part">
<div style="padding:10px;">
<div align="center">
<table border="0" width="65%" id="table12" cellspacing="0" cellpadding="0" bgcolor="#E7E6E4">
<tr>
<td>
<img border="0" src="images/cv.gif" width="221" height="23"></td>
</tr>
<tr>
<td><p>&nbsp;</p>
<p><span class="navyboldtxt">CV Advice</span>. </p>
<p>&nbsp;- <a href="cvadvice.php">How to create a CV</a> </p>
<p>&nbsp;- <a href="cvreferences.php">CV References</a> </p>
<p>&nbsp;</p>
</td>
</tr>
</table>
<table border="0" width="65%" id="table13" cellspacing="0" cellpadding="0" bgcolor="#E7E6E4">
<tr>
<td>
<img border="0" src="images/interview.gif" width="221" height="23">
</td>
</tr>
<tr>
<td>&nbsp;<p><span class="navyboldtxt">
Interview Advice</span> - </p>
<p>&nbsp;&nbsp;- <a href="interviewadvice.php">Interview tips</a> </p>
<p>&nbsp;</p><p>&nbsp;</td>
</tr>
</table>
</div>
</div>
</div>


<!-- (bottom) -->
<div class="box_lower_part" style="width: 313px; height: 22px">
<img src="img/box_low-left_edge_dark.png" alt="" class="align-left"/>
<img src="img/box_low-right_edge_dark.png" alt="" class="align-right"/>
</div>
</div>
</div>
</div>


<!-- Footer -->
<div id="footer">
<div id="footer_designby" style="width: 987px; height: 30px">
<div class="designedby">Designed by
<a href="">Philip Rodgers</a></div>
</div>
</div>
</div>

</body>
</html>

PRodgers4284
02-18-2008, 12:14 PM
got this sorted guys, thanks for the help :)

_Aerospace_Eng_
02-18-2008, 03:39 PM
What was the problem?

PRodgers4284
02-18-2008, 04:43 PM
What was the problem?

Aerospace i just needed to include the line in between the fetch array and the insert statement and it works fine.


$username = $account["username"];


Thanks again for your help, appreciate it :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum