PHP with 'enexpected' T_ELSEIF - if-statement

I am really wondering why this code is wrong, I have already been searching for a solution for over an hour on the internet! this is for a school project.
error:
Parse error: syntax error, unexpected 'elseif' (T_ELSEIF) in C:\00usbx\xampp\htdocs\index.php on line 344
script from line 344 to 346:
} elseif ($path[2] == 'noteshop') {
$post = $path[3]; {
if($_SESSION[login] == 'true') { ?>

you need to terminate the original if with an else :
} elseif ($path[2] == 'noteshop') {
$post = $path[3];
else {} // ?
if($_SESSION[login] == 'true') { ?>
i don't know your intent but there was an errant { which i couldnt understand as a nested expression or just cruft

Related

Error while executing if else condition in Powershell

I am trying to execute the if & else code but unable to pass through the condition
{
if(($ENV_TYPE = 'Dev') && ($REGION_CODE = 'eus2'))
{
}
else
{
}
}
Both the env_type and region_code values are getting from env variables
I get this error:
The token '&&' is not a valid statement separator in this version.
if ($ENV_TYPE -eq 'Dev' -And $REGION_CODE -eq 'eus2'){
}

Drupal 8 Webform add prefix to uploaded file names

I have a webform with a file upload field. I need do one of two things. Either upload files into a subfolder inside the private area, OR, add a prefix to the filename that the user is uploading. The user can upload several files. The webform editor allows you to 'Rename' the file and use tokens for this, but I don't see any way of preserving the original file name. I can hack getFileDestinationUri() in WebformManagedFileBase.php to do what I want, but obviously I would rather not do that. Am I missing something?
It turns out that you can use the drupal form alter hook to alter the destination. I had thought of this but felt if was unlikely to work. It does.
Below is MY code solution: (I may be missing container types)
function _mymodule_fix_elements(&$elements) {
foreach ($elements as $key => &$element) {
if (strpos($key, '#') !== 0) {
if (is_array($element)) {
if (isset($element['#type'])) {
if (($element['#type'] == 'fieldset') ||
($element['#type'] == 'webform_flexbox') ||
($element['#type'] == 'container')) {
_mymodule_fix_elements($element);
} else if ($element['#type'] == 'managed_file') {
$pattern = $element['#upload_location'];
if (strpos($pattern, 'private:') === 0) {
$element['#upload_location'] = $pattern . '/' . $key;
}
}
}
}
}
}
}
function mymodule_form_alter(&$form, &$form_state, $id) {
if (strpos($id, 'webform_') === 0) {
_mymodule_fix_elements($form['elements']);
}
}

allocating a string based on PHP if statement

I quite new to PHP this seems to be causing me problems:
<?php
$ppe1="Water";
echo $ppe1;
if ($ppe1="Tap") {
$dog="time";
}
else
{$dog="travel";}
echo $dog;
?>
I am obviously being bery stupid but I cannot seem to allocate the $dog string based on the if statement
You should have a read on:
Comparison Operators.
In short: You are not comparing but assigning a value with =.
<?PHP
$ppe1 = "Walter";
$dog = $ppe1 === "Tap" ? "time" : "travel";
echo $dog;
This makes use of the ternary operator which is basically $variable = boolean expression ? then : else;
Or with your code structure:
<?PHP
$ppe1 = "Walter";
$dog = "";
if($ppe1 === "Tap")
{
$dog = "time";
}
else
{
$dog = "travel";
}
echo $dog;
Take a look at the Comparison Operators. Use the following code. Also as you said you are a beginner, I recommend you to read this.
<?php
$ppe1 = "Water";
echo $ppe1; // "Water"
if ($ppe1 == "Tap") {
$dog = "time";
} else {
$dog="travel";
}
echo $dog; // "travel"
?>

Problems with a IF statement with multiple POSTS in it

I seem to have a problem which I can't seem to figure out.
I've made a simple index.php where I include all my files on conditions.
But I get an 500 error: PHP Parse error: syntax error, unexpected '{' in index.php on line 6
My code looks like this:
<?php
session_start();
$level = $_SESSION['Code'];
$functie = $_SESSION['cia'];
if (ISSET($_POST['projectmaken']) || ISSET($_POST['verstuurf']) {
include 'NieuwProject.php';
}
else {
if ($level == 3 || $level == 4 || $functie == "supervisor") {
include 'deadlineproject.php';
}
else {
include '/';
}
}
?>
Does anyone know the problem here?
Thanks in advance!

Check if multiple textboxes are empty PHP if not then execute php

<?
if ($_POST['username'] == NULL){ //if nothing is entered or only a zero is entered
echo "Missing a field.";
}else{
//rest of code
}
This won't handle multiple textboxes I have 3: username, password, email
Try the below PHP code
<?
if ($_POST['username'] == NULL ||
$_POST['password'] == NULL ||
$_POST['email'] == NULL)
{ //if nothing is entered or only a zero is entered
echo "Missing a field.";
}else{
//rest of code
}
if(empty($_POST['memberfullname'])){
header("Location:srgbusinesspartnersmsg.php");
} else {
$insert= $con->command($ins);
header("Location:srgvalidatepartners.php");
}
This works for me. if it is empty , redirect a dialog form and else execute the job which is here an insert statement to be executed
Join us on Missionsoft Programming Institute (mtscertification.com)