Hey there,
I am trying to integrate switch statements (unless you have a better option). What I want to do is decrease a piece of data in the database. The amount of the decrease is calculated based on the amount of time the person inputs, which is then multiplied by X, where X is determined by which option was selected on the drop down. {select_2} is the name of the dropdown in the chronoform. {text_6} is hours. {text_7} is minutes.
When $taskcost was just an integer (before I tried to write in the switch statement), the data was decreased (ie. it worked). Since writing in the switch statement, it is not working. Any ideas?
Thanks so much.
I am trying to integrate switch statements (unless you have a better option). What I want to do is decrease a piece of data in the database. The amount of the decrease is calculated based on the amount of time the person inputs, which is then multiplied by X, where X is determined by which option was selected on the drop down. {select_2} is the name of the dropdown in the chronoform. {text_6} is hours. {text_7} is minutes.
<?php
switch ($_POST["select_2"])
{
case "Type 1" :
$taskcost = 6;
break;
case "Type 2" :
$taskcost = 10;
break;
}
$debitthisamount = ($_POST[text_6] + ($_POST[text_7])/60) * $taskcost;
echo ("Thank You For Your Submission");
$database =& JFactory::getDBO();
$user =& JFactory::getUser();
$database->setQuery( "UPDATE jos_jumbo SET credit=credit-'{$debitthisamount}' WHERE userid='{$user->id}'" );
$database->query();
?>When $taskcost was just an integer (before I tried to write in the switch statement), the data was decreased (ie. it worked). Since writing in the switch statement, it is not working. Any ideas?
Thanks so much.
Hi,
Crossposting really isn't that helpful, feel free however to bump your post if there's been no response.
The first thing that comes to mind, is that you do not have a default case in your switch statement, opening the possibility that $taskcost never gets assigned any value at all. Also, it would seem you convert the value of $debitthisamount into a string ('{$debitthisamount}') in your query, which the sql-server then would probably treat as a 0 value.
Try enabling the SQL-query debug output in your site config, that should reveal what actual query is sent, which then would hint as to what needs to be changed..
/Fredrik
Crossposting really isn't that helpful, feel free however to bump your post if there's been no response.
The first thing that comes to mind, is that you do not have a default case in your switch statement, opening the possibility that $taskcost never gets assigned any value at all. Also, it would seem you convert the value of $debitthisamount into a string ('{$debitthisamount}') in your query, which the sql-server then would probably treat as a 0 value.
Try enabling the SQL-query debug output in your site config, that should reveal what actual query is sent, which then would hint as to what needs to be changed..
/Fredrik
Hey Fredrik,
Thank you so much. I apologize for the cross positing. I only reposted because I did not know how to move the post. I just deleted the other post.
I will do what you said and see what i can come up with. Thanks!
Thank you so much. I apologize for the cross positing. I only reposted because I did not know how to move the post. I just deleted the other post.
I will do what you said and see what i can come up with. Thanks!
This topic is locked and no more replies can be posted.
