Jump to content

Using fetch and insert statement help


PRodgers4284

Recommended Posts

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"> </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> 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.