Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6814575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:42:19+00:00 2026-05-26T20:42:19+00:00

I am a very inexpert php programmer, I ve done some asp.net programming but

  • 0

I am a very inexpert php programmer, I ve done some asp.net programming but never php.

I need the requirement to add a dropdownlist with values from a table in the mysql database. I manually created a table training:
id
training
date
hour
openseats

And I need to display this dates and hour in the dropdownlist, so once the user clikc submits this get stored into a table called
jos_jquarks_users_acknowledge

Can you help me how to pupulate the dropdown?

Code:

{source}
<!-- You can place html anywhere within the source tags -->
<?php 
// If the constant _JEXEC is not defined, quit now.
// This stops this script from running outside of the system.
defined( '_JEXEC' ) or die( 'Restricted access' );
?>

<?php

$user = JFactory::getUser(); 
$id = $user->get('id'); 
$name = $user->get('name');
$username = $user->get('username'); 
$department = $user->get('department');

$vardate = date("Y-m-d H:i:s");

$acknowledge = 1;
$courseTitle = $mainframe->getPageTitle();

$courseDate = ;
$courseHour =;


/***************************************/

$db = &JFactory::getDBO();

$query = "
INSERT INTO
`jos_jquarks_users_acknowledge`
(
course_name,
user_id,
employeeNumber,
department,
name,
acknowledge,
timeStamp,courseDate,
courseHour
)
VALUES
(
'{$courseTitle}',
'{$id}',
'{$username}',
'{$department}',
'{$name}',
'{$acknowledge}',
'{$vardate}',
'{$courseDate}',
'{courseHour}'

 )";

$db->setQuery($query);

$db->query();


if($db->getErrorNum()) { 
JError::raiseError( 500, $db->stderr()); 
}

?>

<form name="quiz_info" method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>"> 

<?php echo JText::_('Do you want to enroll into the course?') ; ?>

<? $queryCourses="SELECT training_id,training,trainingDate FROM training"; ?>

$result = mysql_query ($queryCourses); 
echo "<select name=courseDates value=''>Date</option>"; 
// printing the list box select command 

while($nt=mysql_fetch_array($result)){//Array or records stored in $nt 
echo "<option value=$nt[id]>$nt[training]</option>"; 
/* Option values are added by looping through the array */ 
} 
echo "</select>";//Closing of list box

<input id="proceedButton" name="proceedButton" value="Acknowledge" type="submit" />

<input type="hidden" name="layout" value="default" /> <?php echo JHTML::_( 'form.token' ); ?>

</form>

{/source} 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:42:19+00:00Added an answer on May 26, 2026 at 8:42 pm

    Difficult to know where to start in trying to answer.
    How much of the above code is actual, and how much is for demo purposes in asking the question?
    I assume you wont be inserting data into the database on each page load.
    I assume you won’t be hard coding your database table name with the ‘jos_’ prefix. When doing this for real you should use ‘#__’ without the quotes.

    Does a database query returning an error need to kill the script and raise a server 500 error? I think detecting and intercepting the error and handling gracefully would be better.

    After your tag you have the word date and then a – ie you close an option tag you never opened. I assume you intend to somehow label the select – best to do this with an actual tag rather than populating a dummy option within the select.

    If you don’t wrap your array keys in quotes you’ll probably generate warnings – so do this
    $nt[‘training’] rather than $nt[training]

    You probably need to retrieve as associative array rather than a standard ordinal array.

    You then run a database query ‘outside’ of Joomla. You have retrieved the database object – you should use it rather than running mysql_query directly.

    Instead of this:

    $queryCourses="SELECT training_id,training,trainingDate FROM training"; ?>
    $result = mysql_query ($queryCourses);
    

    You probably need to do something more like this

    // http://docs.joomla.org/How_to_use_the_database_classes_in_your_script#loadAssoc.28.29

    $queryCourses="SELECT training_id,training,trainingDate FROM training"; ?>
    $db->setQuery($queryCourses);
    $db->query();
    
    $num_rows = $db->getNumRows();
    if(! $num_rows){ 
        // return or die or something - there ar no results
    }
    while($nt = $db->loadAssoc()){
    

    On this line

    echo "<option value=$nt['id']>$nt['training']</option>"; 
    

    you should probably do this:

    echo "<option value=\"{$nt['id']}\">{$nt['training']}</option>"; 
    

    clearly delineating the variables with curly braces as the whole line is wrapped in quotes and remembering to put quotes around the value parameter in case you decide to add other variables into there and include spaces etc.

    From your description you want to display the date to the user – you probably want to add an extra variable – maybe two within the … part, perhaps something like:

    echo "<option value=\"{$nt['id']}\">{$nt['training']} {$nt['trainingDate']}</option>"; 
    

    I’m sure there are other things that I’m missing – and I’ve assumed your db query is broadly correct and returns results, but there should be enough pointers there to get you on the right track.

    Finally – when building / populating a select list you can build data structures and get Joomla’s jHTML class to do the heavy lifting for you. I wonder sometimes if too much abstraction creates more work than rolling your own – but hey, the option is there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Very often when working on an ASP.NET web site, the options View Code and
Very basic, But I don't know, How to add JSoup.jar to my android workspace?
Very new to PHP and ran into some trouble and was wondering if anyone
Very periodically, some of our forms in our MDI vb.net project will return me.parent
Very new to PHP/programming in general, and I've been trying to run a PHP
Very simply, what is tail-call optimization? More specifically, what are some small code snippets
Very odd problem as this is working perfectly on our old Classic ASP site.
Very direct question, i need to know if its possible and maybe where to
Very simple question but giving me hard time, I want to replace to \
Very simple I guess but I cannot get what I perceive to be the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.