How to fix unexpected 'else' [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 5 years ago.
Improve this question
Good day! i'm trying to connect my php program to mysql local host. however i got an error saying
Parse error: syntax error, unexpected 'else' (T_ELSE) in C:\xampp\htdocs\loginpage\log.php on line 6
Here's my program:
<?php
$connect = new mysqli('localhost','root','','login');
if($Connect->connect_error);{
die('connectin failed bruh');
}else
echo('connect worked');
?>
I badly needed your help! Thanks!

If statement body is closed before you start it, you just need to remove semicolon to execute statement of the if condition the right code should be
if($Connect->connect_error){
............
.............
}

Related

PHP Inline If Syntax error [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 5 years ago.
Improve this question
I'm trying to make a inline if request.
Here the code
<?=(file_exits($storage.$file.'.md5')) ? file_get_contents($storage.$file.'.md5') : file_put_contents($storage.$file.'.md5', md5_file($storage.$file)?>
The log says
syntax error, unexpected '?>', expecting ',' or ')'
What's the problem?
You've missed a closing bracket ) in the end, just before the ?>
Here is a fixed code:
<?=(file_exits($storage.$file.'.md5')) ? file_get_contents($storage.$file.'.md5') : file_put_contents($storage.$file.'.md5', md5_file($storage.$file))?>

PHP: Parse error: syntax error, unexpected 'http' (T_STRING) in [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
Without getting into too much details on my project, I'm currently trying to use PHP to download a remote file and store it in the current directory on the server. Please keep in mind I do not know much of anything about PHP and am trying to learn.
I'm using the following code:
<?php file_get_contents(''http://xxx.xx.xx/file.php/'');?>
As you can see, this is pretty basic, and I'm not even really sure if it will get the job done.
Any help is greatly appreciated!
Try this:
<?php file_get_contents("http://xxx.xx.xx/file.php");?>

I don't know how to use real path in php [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 trying to use this code but it gives me an error :
// root path defined("ROOT_PATH")
|| define("ROOT_PATH", realpath(dirname(__ FILE__) . DS."..".DS));
this is the error:
Parse error: syntax error, unexpected 'FILE__' (T_STRING) in /opt/lampp/htdocs/op/inc/config.php on line 20
You have an extra space in __ FILE__ , It should be __FILE__.
Not sure if you did that just for formatting here.

SimpleXML PHP script not parsing properly [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
This PHP snippet isn't working:
<?php
$fille = simplexml_load_file("http://answers.yahooapis.com/AnswersService/V1/getQuestion?appid=dj0yJmk9OFRTTUI3NGdNNjREJmQ9WVdrOU5FZFBURzFqTkdNbWNHbzlNQS0tJnM9Y29uc3VtZXJzZWNyZXQmeD1iYg--&question_id=20080617101425AAmo159")
echo $fille->Question->Answers->Answer[0]->Content[0];
?>
Its purpose is to parse this XML file, and to get the first answer's contents.
http://answers.yahooapis.com/AnswersService/V1/getQuestion?appid=dj0yJmk9OFRTTUI3NGdNNjREJmQ9WVdrOU5FZFBURzFqTkdNbWNHbzlNQS0tJnM9Y29uc3VtZXJzZWNyZXQmeD1iYg--&question_id=20080617101425AAmo159
However, upon runtime I get this error:
Parse error: syntax error, unexpected T_ECHO in /home/content/76/10008776/html/trysearch.php on line 3
You forgot the ; at the end of your line.
<?php
$fille = simplexml_load_file("http://answers.yahooapis.com/AnswersService/V1/getQuestion?appid=dj0yJmk9OFRTTUI3NGdNNjREJmQ9WVdrOU5FZFBURzFqTkdNbWNHbzlNQS0tJnM9Y29uc3VtZXJzZWNyZXQmeD1iYg--&question_id=20080617101425AAmo159");
echo $fille->Question->Answers->Answer[0]->Content[0];
?>
More generally, when you face an error like Parse error: syntax error, unexpected XXX on line X, check what's right before the line in question, it's mostly because you forgot something :)

Unexpected T_String PHP Error [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 9 years ago.
Improve this question
I seem to be getting an unexpected T_STRING when I run this php code on my wordpress website. The goal is to have customised banners along the top of each post and the problem area appears to be the third line of the attached code...
<div id="header-middle">
<?php bannerAd('template-header'); ?>
<?php if ((get_post_meta("$post->ID", '_as_roomname', true)=='Party Casino') bannerad('party-casino'); ?>
</div>
You're missing a closing ) in the if statement

Categories