I have dropdown menu below where it retrieves the possible modules id’s and their module’name which the user can select from, from the database.
Below is the code for this:
$moduleHTML = "";
$moduleHTML .= '<select name="module" id="modulesDrop">'.PHP_EOL;
$moduleHTML .= '<option value="">Please Select</option>'.PHP_EOL;
foreach ($courseData['Modules'] as $moduleId => $moduleData) {
$moduleHTML .= "<option value='".$moduleId.' '.$moduleData['ModuleName']."'>" . $moduleId . " - " . $moduleData['ModuleName'] ."</option>".PHP_EOL;
}
}
$moduleHTML .= '</select>';
Now when the form is submitted, on the NEXT PAGE I want only the ‘ModuleId’ to be inserted into the ‘ModuleId’ field. But instead what it is doing is that it is inserting the moduleId and the first letter of the ModuleName.
For example if the user selects the module ‘CHI2520 Systems Strategy’ from the drop down menu, then when I insert this in the database, instead of ‘CHI2520’ being inserted in the ‘ModuleId’ field, it inserts ‘CHI2520 S’ in the ‘ModuleId’.
How can the insert be fixed so that it only inserts the Module Id and not the Module Id and the first letter of the Module Name?
Below is the code on the INSERT VALUES into the database:
$sql="INSERT INTO Session (ModuleId)
VALUES
(' ". mysql_real_escape_string( $_POST['module'] ) . "')";
Change this part:
to