By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,723 Members | 1,891 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,723 IT Pros & Developers. It's quick & easy.

job post code cannot post into database

100+
P: 127
Below is my job post code, it cannot post into database... WHAT IS THE PROBLEM OF IT??



[PHP]<?php
session_start();
ob_start();

//connect to server and select database

$conn=mysql_connect("localhost", "root", "") or die (mysql_error());
mysql_select_db("ums e-job portal", $conn) or die(mysql_error());

//If the form was submitted, process it.
if (isset($_POST['submit'])){

$problem=FALSE;

//check for empty value in each mandatory field.
if (empty($_POST['jobTitle'])||empty($_POST['jobType'])||empty($_POST['jobCategory'])||empty($_POST['jobPosition'])||empty($_POST['jobLocation'])||empty($_POST['mRequirement'])||empty($_POST['jobDescription'])){
$problem=TRUE;
echo '<p>Please make sure you enter all the required fields!</p>';
}

//if no problem then insert values into the abstract table in the database.
if (!$problem){

$query = "INSERT INTO job values ( '', '$_SESSION[company_ID]', '$_SESSION[companyName]', '$_SESSION[contactName]' , '$_SESSION[emailAdd]', '$_SESSION[contactNum]', '$_SESSION[contactAdd]', '$_POST[jobTitle]', '$_POST[jobType]', '$_POST[jobCategory]', '$_POST[jobPosition]', '$_POST[jobLocation]', '$_POST[mRequirement]', '$_POST[jobDescription]', now() )";


if(mysql_query($query)){
echo 'The job has been posted.<br>';
exit ();

}else{
echo 'The job could not be submitted. Because:'.mysql_error();
}
}#end of insert values if.


}#end of submit if...



// construct SQL statement
$sql =mysql_query("SELECT * FROM company WHERE company_ID='{$_SESSION['company_ID']}'");
$rows=@mysql_fetch_array($sql)
?>[/PHP]

[HTML]<form name="act" method="post" action="jobPost.php">
<table width="600" border="0">
<tr>
<td colspan="3"><font color="#000000"><strong>COMPANY CONTACT INFORMATION</strong></font></td>
</tr>
<tr>
<td width="217"><font color="#000000">Company Name</font><font color="#000000">&nbsp;</font></td>
<td width="30"><div align="center"><strong>:</strong></div></td>
<td width="339"><input name="companyName" type="text" maxlength="30" value="<? echo $rows['companyName'];?>"></td>
</tr>
<tr>
<td width="217"><font color="#000000">Contact Name</font><font color="#000000">&nbsp;</font></td>
<td width="30"><div align="center"><strong>:</strong></div></td>
<td width="339"><input name="contactName" type="text" maxlength="30" value="<? echo $rows['contactName'];?>"></td>
</tr>
<tr>
<td><font color="#000000">Email Address</font></td>
<td><div align="center"><strong>:</strong></div></td>
<td><input name="emailAdd" type="text" maxlength="50" value="<? echo $rows['emailAdd'];?>"></td>
</tr>
<tr>
<td><font color="#000000">Contact Number</font></td>
<td><div align="center"><strong>:</strong></div></td>
<td><input name="contactNum" type="text" maxlength="11" value="<? echo $rows['contactNum'];?>"></td>
</tr>
<tr>
<td><font color="#000000">Contact Address</font></td>
<td><div align="center"><strong>:</strong></div></td>
<td><textarea name="contactAdd" cols="30" rows="3"><? echo $rows['contactAdd'];?></textarea> </textarea>
</td>
</tr>
<tr>
<td colspan="3"><div align="center"></div></td>
</tr>
<td colspan="3"><font color="#000000"><strong>JOB INFORMATION</strong></font></td>
<tr>
<td width="217"><font color="#000000">Job Title</font><font color="#000000">&nbsp;</font></td>
<td width="30"><div align="center"><strong>:</strong></div></td>
<td width="339"><input name="jobTitle" type="text" maxlength="30"></td>
</tr>
<tr>
<td><font color="#000000">Job Type</font></td>
<td><div align="center"><strong>:</strong></div></td>
<td><select name="jobType">
<option selected></option>
<option>Permanent/Full Time</option>
<option>Temporary/Part Time</option>
<option>Internships</option>
</select></td>
</tr>
<tr>
<td><font color="#000000">Job Category</font> </td>
<td><div align="center"><strong>:</strong></div></td>
<td><select name="jobCategory">
<option selected></option>
<option>Accounting</option>
<option>Advertising</option>
<option>Agriculture</option>
<option>Banking</option>
<option>Biotechnology</option>
<option>Chemical Eng</option>
<option>Chemistry</option>
<option>Clerical/Admin</option>
<option>Customer Service</option>
<option>Education</option>
<option>Electronics Eng</option>
<option>Food Tech</option>
<option>General Workers</option>
<option>Graphics</option>
<option>Healthcare</option>
<option>Hotel/Food</option>
<option>Human Resources</option>
<option>IT/Computer</option>
<option>Journalist/Editor</option>
<option>Manufacturing</option>
<option>Marketing</option>
<option>Mechanical Eng</option>
<option>Media/Entertain</option>
<option>Personal Care</option>
<option>Publishing</option>
<option>Purchasing</option>
<option>Quantity Survey</option>
<option>Sales</option>
<option>Science/Tech</option>
<option>Secretarial</option>
<option>Social Services</option>
<option>Training</option>
<option>Others</option>
</select></td>
</tr>
<tr>
<td><font color="#000000">Job Position Level</font></td>
<td><div align="center"><strong>:</strong></div></td>
<td><select name="jobPosition">
<option selected></option>
<option>Senior Manager</option>
<option>Manager</option>
<option>Senior Executive</option>
<option>Junior Executive</option>
<option>Non-Executive</option>
<option>Fresh/Entry Level</option>
<option>Others</option>
</select></td>
</tr>
<tr>
<td><font color="#000000">Job Location</font></td>
<td><div align="center"><strong>:</strong></div></td>
<td><select name="jobLocation">
<option selected></option>
<option>Perlis</option>
<option>Penang</option>
<option>Kedah</option>
<option>Perak</option>
<option>Kelantan</option>
<option>Terengganu</option>
<option>Pahang</option>
<option>Selangor</option>
<option>Kuala Lumpur</option>
<option>Negeri Sembilan</option>
<option>Melaka</option>
<option>Johor</option>
<option>Labuan</option>
<option>Sabah</option>
<option>Sarawak</option>
</select></td>
</tr>
<tr>
<td colspan="3"><font color="#000000">Minimal Requirement</font></td>
</tr>
<tr>
<td height="75" colspan="3"> <textarea name="mRequirement" cols="66" rows="4"></textarea></td>
</tr>
<tr>
<td colspan="3"><div align="center"></div></td>
</tr>
<tr>
<td colspan="3">Job Description</td>
</tr>
<tr>
<td colspan="3"><font color="#000000">
<textarea name="jobDescription" cols="66" rows="4"></textarea>
</font></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input name="Post Job" type="submit" id="Post Job" value="Post Job">
</div></td>
<td><div align="center">
<input type="reset" name="Reset" value="Reset">
</div></td>
</tr>
</table>
<p>&nbsp;</p>
</form>[/HTML]
Feb 19 '07 #1
Share this Question
Share on Google+
3 Replies


P: 99
Below is my job post code, it cannot post into database... WHAT IS THE PROBLEM OF IT??



[PHP]<?php

mysql_select_db("ums e-job portal", $conn) or die(mysql_error());

?>[/PHP]
Are those 3 databases or is that the name of one database?

It's not good practice to have spaces in a databasename or in fieldnames for that matter.
Feb 19 '07 #2

100+
P: 127
Are those 3 databases or is that the name of one database?

It's not good practice to have spaces in a databasename or in fieldnames for that matter.


Is a name for 1 database...
i know, but i think the problem is not in there coz i have done others function which can work with this database name.. Thanks..
Feb 19 '07 #3

P: 99
What is the error you see if you post or is there no error at all?

[PHP]$query = "INSERT INTO job values ( '', '$_SESSION[company_ID]', '$_SESSION[companyName]', '$_SESSION[contactName]' , '$_SESSION[emailAdd]', '$_SESSION[contactNum]', '$_SESSION[contactAdd]', '$_POST[jobTitle]', '$_POST[jobType]', '$_POST[jobCategory]', '$_POST[jobPosition]', '$_POST[jobLocation]', '$_POST[mRequirement]', '$_POST[jobDescription]', now() )";[/PHP]

are you sure that are all the fields in the table?

The following snippet is more secure and easier to maintain

[PHP]
$jobtitle = $_POST[jobTitle];
$jobtype = $_POST[jobType];
$jobcategory = $_POST[jobCategory];
$jobposition = $_POST[jobPosition];
$joblocation] = $_POST[jobLocation];
$mRequirement = $_POST[mRequirement];
$jobDescription = $_POST[jobDescription];
// add post variable checks
$query = 'INSERT INTO job (field,names) VALUES (post,variables,and other)';
[/PHP]

If you do it like this the fieldnames and values must be equal in amount and you don't have to know how many other fields there are or where they are
Feb 19 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.