Populating drop down list with mysql data and add to db

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
duhasteme
Forum Commoner
Posts: 25
Joined: Fri Jun 29, 2007 4:24 am
Contact:

Populating drop down list with mysql data and add to db

Post by duhasteme »

Hello, I am trying to populate some drop down lists with mysql data and add them to the database through a form.

I have managed to populate the drop down list using the following code.

Code: Select all

<strong>Function:</strong><br />
 
<?php
 
$query="SELECT name FROM job_function";
$result = mysql_query ($query);
echo "<select name='in_function'>name</option>";
while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
echo "<option value=$nt[id]>$nt[name]</option>";
/* Option values are added by looping through the array */
}
echo "</select>";// Closing of list box
?>
 
<br />
<br />
 
This is the entire code of the process page.


<?php

function insertJob() {
$job_title = htmlspecialchars(trim($_POST['job_title']), ENT_QUOTES);
$job_description = str_replace(array("\r\n", "\n", "\r"), "<br />", htmlspecialchars(trim($_POST['job_description']), ENT_QUOTES));
$job_function = implode(" ", $_POST['job_function']);
$job_language = implode(" ", $_POST['job_language']);
$job_location = implode(" ", $_POST['job_location']);
$job_industry = implode(" ", $_POST['job_industry']);
$job_contract = implode(" ", $_POST['job_contract']);
$job_experience = implode(" ", $_POST['job_experience']);
$job_education = implode(" ", $_POST['job_education']);
$job_offer = str_replace(array("\r\n", "\n", "\r"), "<br />", htmlspecialchars(trim($_POST['job_offer']), ENT_QUOTES));
$job_reference = htmlspecialchars(trim($_POST['job_reference']), ENT_QUOTES);
$job_address = str_replace(array("\r\n", "\n", "\r"), "<br />", htmlspecialchars(trim($_POST['job_address']), ENT_QUOTES));
$job_happly = implode(" ", $_POST['job_happly']);
$job_payment = implode(" ", $_POST['job_payment']);
$pk = decryptUser();
$date = date('Y-m-d');


queryDatabase("INSERT INTO job (job_title, job_description, job_inserted, in_industry, in_location, in_user, in_function, in_contract, in_experience, in_education, job_offer, job_reference, job_address, in_happly, in_payment, in_language)
VALUES ('$job_title', '$job_description', '$date', '$job_function', '$job_location', '$job_industry', '$job_contract', '$job_experience', '$job_education', '$job_offer', '$job_reference', '$job_address', '$job_happly', '$job_payment', '$job_language', $pk)");

)

?>


Now when i input the valus and submit, i am getting the following error..

Parse error: syntax error, unexpected ')' in C:\AppServ\www\sitename\library\process.php on line 47

Can anyone help me out please....

Edit/Delete Message
helraizer
Forum Commoner
Posts: 31
Joined: Thu Jun 05, 2008 8:20 pm

Re: Populating drop down list with mysql data and add to db

Post by helraizer »

Code: Select all

 
function insertJob() {
$job_title = htmlspecialchars(trim($_POST['job_title']), ENT_QUOTES);
$job_description = str_replace(array("\r\n", "\n", "\r"), "<br />", htmlspecialchars(trim($_POST['job_description']), ENT_QUOTES));
$job_function = implode(" ", $_POST['job_function']);
$job_language = implode(" ", $_POST['job_language']);
$job_location = implode(" ", $_POST['job_location']);
$job_industry = implode(" ", $_POST['job_industry']);
$job_contract = implode(" ", $_POST['job_contract']);
$job_experience = implode(" ", $_POST['job_experience']);
$job_education = implode(" ", $_POST['job_education']);
$job_offer = str_replace(array("\r\n", "\n", "\r"), "<br />", htmlspecialchars(trim($_POST['job_offer']), ENT_QUOTES));
$job_reference = htmlspecialchars(trim($_POST['job_reference']), ENT_QUOTES);
$job_address = str_replace(array("\r\n", "\n", "\r"), "<br />", htmlspecialchars(trim($_POST['job_address']), ENT_QUOTES));
$job_happly = implode(" ", $_POST['job_happly']);
$job_payment = implode(" ", $_POST['job_payment']);
$pk = decryptUser();
$date = date('Y-m-d');
 
 
queryDatabase("INSERT INTO job (job_title, job_description, job_inserted, in_industry, in_location, in_user, in_function, in_contract, in_experience, in_education, job_offer, job_reference, job_address, in_happly, in_payment, in_language)
VALUES ('$job_title', '$job_description', '$date', '$job_function', '$job_location', '$job_industry', '$job_contract', '$job_experience', '$job_education', '$job_offer', '$job_reference', '$job_address', '$job_happly', '$job_payment', '$job_language', $pk)");
 
) // line 47. Should be }
 
 
You're closing the function with a rounded bracket. You need to change that to a curly bracket }

and it'll be fine
Post Reply