Parse error PHP file - php

I was moving my site and everything is working great except on one page I get the following error:
Parse error: syntax error, unexpected $end, expecting T_VARIABLE or T_DOLLAR_OPEN_CURLY_BRACES or T_CURLY_OPEN in domain/details.php on line 85
It was giving other errors that I manged to fix but this one I can not.
The following is lines 80-85 of the details.php page. Thats the end of the file.
Any help would be great
if(!class_exists('Snippets')) {
require_once dirname(__FILE__).'/snippets.class.php';
if(!class_exists('Snippets')) {
require_once dirname(__FILE__).'/snippets.class.php';
}
?>
===================
Add new:
Thanks. I treid all the above ways and it still gives error. Now it says line 84(which is last line here). This is what I changed it to:
if(!class_exists('Snippets')) {
require_once dirname(__FILE__).'/snippets.class.php';
}
?>
=========snippets=====
<?php
class Snippets {
function google_analytics() {
if(ANALYTICS === true) {?>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try{
var pageTracker = _gat._getTracker("<?php echo ANALYTICS_ID; ?>");
pageTracker._trackPageview();
} catch(err) {}
</script>
<?php }
}
function desktop() {
if(DESKTOP === true) {?>
<p class="bottomlinks"><span>Mobile</span> | <span>Desktop</span></p>
<?php }
}
function icon_call() {
if(CALL === true) {?>
<img src="images/icon_phone.gif" width="38" height="38" alt="Click to Call" />
<?php }
}
function icon_facebook() {
if(FACEBOOK === true) {?>
<img src="images/icon_facebook.gif" width="38" height="38" alt="Facebook" />
<?php }
}
function icon_map() {
if(MAP === true) {?>
<img src="images/icon_map.gif" width="38" height="38" alt="View a Map" />
<?php }
}
function icon_linkedin() {
if(LINKEDIN === true) {?>
<img src="images/icon_linkedin.gif" width="38" height="38" alt="Linked In" />
<?php }
}
function icon_twitter() {
if(TWITTER === true) {?>
<img src="images/icon_twitter.gif" width="38" height="38" alt="Twitter" />
<?php }
}
function slogan() {
if(SLOGAN === true) {?>
<p><?php echo SLOGAN_TEXT_LINE1; ?><br /><?php echo SLOGAN_TEXT_LINE2; ?></p>
<?php }
}
function click_to_call() {
if(CLICKTOCALL === true) {?>
<!-- Start Call Button -->
<div class="buttonclick"><?php echo BUTTON_TEXT; ?></div>
<!-- End Call Button -->
<?php
}
}
}
$snippets = new Snippets;
?>

You have two opening { and only one closing } brace in the sample code.

well you forgot to close the second culry brace.. :) Edit the contenct like this
require_once dirname(__FILE__).'/snippets.class.php';
if(!class_exists('Snippets')) // Removed the curly brace :)
require_once dirname(__FILE__).'/snippets.class.php';

You forgot to close a brace !!
if(!class_exists('Snippets')) {
require_once dirname(__FILE__).'/snippets.class.php';
if(!class_exists('Snippets')) {
require_once dirname(__FILE__).'/snippets.class.php';
}
}//<------------ Here
?>

Related

how to call jquery function externally in html

When we click on an anchor tag it should call the jquery function which is in external file but i don't know how to call a click function externally.
This is my code:
php
<html>
<head>
<script type="text/javascript" src="js/loc.js'">
</script>
</head>
<body>
<div id="locname">
<ul class="loct" >
<li >
<a href=# class="c" >Camp
</a>
</li>
</ul>
</div>
</body>
</html>
js file
$(document).ready( function() {
var $flag='0';
$(".c").on("click",function(event){
var $trigger = $(".c");
if($trigger !== event.target &&
!$trigger.has(event.target).length)
{
if($flag=='0')
{
$flag='1';
$(".co").fadeToggle("fast");
}
else if($flag=='1')
{
$flag='0';
$(".co").fadeToggle("fast");
}
}
});
}
}
Above code is working fine now
First of all, you do not need to wrap your JS code in <script></script> if your file's extension is .js
Solution: Update your JS file with the following code
var $flag='0';
function myFunction(event){
var $trigger = $(".c");
if($trigger !== event.target &&
!$trigger.has(event.target).length)
{
if($flag=='0')
{
$flag='1';
$(".co").fadeToggle("fast");
}
else if($flag=='1')
{
$flag='0';
$(".co").fadeToggle("fast");
}
}
};
Your anchor tag should be:
Camp
Also, since you're using jQuery, make sure you include jQuery library as well.
You can do like this
HTML file
<html>
<head>
<script type="text/javascript" src="<?php echo base_url('js/loc.js');?>">
</script>
</head>
<body>
<div id="locname">
<ul class="loct" >
<li >
<a href=# class="c" onclick= "externalFunction(this);">Camp
</a>
</li>
</ul>
</div>
</body>
</html>
JS file
<script type="text/javascript">
$(document).ready( function() {
var $flag='0';
function externalFunction(event){
var $trigger = $(".c");
if($trigger !== event.target &&
!$trigger.has(event.target).length)
{
if($flag=='0')
{
$flag='1';
$(".co").fadeToggle("fast");
}
else if($flag=='1')
{
$flag='0';
$(".co").fadeToggle("fast");
}
}
});
}
}
<script>
I thing it will help you.

Syntax error: end of file [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
It's saying,
Parse error: syntax error, unexpected end of file in
/mnt/sdcard/www/parts/background/editProfilePic_Process.php on line 96
Can't find the error.
Here is the code:
<?php
session_start();
$site="http://".$_SERVER["HTTP_HOST"]."/";
$root=$_SERVER["DOCUMENT_ROOT"];
if(substr($root,-1)!="/")
{
$root=$root."/";
}
if(!isset($_SESSION["u"]))
{
header("location:".$site."user");
exit;
}
else{
$u=$_SESSION["u"];
}
if(!isset($_POST["access"]))
{
echo "You cannot access this page";
exit;
}
?>
<!DOCTYPE html>
<html>
<head>
<?php
include($root."parts/resources.php");
?>
</head>
<body>
<?php
// header also contents the <noscript> alert
include($root."parts/header.php");
?>
<div class="wholepage">
<div class="page scatterList">
<?php
if(isset($_FILES["profilePic"]))
{
$name=$_FILES["profilePic"]["name"];
if($_FILES["profilePic"]["error"] !== UPLOAD_ERR_OK) {
die("Upload failed with error code ".$_FILES["profilePic"]["error"]);
}
if(!getimagesize($_FILES["profilePic"]["tmp_name"]))
{
exit;
}
$path=$site."img/1/".$u.".jpg";
move_uploaded_file($path, $_FILES["profilePic"]["tmp_name"]);
}
?>
</div> <!-- end of .page -->
</div> <!-- wholepage -->
<!-- FOOTER -->
<?php
include($root."parts/footer.php");
?>
</body>
</html>
What should I do to get rid of it?
You forgot to close a brace on your isset if loop. Try this code.
<?php
session_start();
$site="http://".$_SERVER["HTTP_HOST"]."/";
$root=$_SERVER["DOCUMENT_ROOT"];
if(substr($root,-1)!="/")
{
$root=$root."/";
}
if(!isset($_SESSION["u"]))
{
header("location:".$site."user");
exit;
}
else{
$u=$_SESSION["u"];
}
if(!isset($_POST["access"]))
{
echo "You cannot access this page";
exit;
}
?>
<!DOCTYPE html>
<html>
<head>
<?php
include($root."parts/resources.php");
?>
</head>
<body>
<?php
// header also contents the <noscript> alert
include($root."parts/header.php");
?>
<div class="wholepage">
<div class="page scatterList">
<?php
if(isset($_FILES["profilePic"]))
{
$name=$_FILES["profilePic"]["name"];
if($_FILES["profilePic"]["error"] !== UPLOAD_ERR_OK) {
die("Upload failed with error code ".$_FILES["profilePic"]["error"]);
}
if(!getimagesize($_FILES["profilePic"]["tmp_name"]))
{
exit;
}
$path=$site."img/1/".$u.".jpg";
move_uploaded_file($path, $_FILES["profilePic"]["tmp_name"]);
}
?>
</div> <!-- end of .page -->
</div> <!-- wholepage -->
<!-- FOOTER -->
<?php
include($root."parts/footer.php");
?>
</body>
</html>
Line 48: begin if
if (isset ($_FILES["profilePic"])) {
} End tag not exist.
Put } tag after move_uploaded_file line 57 or where you want.
Like this:
if (isset ($_FILES["profilePic"])) {
$name = $_FILES["profilePic"]["name"];
if ($_FILES["profilePic"]["error"] !== UPLOAD_ERR_OK) {
die("Upload failed with error code " . $_FILES["profilePic"]["error"]);
}
if (!getimagesize($_FILES["profilePic"]["tmp_name"])) { exit;}
$path = $site . "img/1/" . $u . ".jpg";
move_uploaded_file($path, $_FILES["profilePic"]["tmp_name"]);
}
you haven't close this block
if(isset($_FILES["profilePic"]))
{
You didn't finish one of you if statements.
Change:
if(isset($_FILES["profilePic"]))
{
$name=$_FILES["profilePic"]["name"];
to:
if(isset($_FILES["profilePic"]))
{
$name=$_FILES["profilePic"]["name"];
}
<?php
if(isset($_FILES["profilePic"]))
{
$name=$_FILES["profilePic"]["name"];
if($_FILES["profilePic"]["error"] !== UPLOAD_ERR_OK) {
die("Upload failed with error code ".$_FILES["profilePic"]["error"]);
}
if(!getimagesize($_FILES["profilePic"]["tmp_name"]))
{
exit;
}
$path=$site."img/1/".$u.".jpg";
move_uploaded_file($path, $_FILES["profilePic"]["tmp_name"]);
}// this one
?>
You never closed the first if statment..

Autoscroll to bottom then scroll manipulation

Hi I'm doing a chat script that I've gotten somewhere that needs quite modifications. The function I need to achieve is after successful loading of user to chat with the view should go to bottom directly. I have done things which failed on several occasions, it does automate to bottom but when I tried scrolling the content it still goes back to bottom which should not happen.
This is what I have so far.
<?php
$ctr = 0;
if (is_array($buddies)) {
foreach ($buddies as $buddy) {
?>
<span style="float: right;"><?php echo $buddy->unreadMsgCtr; ?></span>
<b><?php echo humanize($buddy->fullName) ?></b> <br />
<?php
++$ctr;
}
}
?>
<script type="text/javascript">
$(document).ready(function() {
<?php for ($ctrjs = 0; $ctrjs < $ctr; $ctrjs++) {?>
$('#friend' + <?php echo $ctrjs; ?>).live('click', function() {
$('#buddies').hide();
var chattingWith = $(this).attr('chattingID');
startrefresh();
$('#chatroom').show();
$('#chatmessage').html('<img src="<?php echo site_url('/images/ajax-loader.gif');?>" width="16" height="16" />');
$.post("<?php echo site_url('chats/chatbuddy');?>",{
username: $("#friend"+<?php echo $ctrjs; ?>).html(),
recipientID: chattingWith
});
});
<?php } ?>
});
</script>
//chats.php when a particular buddy has been clicked.
<script type="text/javascript">
var autoScrollEnabled = true;
$(document).ready(function() {
toggleAutoScroll();
if(autoScrollEnabled == true) {
$(".messages").animate({ scrollTop: $('.messages')[0].scrollHeight}, 1000);
//return false;
toggleAutoScroll();
}
function toggleAutoScroll() {
autoScrollEnabled = !autoScrollEnabled; //! reverses the value, true becomes false, false becomes true
if (autoScrollEnabled == true) { //scroll down immediately if a.s. is reenabled
$(".messages").animate({ scrollTop: $('.messages')[0].scrollHeight}, 9999999999);
}
}
$('#closechat').live('click', function() {
$('#chatroom').hide();
//scrolled = 0;
stoprefresh();
});
});
</script>
<div class="headerchat" style="width: 217px;"><div class="buddycontainer"> Chatting</div>
<div class="closecontainer">✖ </div>
<br class="breaker" />
</div>
<?php
if (is_array($chat)) {
foreach ($chat as $item){ ?>
<div class="conversation" style="width: 215px;">
<b><span class="username"><?php echo $item['username']; ?></span></b>
<span class="gray" style="float: right;" title="<?php echo date('M d, Y g:i A', $item['time']);?>"> <?php echo date('g:i A', $item['time']);?></span>
<br /><?php echo $item['message']; ?>
</div>
<?php } ?>
<?php }?>
BTW here is the jsfiddle I don't understand it's working properly in jsfiddle. http://jsfiddle.net/STQnH/3/
I'm not sure if I am heading on the right track. I just want to achieve that. Thank you guys.
Try wrapping your code in:
$(document).ready(function(){ //your code here
});
or
$( window ).load(function() {//your code here
});
If it works in jsFiddle but not on the live site this is likely what's missing. jsFiddle adds it for you. You can change this option in the drop down menu indicated by my freehand circle.
jQuery faq for $(document).ready()

showing or hiding div with id generated using php and javascript

I am trying to hide or show the div based on the div id from the php function. I am not able to make it work, please help me.
Javascript:
<script>
showOrHide(id) {
var elem=getElementById(id);
if(elem.style.visibility="hidden")
elem.style.visibility="visible";
else
elem.style.visibility="hidden";
}
</script>
PHP Script:
<?php
function display_link($link_id,$upvote_array,$downvote_array,$divid) {
?>
More links
<div id="<?php echo $divid ?>" style="visibility:hidden;">
</div>
<?php } ?>
Here's a cleaned-up version of your function.
function showOrHide(id) {
var elem = document.getElementById(id);
elem.style.visibility = (elem.style.visibility === 'hidden')? 'visible' : 'hidden';
}
<script>
function showOrHide(id){
var elem = getElementById(id);
if(elem.style.visibility=="hidden"){
elem.style.visibility="visible";
} else {
elem.style.visibility="hidden";
}
}
</script>
<?php
function display_link($link_id,$upvote_array,$downvote_array,$divid)
{
?>
More links
<div id="<?php echo $divid ?>" style="visibility:hidden;">
</div>
1 - visibility == 'hidden'
2 - missing ; after visibility="visible" and ="hidden"
3 - href="javascript:showOrHide('')" - missing '' inside your javascript function
Try this
<script>
function showOrHide(id){
var elem = document.getElementById(id);
elem.style.visibility = (elem.style.visibility === 'hidden')? 'visible' : 'hidden';
}
</script>
<?php
function display_link($link_id,$upvote_array,$downvote_array,$divid)
{
?>
More links
<div id="<?php echo $divid ?>" style="display:hidden;">
</div>
<?php
}
?>

document.friendform1.friends[i].checked not working when there is only one element in checkbox array

document.friendform1.friends[i].checked is not working when there is only one element in checkbox array. If there are more than one element in checkbox array than it is working fine
my html and php code is
$x=0;
foreach($result as $row)
{
if($x==0)
{?>
<div class="invite-friends-con">
<?php
}else{?>
<div class="invite-friends-con" style="margin-left:70px;">
<?php
}?>
<div class="invite-friends-con-img">
<img src="<?php echo base_url();?>Profile_images/<?php echo $row->vchPicture?>" width="48" height="39" align="absmiddle" />
</div>
<span><?php echo $row->vchFirstName?></span><input type="checkbox" name="friends[]" style="margin-top:10px" value="<?php if($row->intFriendID==$this->session->userdata('user_id')){ echo $row->intMemberID;}else{ echo $row->intFriendID;}?>" id="friends" />
<input type="hidden" name="frnd[]" id="frnd" value="<?php echo $row->vchFirstName?>" />
<?php if($x==1){$x=0;}else{$x++;}?>
<?php
} ?>
and javascript code is:
function addalfriend()
{
var str='';
var str1='';
var len=document.friendform1.friends.length;
for(i=0;i<len;i++)
{
if(document.friendform1.friends[i].checked==true)
{
if(str=='')
{
str=document.friendform1.friends[i].value;
str1=document.friendform1.frnd[i].value;
}
else
{
str=str+","+document.friendform1.friends[i].value;
str1=str1+","+document.friendform1.frnd[i].value;
}
}
}
document.getElementById('invite_1').value=str;
if(str!='' && str1!=''){
document.getElementById('invited').style.display="block";
}
else{
document.getElementById('invited').style.display="none";
}
document.getElementById('invited').value = str1;
document.getElementById("low-high-div").style.display="none";
document.getElementById("events-input-bg2").value="";
document.getElementById("events-input-bg3").value="";
closemessage1();
return false;
}
So please someone let me know my mistake.
Thanks
when there is one item return then array is not retuned element object is returned so you need to access it differently then
as
var len=document.friendform1.friends.length;
if(len>1)
for(i=0;i<len;i++)
{
if(document.friendform1.friends[i].checked==true)
{
if(str=='')
{
str=document.friendform1.friends[i].value;
str1=document.friendform1.frnd[i].value;
}
.
.
.
}
else
{
if(document.friendform1.friends.checked==true)
{
if(str=='')
{
str=document.friendform1.friends.value;
str1=document.friendform1.frnd.value;
}
}
.
.
.
}
You can try it simply like:
var len=document.friendform1['friends[]'].length || 1;
for(i=0;i<len;i++)
{
...
...
...
}
...
...
...
Read Why I can not get checkbox length while using it differently?

Categories