New Error.. Cant Figure This One Out - php

My timestamp code worked well before i put it in a function.. Get this parse error on line 55, ive marked the line number with "// LINE 55", cant figure it out :(
Here's my error:
Parse error: syntax error, unexpected '.' in C:\wamp\www\flueforumdk\config.php on line 55
Here's the calling of the function:
$GET_UNIX_STAMP_FROM_DB = $art[tidspunkt];
$UNIX_TIME_SECONDS = $GET_UNIX_STAMP_FROM_DB;
echo timestamp_converter($UNIX_TIME_SECONDS);
Here's my function code:
## TIMESTAMP CONVERTER FUNCTION
function timestamp_converter($UNIX_TIME_SECONDS){
// UDREGNING FRA UNIX TIME
$tid = time() - $UNIX_TIME_SECONDS;
$timer = floor($tid/3600);
$minutter = floor($tid/60);
$dage = floor($timer / 24);
$uge = floor($dage / 7);
$month = floor($dage / 30.5);
$aar = floor($dage / 365);
if($tid < 60){
echo"<b>$tid</b> sekunder";
} elseif ($tid > 60){
echo"";
}
if($minutter == 0){
echo"";
} elseif ($minutter < 60){
if($minutter == 1){
echo"<b>$minutter</b> minut";
}else{
echo"<b>$minutter</b> minutter";
}
}
if($timer == 0){
echo"";
} elseif ($timer < 24){
if($timer == 1){
echo"<b>$timer</b> time";
}else{
echo"<b>$timer</b> timer";
}
}
//LINE 55 if($dage == 0){
echo"";
} elseif ($dage < 7){
if($dage == 1){
echo"<b>$dage</b> dag";
}else{
echo"<b>$dage</b> dage";
}
}
if($uge == 0){
echo"";
} elseif ($uge < 4){
if($uge == 1){
echo"<b>$uge</b> uge";
}else{
echo"<b>$uge</b> uger";
}
}
if($month == 0){
echo"";
} elseif ($month < 12){
if($month == 1){
echo"<b>$month</b> måned";
}else{
echo"<b>$month</b> måneder";
}
}
if($aar == 0){
echo"";
} elseif ($aar > 0){
if($aar == 1){
echo"<b>$aar</b> år";
}else{
echo"<b>$aar</b> år";
}
}
}

Related

Undefined variable error when doing calculations

I have a web application that I'm rebuilding in Laravel for a cleaning company.
1) I pass in the paramaters to the URL route
http://127.0.0.1:8000/book?bed_range=1&bath_range=1&percentage_range=0&duration_range=
2) It does calculations:
$bedroomCostFactor = [0, 30, 60, 90, 120, 150];
$bathroomCostFactor = [0, 20, 40, 60, 80, 100];
$percentageFactor = [0, 5, 15, 10, 20];
if (isset($bed_range) && !empty($bed_range)) {
if ($bed_range == 1) {
$bed_cost = $bedroomCostFactor[0];
} else if ($bed_range == 2){
$bed_cost = $bedroomCostFactor[1];
} else if ($bed_range == 3){
$bed_cost = $bedroomCostFactor[2];
} else if ($bed_range == 4){
$bed_cost = $bedroomCostFactor[3];
} else if ($bed_range == 5){
$bed_cost = $bedroomCostFactor[4];
} else if ($bed_range == 6){
$bed_cost = $bedroomCostFactor[5];
}
}
if(isset($bath_range) && !empty($bath_range)) {
if ($bath_range == 1) {
$bath_cost = $bathroomCostFactor[0];
} else if ($bath_range == 2){
$bath_cost = $bathroomCostFactor[1];
} else if ($bath_range == 3){
$bath_cost = $bathroomCostFactor[2];
} else if ($bath_range == 4){
$bath_cost = $bathroomCostFactor[3];
} else if ($bath_range == 5){
$bath_cost = $bathroomCostFactor[4];
} else if ($bath_range == 6){
$bath_cost = $bathroomCostFactor[5];
}
}
if(isset($percentage_range) && !empty($percentage_range)) {
if ($percentage_range == 0) {
$percentage_cost = $percentageFactor[0];
} else if ($percentage_range == 5){
$percentage_cost = $percentageFactor[1];
} else if ($percentage_range == 15){
$percentage_cost = $percentageFactor[2];
} else if ($percentage_range == 10){
$percentage_cost = $percentageFactor[3];
} else if ($percentage_range == 20){
$percentage_cost = $percentageFactor[4];
}
}
$subtotal = "100.00";
$tax = number_format($subtotal * .0725, 2);
$total = $subtotal + $tax;
$discount = number_format(($subtotal * $percentage_cost) / 100, 2);
For some reason, when I migrate the code to Laravel, it no longer works and it starts saying variables like $discount and $percentage_cost are undefined.
In my previous application the calculations run just fine like you'd expect. Why isn't it working in Laravel?
I had to remove the if condition
if(isset($percentage_range) && !empty($percentage_range)) {

Inserting echo via mysql statement

I am aiming to insert the respective learning style into the database if the echo statement has been triggered by the if statement. The DB columns are as follows: studentNumber, dimension1, dimension2, dimension3, dimension4. Any feedback would be appreciated. Trialing 'mildly active' hence the statement only being present at that stage of the code.
<?php
$active =0;
$reflective=0;
$sensing=0;
$intuitive=0;
$visual=0;
$verbal=0;
$sequential=0;
$global=0;
$mildlyActive = "Mildly Active";
$moderatelyActive = "Moderately Active";
$stronglyActive = "Strongly Active";
$mildlyReflective = "Mildly Reflective";
$moderatelyReflective = "Moderately Reflective";
$stronglyReflective = "Strongly Reflective";
if(isset($_POST['submit'])){
foreach($_POST as $key=>$value){
if($key != "submit"){
$dbQuery1 = $db->prepare("select * FROM answer WHERE answerID = '".$value."'");
$dbQuery1-> execute();
while ($dbRow = $dbQuery1->fetch (PDO::FETCH_ASSOC)){
$answerTypeID=$dbRow["answerTypeID"];
$dbQuery2 = $db->prepare("select * FROM answerType WHERE answerTypeID = '".$answerTypeID."'");
$dbQuery2-> execute();
while ($dbRow2=$dbQuery2->fetch()){
$answerType=$dbRow2["answerType"];
//echo $answerType;
if ($answerType=='active'){
$active++;
}
if ($answerType=='reflective'){
$reflective++;
}
if ($answerType=='sensing'){
$sensing++;
}
if ($answerType=='intuitive'){
$intuitive++;
}
if ($answerType=='visual'){
$visual++;
}
if ($answerType=='verbal'){
$verbal++;
}
if ($answerType=='sequential'){
$sequential++;
}
if ($answerType=='global'){
$global++;
}
}
}
$dbQuery=$db->prepare("INSERT INTO `userResponse` VALUES (:studentID, :questionID, :answerID)");
$dbParams=array('studentID'=>$_SESSION["currentUser"], 'questionID'=>$key, 'answerID'=>$value);
$dbQuery->execute($dbParams);
}
}
}
if ($active>$reflective){
$total = $active - $reflective;
if ($total == 1){
echo "Mildly active";
$dbQuery=$db->prepare("INSERT INTO indexLearningStyle (dimension1) VALUE (:mildlyActive)");
}
if ($total == 2){
echo "Mildly active";
$dbQuery=$db->prepare("INSERT INTO indexLearningStyle (dimension1) VALUE (:mildlyActive)");
}
if($total == 3){
echo "Moderately active";
}
if($total == 4){
echo "Moderately active";
}
if ($total == 5){
echo "Strongly active";
}
}
else {
$total = $reflective - $active;
if ($total == 1){
echo "Mildly reflective";
}
if ($total == 2){
echo "Mildly reflective";
}
if ($total == 3){
echo "Moderately reflective";
}
if ($total == 4){
echo "Moderately reflective";
}
if ($total == 5){
echo "Strongly reflective";
}
}
if ($sensing>$intuitive){
$total = $sensing - $intuitive;
if ($total == 1){
echo "Mildly sensing";
}
if ($total == 2){
echo "Mildly sensing";
}
if($total == 3){
echo "Moderately sensing";
}
if($total == 4){
echo "Moderately sensing";
}
if ($total == 5){
echo "Strongly sensing";
}
}
else {
$total = $intuitive - $sensing;
if ($total == 1){
echo "Mildly intuitive";
}
if ($total == 2){
echo "Mildly intuitive";
}
if ($total == 3){
echo "Moderately intuitive";
}
if ($total == 4){
echo "Moderately intuitive";
}
if ($total == 5){
echo "Strongly intuitive";
}
}
if ($visual>$verbal){
$total = $visual - $verbal;
if ($total == 1){
echo "Mildly visual";
}
if ($total == 2){
echo "Mildly visual";
}
if($total == 3){
echo "Moderately visual";
}
if($total == 4){
echo "Moderately visual";
}
if ($total == 5){
echo "Strongly visual";
}
}
else {
$total = $verbal - $visual;
if ($total == 1){
echo "Mildly verbal";
}
if ($total == 2){
echo "Mildly verbal";
}
if ($total == 3){
echo "Moderately verbal";
}
if ($total == 4){
echo "Moderately verbal";
}
if ($total == 5){
echo "Strongly verbal";
}
}
if ($sequential>$global){
$total = $sequential - $global;
if ($total == 1){
echo "Mildly sequential";
}
if ($total == 2){
echo "Mildly sequential";
}
if($total == 3){
echo "Moderately sequential";
}
if($total == 4){
echo "Moderately sequential";
}
if ($total == 5){
echo "Strongly sequential";
}
}
else {
$total = $global - $sequential;
if ($total == 1){
echo "Mildly global";
}
if ($total == 2){
echo "Mildly global";
}
if ($total == 3){
echo "Moderately global";
}
if ($total == 4){
echo "Moderately global";
}
if ($total == 5){
echo "Strongly global";
}
}
?>

PHP For Loop only running once

I have a for loop to cycle through and array, run a database query in relation to each element, then call a function that prints out something in relation to it. The array is 12 elements long but the for loop never gets past element 0. It doesn't error or fail it just doesn't do anything after the first element. I verified that by putting the echo $x; and echo $vendorsname[$x]; at the start of each loop cycle and sure enough it only ever echo's 0 out to the page.
$continuetill = count($vendorsname);
for ($x = 0; $x < $continuetill; $x++)
{
echo $x;
echo $vendorsname[$x];
$sql="SELECT low,mid,high,verlow,vermin,verhigh FROM vendors WHERE vendor = ".$x." ORDER BY id DESC LIMIT 1";
if ($result=mysqli_query($conn,$sql))
{
// Fetch one and one row
while ($row=mysqli_fetch_row($result))
{
$low = $row[0];
$mid = $row[1];
$high = $row[2];
$verlow = $row[3];
$vermid = $row[4];
$verhigh = $row[5];
if(($low > $mid) && ($low > $high))
{
likely295Message($vendorsname[$x]);
}
elseif (($high > $low) && ($high > $mid) && ($high < 15))
{
possibly300Message($vendorsname[$x]);
}
elseif (($high > $low) && ($high > $mid) && ($high >= 15))
{
likely300Message($vendorsname[$x]);
}
elseif (($mid > $low) && ($mid > $high))
{
likely296Message($vendorsname[$x]);
}else
{
unknownMessage($vendorsname[$x]);
}
if(($verlow != 0) || ($vermid != 0) || ($verhigh != 0))
{
if(($verlow > $vermid) && ($verlow > $verhigh))
{
verified295Message($vendorsname[$x]);
changeBackgroundBack($vendorsname[$x]);
changeImage($vendorsname[$x]);
}
elseif (($verhigh > $verlow) && ($verhigh > $vermid))
{
verified300($vendorsname[$x]);
changeBackground($vendorsname[$x]);
changeImage($vendorsname[$x]);
}
elseif (($vermid > $verlow) && ($vermid > $verhigh))
{
verified296($vendorsname[$x]);
changeBackgroundBack($vendorsname[$x]);
changeImage($vendorsname[$x]);
}
}
}
mysqli_free_result($result);
}
}
Make sure you have error displaying turned on. Add at the beginning of your script:
ini_set('display_errors', 1);
to make sure you don't have any errors.

php conditional form validation by date

I have the function below that takes an entered date and serves different validation messages base don the dates value .The thing is is not always working as it's supposed. I'm new at PHP and maybe i'm doing something wrong. Anyone has an ideea how to correct it?
function validate_date($result, $value, $form, $field){
$date1=date("Y", strtotime($value));
$date2=date("Y");
$diff= $date2-$date1;
$diff2=18-$diff;
if ($value ==0) {
$result["is_valid"] = false;
$result["message"] = "Compeltati data!";
}
else {
if ($diff < 0) {
$result["is_valid"] = false;
$result["message"] = "Data invalida!";
}
elseif ($diff == 0) {
$result["is_valid"] = false;
$result["message"] ="Data invalida!";
}
elseif ($diff > 0){
if ($diff2 > 0 and $diff2 < 5 ){
$result["is_valid"] = true;
echo '<script type="text/javascript">alert("Va trebuie confirmarea parintilor. Contactati-ne pe email!");</script>';
}
elseif ($diff2 > 5) {
$result["is_valid"] = false;
$result["message"] = "Nu aveti varsta minima pentru participare!";
}
}
}
return $result;
}
As I understand $diff is AGE and $diff2 is how much he/she is younger then 18year age. In that case if age of person is more then 18 then $diff2 will be negative and you have'nt added any clause for $diff2<0. so add it like:
if ($diff2 > 0 and $diff2 < 5 ){
$result["is_valid"] = true;
echo '<script type="text/javascript">alert("Va trebuie confirmarea parintilor. Contactati-ne pe email!");</script>';
}
elseif ($diff2 > 5) {
$result["is_valid"] = false;
$result["message"] = "Nu aveti varsta minima pentru participare!";
}
else { //for $diff<=0
$result["is_valid"] = false; //as you need change it on age >=18
$result["message"] = "as you need!";
}

Problem calling method inside same method in php?

Will any one please tell me how to run this class. I am getting the FATAL ERROR: Fatal error: Call to undefined function readnumber() in E:\Program Files\xampp\htdocs\numberToWords\numberToWords.php on line 20 while giving input as 120
<?php
class Test
{
function readnumber($num, $depth)
{
$num = (int)$num;
$retval ="";
if ($num < 0) // if it's any other negative, just flip it and call again
return "negative " + readnumber(-$num, 0);
if ($num > 99) // 100 and above
{
if ($num > 999) // 1000 and higher
$retval .= readnumber($num/1000, $depth+3);
$num %= 1000; // now we just need the last three digits
if ($num > 99) // as long as the first digit is not zero
$retval .= readnumber($num/100, 2)." hundred\n";
$retval .=readnumber($num%100, 1); // our last two digits
}
else // from 0 to 99
{
$mod = floor($num / 10);
if ($mod == 0) // ones place
{
if ($num == 1) $retval.="one";
else if ($num == 2) $retval.="two";
else if ($num == 3) $retval.="three";
else if ($num == 4) $retval.="four";
else if ($num == 5) $retval.="five";
else if ($num == 6) $retval.="six";
else if ($num == 7) $retval.="seven";
else if ($num == 8) $retval.="eight";
else if ($num == 9) $retval.="nine";
}
else if ($mod == 1) // if there's a one in the ten's place
{
if ($num == 10) $retval.="ten";
else if ($num == 11) $retval.="eleven";
else if ($num == 12) $retval.="twelve";
else if ($num == 13) $retval.="thirteen";
else if ($num == 14) $retval.="fourteen";
else if ($num == 15) $retval.="fifteen";
else if ($num == 16) $retval.="sixteen";
else if ($num == 17) $retval.="seventeen";
else if ($num == 18) $retval.="eighteen";
else if ($num == 19) $retval.="nineteen";
}
else // if there's a different number in the ten's place
{
if ($mod == 2) $retval.="twenty ";
else if ($mod == 3) $retval.="thirty ";
else if ($mod == 4) $retval.="forty ";
else if ($mod == 5) $retval.="fifty ";
else if ($mod == 6) $retval.="sixty ";
else if ($mod == 7) $retval.="seventy ";
else if ($mod == 8) $retval.="eighty ";
else if ($mod == 9) $retval.="ninety ";
if (($num % 10) != 0)
{
$retval = rtrim($retval); //get rid of space at end
$retval .= "-";
}
$retval.=readnumber($num % 10, 0);
}
}
if ($num != 0)
{
if ($depth == 3)
$retval.=" thousand\n";
else if ($depth == 6)
$retval.=" million\n";
if ($depth == 9)
$retval.=" billion\n";
}
return $retval;
}
}
$objTest = new Test();
$objTest->readnumber(120,0);
?>
You are using the readnumber function in the class itself, try this instead where it appears $this->readnumber

Categories