Syntax error - unexpected ":" [closed] - php

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
My php script directs to a url depending on which submit button was pressed. However, when I run the test I'm getting an error saying line 4 contains an unexpected ":" but my line 4 is my header script with the url?
I'm confused because I have other scripts similar to this and they don't give me that error. Can anyone tell me what I'm missing, might be simple, I have been caught being simple before.
<?php
if ($_REQUEST['Dish1'] == 'Dish1')
{
header(“Location: http://blahblah”.urlencode($_POST[‘uid’]));
}
else if ($_REQUEST['Dish1'] == 'Dish2')
{
header(“Location: http://blahblah2”.urlencode($_POST[‘uid’]));
}
else if ($_REQUEST['Dish1'] == 'Dish3')
{
header(“Location: http://blahblah3”.urlencode($_POST[‘uid’]));
}
etc.....
?>

You are using curly quotes.
Replace all the “ ” and ‘ ’ to " and ' respectively.

You are using the wrong quotes... use "" instead of “”. Refer to Wikipedia, you must use typewriter quotes, not curly or inverted commas.
PD: Also PHP Parse error: syntax error, unexpected '.' on line 15 ; )

Replace you code with following
<?php
if ($_REQUEST['Dish1'] == 'Dish1')
{
header("Location: http://blahblah.urlencode".($_POST['uid']));
}
else if ($_REQUEST['Dish1'] == 'Dish2')
{
header("Location: http://blahblah2".urlencode($_POST['uid']));
}
else if ($_REQUEST['Dish1'] == 'Dish3')
{
header("Location: http://blahblah3".urlencode($_POST['uid']));
}
?>

Is it not much easier to write:
$lookup = array('Dish1' = > 'http://blba1', 'Dish2' = > 'http://blba2');
if( isset($lookup[$_REQUEST['Dish1']]))
header("Location: " . $lookup[$_REQUEST['Dish1']]);

Related

mysql php - check if last variable is the same [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I tried to echo out the $rinse variable, I get nothing
But I do get one for the $rang['email'], any clues would be good
I also tried doing $rinse == $rang['email'];
while($rang = mysql_fetch_assoc($results))
{
if ($rang['email'] = $rinse){
echo $rang['email'];
}
$rinse = $rang['email'];
}
my code updated:
echo $rinse;
if ($rang['email'] == $rinse){
echo $rang['email'];
}
$rinse = $rang['email']
This is still not working for me
You need two = in your if statement.
if ($rang['email'] == $rinse){
You should add double ==. This is comparion, a single = means set to
while($rang = mysql_fetch_assoc($results))
{
if ($rang['email'] == $rinse){
echo $rang['email'];
}
$rinse = $rang['email'];
}

Php Loop While Condition = True [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have a php file which basically reads a page using JSON and a variable is returned to it (pending/paid/expired). now my simple requirement is if the returned variable is paid/expired the respective actions for them should be taken and the loop should not be repeated but if the response is pending the code should recheck after 10 seconds. A similar cycle then happens again and so on till the loop is stopped(by receiving either a expired/paid response.
here is the code i prepared for it using the examples i found at various places but this doesnt seem to work correctly.. pls guide..
while($end==0) {
$json = file_get_contents('http://old.kbourbaki.com/xlisteningpageprestashop.aspx?yyyyyyy');
$obj = json_decode($json);
$result=$obj->response;
echo($result);
if ($result=='paid') {
p('Order Successfull');
$end=1;
} elseif ($result=='expired' ) {
p('status = expired');
$end=1;//ex
} else {
d('status = Pending');
sleep(10);
}
}
CODE UPDATED extra '{' removed
You have one too many curly braces.
The proper elseif and else block should look like this
} elseif ($result=='expired' ) {
p('status = expired');
$end=1;//ex
} else {
It would help you a lot if you properly formatted your code.
You close the IF condition before the last ELSE just delete the closing clasp.
if($result=='paid'){
p('Order Successfull');
$end=1;
}else if($result=='expired'){
p('status = expired');
$end=1;//ex
}else{
d('status = Pending');
sleep(10);
}

PhP Error: FUNCTION [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
<?php
function me1($str) {
$hash = 'http://me1.wink.ws/me1/request.php?a=' . $str;
return $hash
}
$hi = me1('Hi');
?>
Where is my error?
Parse error: syntax error, unexpected '}' in /home/u727762781/public_html/client/me1.php on line 5
Fixed Code:
<?php
header('Content-Type: text/plain');
function me1($str) {
$hash = file_get_contents('http://me1.wink.ws/me1/request.php?a=' . $str);
return $hash;
}
$hi = me1('Hi');
echo $hi;
?>
You forgot the semi-colon at the end of the return statement.

Using PHP variable inside function [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I use the following code to get the full filename of a package using only the name of the app:
<?php
// define which app
$app = "appname";
// Search the directory for possible matches
foreach (glob("../../debs/com.dev.".$app."*") as $filename) {
preg_match('/\\d\\.\\d-\\d_.*\\.deb/', $filename, $matches);
$debname = "com.dev.".$app."_{$matches[0]}\n"; }
echo $debname;
?>
The filename of the package ($debname) is then shown correctly in the echo as: com.dev.appname_1.0-1_iphoneos-arm.deb
So i'm then trying to use this $debname variable to get the size of the file:
<?php function format_size($size) {
$sizes = array(" Bytes", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB");
if ($size == 0) { return('n/a'); } else {
return (round($size/pow(1024, ($i = floor(log($size, 1024)))), 2) . $sizes[$i]); }
}
echo format_size(filesize("../../debs/".$debname));
?>
For some weird reason the code is not showing the size and it shows n/a
If i set the debname variable manually to $debname = "com.dev.appname_1.0-1_iphoneos-arm.deb" it works fine and i get the file size..
I just can't figure out what's the problem
I tried using SESSION..
session_start();
$SESSION['debname'] = $debname;
...
...
echo format_size(filesize("../../debs/".$SESSION['debname']));
But same issue..
This line is wrong:
$debname = "com.dev.".$app."_{$matches[0]}\n";
^^ new-line character
Note that you are adding a new-line to the end of your string. You should remove that and confirm the correct name with a var_dump($debname); if necessary to make sure there are no white-spaces in between or at the end:
$debname = "com.dev.".$app."_{$matches[0]}";

php if empty string do something [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm having trouble making a empty string to have something inside, I'm also removing some other unnecessary characters from that string which works.
$desc = strip_tags($mapAnnotationArray);
$mapAnnotationArrayOutput = str_replace( array('"', '(' , ')'), '', $desc);
$mapAnnotationArrayOutput = trim($mapAnnotationArrayOutput);
if(empty($mapAnnotationArrayOutput)) {
($mapAnnotationArrayOutput == "empty");
}
Change this
($mapAnnotationArrayOutput == "empty");
To this
$mapAnnotationArrayOutput = "empty";
I've seen many people write:
if( x = "foo")
and wonder why it assigns "foo" to x... but never the other way around.
if( !$mapAnnotationArrayOutput) $mapAnnotationArrayOutput = "empty";
Try putting:
print("String is empty");
In the if statement, at the moment ($mapAnnotationArrayOutput == "empty"); will have no output so you wouldn't know if the string was empty or not.
If you're trying to assign the variable the value of "empty", use:
$mapAnnotationArrayOutput = "empty";
Instead.

Categories