unexpected T_CONSTANT_ENCAPSED_STRING with quotes [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 9 years ago.
Improve this question
Can someone help me to find what is wrong in the $secret line ?
$secret should give :
{"name":"JustAname","extra":"1","password":"ASD123","report":"http:\/\/website.com\/dev\/gamereport\/0001.php"}
here's the PHP code:
<?php
date_default_timezone_set('America/Montreal');
$name = 'JustAname';
$extra = '1';
$password = 'ASD123';
$reception = 'http:\/\/website.com\/dev\/gamereport.php';
// Code de génération de la base64
$secret = '{"name":"'.$name'","extra":"'.$extra'","password":"'.$password'","report":"'.$reception'"}';
$encodedSecret = base64_encode($secret);
$tournementLink = 'pvpnet://lol/customgame/joinorcreate/map1/pick6/team5/specALL/'.$encodedSecret;
echo $tournementLink;
?>
I got: Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in [...] on line 20

You're incorrectly concatenating strings, as #hobbs suggests. You're also using the undefined variable $Tournament, which I think should be $name. Try this:
$secret = '{"name":"' . $name . '","extra":"' . $extra . '","password":"' . $password . '","report":"' . $reception . '"}';
On a side note, a slightly nicer way to create JSON in PHP is to use an array and json_encode():
$secret = json_encode(array(
'name' => $name,
'extra' => $extra,
'password' => $password,
'report' => $reception));

Related

PDO - Error with number of bound variables [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 3 years ago.
Improve this question
I have this error when I run the code:
Error:
Invalid parameter number: number of bound variables does not match number of tokens - Line: 106
Code:
$data_cadastro = date("Y-m-d G:i:s");
$query = "INSERT INTO FRETES (VENDA_CLIENTE_ID_CLIENTE, VENDA_ID_VENDA, DT_COLETA, DT_ENTREGA, LINK, TRANSPORTADORA, POSICAO, VALIDA, DT_CADASTRO)
VALUES (:id_cliente, :id_venda, ':dt_coleta', ':dt_entrega', ':link', ':transportadora', ':posicao', :validacao, ':dt_cadastro')";
$banco = $this->pdo->prepare($query);
try {
$banco->execute(
array(
':id_cliente' => $this->id_cliente,
':id_venda' => $this->id_venda,
':dt_coleta' => $dados['DTcoleta'],
':dt_entrega' => $dados['DTentrega'],
':link' => $dados['linkFrete'],
':transportadora' => $dados['transportadora'],
':posicao' => $dados['posicaoFrete'],
':validacao' => $dados['validacao'],
':dt_cadastro' => $data_cadastro
)
);
} catch (PDOException $exception) {
die("Execução da Query com erro (inserir novo frete): " . $exception->getMessage() . ' - Linha: ' . $exception->getLine());
}
Where i wrong?
Remove the quotes around the placeholders
$query = "INSERT INTO FRETES
(VENDA_CLIENTE_ID_CLIENTE, VENDA_ID_VENDA, DT_COLETA,
DT_ENTREGA, LINK, TRANSPORTADORA, POSICAO, VALIDA, DT_CADASTRO)
VALUES (:id_cliente, :id_venda, :dt_coleta, :dt_entrega, :link,
:transportadora, :posicao, :validacao, :dt_cadastro)";

PDOException: Query was empty [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 7 years ago.
Improve this question
I have a PDO PHP file making use of just one $_POST value stored on the $data array, and if an statement is true, a second value is added to that array to make a new query with two values:
<?php
session_start();
include("../conexionbbdd.php");
if($_SESSION['estado'] == 'activo' && $_SESSION['rol'] == '1'){
$data = array(
'us_id' => $_POST['us_id'],
);
$selectUsers= "SELECT * FROM ws_users WHERE us_id= :us_id";
$statementSelectUsers = $pdo->prepare($selectUsers);
$statementSelectUsers->execute($data);
$result = $statementSelectUsers->fetch(PDO::FETCH_ASSOC);
$us_fk_ui_id = $result['us_fk_ui_id'];
if($us_fk_ui_id==='1'){
$data['us_credits']=$_POST['us_credits'];
$updateUser = mysqli_query($con,"UPDATE ws_users SET us_credits = :us_credits, us_access = '1' WHERE us_id = :us_id");
$statementUpdateUser = $pdo->prepare($updateUser);
$statementUpdateUser->execute($data);
}
Everything goes fine untill the $statementUpdateUser->execute($data); line (34), where I get the usual error
PDOException: SQLSTATE[42000]: Syntax error or access violation: 1065
Query was empty in C:\wamp\www**********\actions\ad_updateUserInfo.php on
line 34
As far as I've seen, this should be due to the unexistance of one of the placeholders on the array, but if I print the array values after the $data['us_credits']=$_POST['us_credits']; it seems to be correct, having the 2 expected values needed for my query:
Array (
[0] => 2
[1] => 1.5 )
How could I check where the mistake is? There's no possibility of echoing the query as it is an object unable to transform on string.
$updateUser = mysqli_query($con,"UPDATE ws_users SET us_credits = :us_credits, us_access = '1' WHERE us_id = :us_id");
^^^ WTF??
You have to pay more attention to the code you write. Stack Overflow is NOT the service for finding typos for you.

Array to string conversion [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
There is an error in my code but the code works perfectly. I mean all the values are inserted in the database but there is an error like this on the screen:
Severity: Notice
Message: Array to string conversion
Filename: models/some_model.php
Line Number: 106
This is my code:
View:
<?php foreach($app as $row){
echo "<tr><td><input type=checkbox name=appname[] value='".$row->app_name."'/>".$row->id."</td><td>".$row->app_name."</td><tr>".
?>
Controller:
public function hide(){
$this->load->model('some_model');
$visi = $this->input->post('appname');
$success = $this->some_model->hideApp($visi);
foreach($visi as $key=>$value)
{
$success = $this->some_model->hideApp($visi[$key]);
}
if($success == TRUE)
$this->hideApp_page(TRUE);
else $this->hideApp_page(FALSE);
}
Model:
public function hideApp($visi){
$visi = $this->db->escape_str($visi);
$queryStr = "UPDATE appwarehouse.application_table SET visibility='hidden' where app_name='$visi';"; /* this is line 106*/
$query = $this->db->query($queryStr);
return $query;
}
$visi is array like [1,2,3,4]
when you put $visi in hideApp()
it will be display "array to string error"
so maybe you can remove this line $success = $this->some_model->hideApp($visi);
you have already do some_model->hideApp($visi[$key]) in the foreach loop
so i don't know why you write this$success = $this->some_model->hideApp($visi);
if you still want to run $success = $this->some_model->hideApp($visi);
you have to put $visi into a string

Parse error: syntax error, unexpected T_BOOLEAN_OR [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 new here and i'm an absolute beginner.
Please help with that error:
Parse error: syntax error, unexpected T_BOOLEAN_OR in index.php on line 174
First line is line 174
( $sql = || print mysql_error( ) );
if (0 < mysql_num_rows( $sql )) {
while ($row = mysql_fetch_assoc( $sql )) {
#extract( $row );
$numview = ($viewer == 1 ? 'view' : 'views');
$numvideo = ($counter == 1 ? 'video' : 'videos');
$chanlink = 'index.php?channels=browse&channel_id=' . $uid;
if (!empty( $img )) {
$show_images = '<img src="thumbs/channel/' . $img . '" width="' . $chan_img_width . '" height="' . $chan_img_height . '" border"0">';
}
else {
$show_images = '';
}
The error is pretty clear...
unexpected T_BOOLEAN_OR in index.php on line 174
This is line 174:
( $sql = || print mysql_error( ) );
This is a boolean OR:
||
You can't assign a boolean OR operator to a variable, so this doesn't make sense (let alone the rest of the line):
$sql = ||
The PHP parser doesn't expect things that don't make sense, so it throws an error.

Format DateTime 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 9 years ago.
Improve this question
I need to format Date time to specific date format using php.
Now date format
2014-02-10 09:32:24
I need format
2014/02/10
error is :Parse error: syntax error, unexpected '$ModifiedDate' (T_VARIABLE), expecting ',' or ';' in ................. line
Here i tried like this
<?php
include(config.php);
$sql = "SELECT Id,Title,description,Image,Category,ModifiedDate from News WHERE ISActive=true";
$query = mysql_query($sql);
if(mysql_num_rows($query)>0){
while($test = mysql_fetch_array($query))
{
$Mod = $test['ModifiedDate'];
$ModifiedDate = date_format($Mod, 'yyyy/MM/dd');
echo"<td><font color='black'>"$ModifiedDate"</font></td>";
}
}
else
{
echo "No Records";
}
?>
You forgot to concatenate the variable. Do like this
echo"<td><font color='black'>".$ModifiedDate."</font></td>";
//^----- ^----- Add those dots !
Use below format,
date_format($Mod, 'YY/MM/DD');
try this code:
$ModifiedDate = date_format($Mod, 'Y/m/d');

Categories