Error on Query with $_SESSION Var - php

$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.

Related

PHP Parse: Syntax Error with echo "\PDOStatement::errorInfo():\n

I am trying to create a page that will delete a row from a database but I keep getting syntax error and when I fix one I get a new error. For example, in the first code I tried re-typing the single quotation and it fixed the first error which was:
PHP Parse error: syntax error, unexpected ''];' (T_CONSTANT_ENCAPSED_STRING), expecting ']' in /banking_delete.php on line 11
The Code:
<?php
include_once 'banking_db.php';
include 'banking_display.php';
# form data
$customer_name=$_POST['customer_name'];
$sql = "delete from customer where customer_name = :customer_name;";
$stmt = $conn->prepare($sql);
# data stored in an associative array
$data = array ('customer_name' => $customer_name);
if($stmt->execute($data)){
$rows_affected = $stmt->rowCount();
echo "<h2>".$rows_affected." row deleted sucessfully!</h2>";
display("select customer_name as customer_name, customer_city as customer_city, customer_street as customer_street from customer;”);
} else
{
echo "\PDOStatement::errorInfo():\n";
print_r($stmt->errorInfo());
}
$stmt = null;
$conn = null;
?>
After that I got this new error:
PHP Parse error: syntax error, unexpected '\' (T_NS_SEPARATOR) in /banking_delete.php on line 16
When I changed echo "\PDOStatement::errorInfo():\n"; to echo "\nPDOStatement::errorInfo():\n"; I still get the same error message
You've got a ” instead of a " at the end of
display("select customer_name as customer_name, customer_city as customer_city, customer_street as customer_street from customer;”);

Laravel syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING

I have upload my files to a new server and error occurres in this line
if(empty($data['customer_id'])) -- Error in thisline
with message syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting '-' or identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)
the data is comming from
public function store(Request $request)
{
$data = $request->all();
if(empty($data['customer_id']))
$data['customer_id'] = Customer::create($data)->id;
If I change it to $data->customer_id it is not throwing error

How to fix "Unexpected T_ENCAPSED_AND_WHITESPACE" error in PHP? [duplicate]

This question already has an answer here:
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE) [duplicate]
(1 answer)
Closed 8 years ago.
Here is the error:
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\xampp\htdocs\new-training-site\config\info.php on line 4;
Here is line 4:
$link = mysql_query("SELECT * FROM users WHERE id='$_SESSION['MM_Username']' AND password='$_SESSION['MM_PASSWORD']'");
$link = mysql_query("SELECT * FROM users WHERE id='{$_SESSION['MM_Username']}' AND password='{$_SESSION['MM_PASSWORD']}'");
Try this one
$link = mysql_query(sprintf(
"SELECT * FROM users WHERE id='%s' AND password='%s'",
mysql_real_escape_string($_SESSION['MM_Username']),
mysql_real_escape_string($_SESSION['MM_PASSWORD']),
));
It will help you to avoid sql-injection. And please don't use mysql_ functions as it were mentioned in comments

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

PHP echo href issue

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']}?";

Categories