By anamashrafali on
Hey everyone, I am new to drupal and trying to get a hang of module coding. This is what I have done so far :
function deallocmodule_menu() {
$items = array();
$items['deallocmodule/form'] = array(
'title' => t('Deallocation Form'),
'page callback' => 'deallocmodule_form',
'access arguments' => array('access content'),
'description' => t('Form for Deallocating Resources'),
'type' => MENU_CALLBACK,
);
return $items;
}
function deallocmodule_form() {
return drupal_get_form('deallocmodule_my_form');
}
// Create a fieldset for the form for Resource details:
function deallocmodule_my_form($form_state) {
$form['Dealloc'] = array(
'#type' => 'fieldset',
'#title' => t('Resource Details'),
);
// Textfield for resource details
$form['resource']['UserID'] = array(
'#type' => 'textfield',
'#title' => t('User ID'),
'#size' => 10,
'#description' => t('Assigned ID of the Resource to be Deallocated'),
);
$form['resource']['ProjID'] = array(
'#type' => 'textfield',
'#title' => t('Project ID'),
'#size' => 10,
'#description' => t('Assigned ID of the Project to which the Resource is presently allocated'),
);
// Finally, a submit button:
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Deallocate Resource'),
);
return $form;
}
function deallocmodule_my_form_submit($form,&$form_state)
{
$uid = $form_state['values']['UserID'];
$pid = $form_state['values']['ProjID'];
//Here check to see if the record exists of such allocation in the rms_Allocation Table, if it does then change the status to 'deallocated'
//and fetch the allocationtypeID, according to allocationtypeID make subtraction/addition to the SumPercent in User Table
function dealloacmodule_update($node)
{
//check if the resource record exists in parameters with ProjID and UserID
$exists = db_result(db_query('SELECT AllocID FROM rms_allocation WHERE UserID = %d AND ProjectID = %d', $node->uid,$node->pid));
if($exists <> null)
{
db_query("update rms_allocation set Status = 'Dealloacted');
}
else
{
drupal_set_message(t('The resource has been dealloacted.'));
}
//Now Subtract the SumPercent Allocated of the Resource according to the allocation type.
}
}
- The problem is that this code doesn't compile and gives an error which is :
Parse error: parse error, expecting `T_VARIABLE' or `T_DOLLAR_OPEN_CURLY_BRACES' or `T_CURLY_OPEN' in C:\wamp\www\sites\all\modules\Deallocation Module\Deallocation.module on line 74
- Please tell me what I am doing wrong, I feel like its a very silly mistake.
Thanks!
Comments
Which line?
The error message clearly points you to a line number. What's on that line?
In the code you posted, there's an obvious error here:
Actually two, if you count spelling.
text field..
There is nothing on line 74, the code ends at 73.
And abt db_query, the field Status is a text field whose content I am trying to change to 'Deallocated' if the ProjID and UserID matches.
- Spelling mistake, noted.
Look more closely
You should be editing your code with a proper programmer's editor. I use Gedit on Linux; Komodo is a good cross-platform editor that runs on everything. A programmer's editor will colorize your code so that it's easier to see where you've made a mistake.
Fortunately so does Drupal's code filter, and if you look at the code you pasted onto this page you'll notice that the last several lines are all red.
Your error is here:
db_query("update rms_allocation set Status = 'Dealloacted');PHP reads this line, which has an open double quote. It considers everything until a matching double quote to be a quoted string.
So the last section of your code is never parsed by PHP at all. PHP runs off the end of your file (line 73) looking for your to close your quoted string and then throws the error at what it considers to be line 74.
This is actually pretty common with script processors and compilers -- they give up trying to figure out what you mean several lines after your actual error. When you get an error like this, work backward from the cited line until you find something out of kilter.
You should have a look at the
You should have a look at the form example module (in here: http://drupal.org/project/examples).
Your code is violating best practices and I really recommend you to have a look on it.
try to change;if($exists <>
try to change;
if($exists <> null) {with;
if(db_affected_rows($exists) > 0) {and
db_query("update rms_allocation set Status = 'Dealloacted');add coma
db_query("update rms_allocation set Status = 'Dealloacted'");