PHP echo href issue - php

I am trying to add a delete session option in my form, but I cannot get around the following error:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /users/bfullilo/acme_dl_sessions.php on line 31
Here is my line 31
echo " Not $_SESSION[\"email\"]?";
I know that I'm not escaping everything I need to, but I've hit a wall. Any help?

It's slightly faster to use single quotes
echo ' Not ' . $_SESSION["email"] . '?';

change to either:
echo " Not $_SESSION[email]?";
or
echo " Not {$_SESSION['email']}?";

Related

get variable from url give error

I am using this code to get the variable iduser to use it in php as part of another url ( line2). But it gives me the following error "Parse error: syntax error, unexpected T_VARIABLE in" can you please show me my mistake.
<?php
$iduser=$_GET['iduser'];
$currsiteurl = 'http://graph.facebook.com/'$iduser;
You have a syntax error.
$currsiteurl = 'http://graph.facebook.com/' . $iduser;
<?php
$iduser = $_GET['iduser'];
$currsiteurl = "http://graph.facebook.com/${iduser}";
?>
should work hope this helps.
you forgot the concatination . between string and variable:
$currsiteurl = 'http://graph.facebook.com/' . $iduser;
should work
Use this code
<?php
$iduser=$_GET['iduser'];
$currsiteurl = 'http://graph.facebook.com/'.$iduser;
?>
You have to use '.' to join string in php

getting T_ENCAPSED_AND_WHITESPACE error in PHP

I am creating an App in php
in which i am getting an error on this line #
$sql="INSERT INTO table ( `rollnum`,'sessionid', `class`, `subject`, `theory`, `practical`, `type_of`, `term`) VALUES ('$students['rollnum']', '$session','$class','$subject['id']','$_REQUEST[$subject['id'].'_'.$students['rollnum'].'_th']','$_REQUEST[$subject['id'].'_'.$students['rollnum'].'_pr']', '$examtype', '$examsubtype')";
I dont knoe what's wrong with this line.
i even checked at an online platform.They said the same that there is error on Line #(above).
Anyone who can help me with this
Thanks
you likely need to surround the variables in a double quoted string with braces.
$string = "I want to use {$variable1} and {$variable['thisKey']}";
or the following, which is a little faster to run;
$string = 'I want to use'.$variable1.'and '.$variable['thisKey'];
So that should solve your immediate problem, however your query is very open to an injection which can be very bad, especially if your using $_REQUEST right in your query string. I'd recommend looking into preparing your query statements before running them and ensuring all the dangerous stuff is escaped.
I answered another question that includes a safe way of doing a query over here with this answer
If your PHP environment had had these settings: display_errors = On; error_reporting = E_ALL, you would have seen:
PHP Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)
Like in this example:
$array['value'] = 'test';
echo "$array['value']";
It should be like that:
echo "".$array['value']."";
echo "{$array['value']}";
Anyway, you can use numeric keys:
$array[0] = 'test';
echo "$array[0]";
You need to surround your variable names with braces inside the string:
$sql="INSERT INTO stdexamrecord ( `rollnum`,'sessionid', `class`, `subject`, `theory`, `practical`, `type_of`, `term`) VALUES (
'${students['rollnum']}',
'$session',
'$class',
'${subject['id']}',
' " . $_REQUEST[ $subject['id'] . '_' . $students['rollnum'] . '_th'] . "',
' " . $_REQUEST[ $subject['id'] . '_' . $students['rollnum'] . '_pr'] . "',
'$examtype',
'$examsubtype')";
try to use dreamweaver or net bean that might help you to find the error at the correct place

Does anyone know what's wrong with mysql query?

define("QUERY","INSERT INTO rft_media_invention . " " (dbInventionFileType, dbStaffId, dbInventionFileName, dbInventionFileContent)" . "VALUES (?, ?, ?, ?)");
Its always giving me this error
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in p3t\phpappfolder\public_php\cw\UC213.php on line 20
anyone knows if my query is fully correct?
Syntax errors:
define("QUERY","INSERT INTO rft_media_invention . " " (dbIn etc...
^^^^^
should probably be
define("QUERY","INSERT INTO rft_media_invention " . " (dbIn etc...
which also begs the question of why you're concatenating the strings to begin with.
it looks like you need to transpose the first period and the quote that follows it:
...rft_media_invention . " "
should be
...rft_media_invention " . "
Try this: Your comma after rtf_media_invention should go after the double quotes, not before.
define("QUERY","INSERT INTO rft_media_invention " . "(dbInventionFileType, dbStaffId, dbInventionFileName, dbInventionFileContent)"

Why does my SQL string cause a "Error Message: Parse error: syntax error" in PHP?

This code keeps erroring.
Error Message: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/soulz/public_html/inbox.php on line 19
Here is the code:
mysql_query("UPDATE `messages` SET message_title = '[NO SUBJECT]' WHERE `message_id`=$row['message_id']");
Use curly braces:
mysql_query("UPDATE `messages` SET message_title = '[NO SUBJECT]'
WHERE `message_id`={$row['message_id']}");
Don't put apostrophes around the field name:
mysql_query("UPDATE `messages` SET message_title = '[NO SUBJECT]'
WHERE `message_id`=$row[message_id]");
^^^^^^^^^^
Inside quoted strings, you cannot use additional quotation marks for array field names. There's an alternative, more elaborate syntax involving braces if you have a very complicated array expression, but you don't need that here.
It seems message_id is integer, so you can fix that error with a best practice.
mysql_query("UPDATE `messages` SET message_title = '[NO SUBJECT]'
WHERE `message_id`=" . intval($row['message_id']));
You can use strval() for strings. Both functions are detailed in intval() manual page and strval() manual page.

Error on Query with $_SESSION Var

$sth7 = $pdo7->prepare("SELECT usr FROM tz_members WHERE id = $_SESSION['id'];");
is giving me this error:
syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
How do I fix this?
Try:
$sth7 = $pdo7->prepare("SELECT usr FROM tz_members WHERE id = " . $_SESSION['id'] . ";");
Here's a link to the exact same problem with a solution.

Categories