This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
I am new to PHP, I got this syntax error but I can't figure it out
$pageid = $_GET['pageid'];
$sql = "SELECT article_id FROM page_content WHERE id='" .$pageid ."'";
$row = $conn->query($sql);
if ($row != false){
$result = $row->fetch();
$sql = "SELECT html_code from article WHERE id=" .$result['article_id'];
$row = $conn->query(&sql);
if ($row != false){
$result = $row->fetch();
echo $result['html_code'];
}
}
Result: Parse error: syntax error, unexpected ')', expecting '(' in the line 7.
Please help me, thank you.
You are using a & not a $ for the variable so change this:
$row = $conn->query(&sql);
to this:
$row = $conn->query($sql);
Related
This question already has answers here:
How can I access an object attribute that starts with a number?
(3 answers)
Closed 2 years ago.
I would like to get a value of my mysql table.
the column name has got numbers.
$temp= array();
$sql = "SELECT `00003A` FROM `table`";
$statement = $mysqli->prepare($sql);
$statement->execute();
$result = $statement->get_result();
while($row = $result->fetch_object()) {
temp[] = $row->00003A;
}
I get this error:
Parse error: syntax error, unexpected '00003' (T_LNUMBER), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' on line 19
This is line 19:
temp[] = $row->00003A;
You can try save this value in a variable like:
$prop = '00003A';
temp[] = $row->$prop;
Or get data with
temp[] = $row['00003A'];
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 3 years ago.
I'm adding [] this symbol within an execute() in PDO, and it returns error.
I'm working in WAMP5
$sqlStatement="
SELECT *
FROM $table_results
WHERE title = ? AND id_category = ?
";
$stmt = $bdConection->prepare($sqlStatement);
$stmt->execute([$title, $id_category]);
echo $stmt->rowCount();
It works well if I delete WHERE title = ? AND id_category = ? and [$title, $id_category] bur returns more results, instead of adding those ... then
IT RETURNS:
Parse error: syntax error, unexpected '[', expecting ')' in
I can reproduce this error with PHP 5.2. Documentation about PHP array's syntax states:
... As of PHP 5.4 you can also use the short array syntax, which
replaces array() with []. ...
What you can do in your case is to define an array using array():
<?php
$sqlStatement = "
SELECT *
FROM $table_results
WHERE title = ? AND id_category = ?
";
...
$stmt = $bdConection->prepare($sqlStatement);
$stmt->execute(array($title, $id_category));
echo $stmt->rowCount();
...
?>
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 6 years ago.
Hello, I'm very new to PHP and im getting this error...:
Parse error: syntax error, unexpected ''arak''
(T_CONSTANT_ENCAPSED_STRING) in /testSQL.php on line 6
...for this line:
$query = UPDATE 'arak' SET `ara` = '$ar1' Limit 0,1;
A little help would be appriciated :)
You have to quote the string by ", protect the table name by ` and protect value with '
$query = "UPDATE `arak` SET `ara` = '$ar1' Limit 0,1";
Be careful, $ar1 must be protected. For example, if $ar1 = '33\'33', you could have problem.
$ar1 = addslashes($ar1);
$query = "UPDATE `arak` SET `ara` = '$ar1' Limit 0,1";
Addslashes is a first step to prevent SQL Injection, but it is not enough as you can read it
This question already has an answer here:
Difference in accessing arrays in PHP 5.3 and 5.4 or some configuration mismatch?
(1 answer)
Closed 8 years ago.
Parse error: syntax error, unexpected '[', expecting ',' or ';' in /home/u844411171/public_html/index.php on line 8
I have a problem with mysqli_fetch_array(). I use mysqli_fetch_array():
if (isset($_SESSION["user_id"])) {
$query = "SELECT typ FROM `uzivatel` WHERE id = " . $_SESSION["user_id"];
$uzivatel = $mysqli->query($query);
$prava = mysqli_fetch_array($uzivatel)[0];
}
and
$celkemClenu = "SELECT count(`id`) FROM
`uzivatel`" or die("Error in the consult.." . mysqli_error($mysqli));
$result = $mysqli->query($celkemClenu);
echo "<p>Celkem členů: " . mysqli_fetch_array($result)[0];
Plz, where is a problem?
Your PHP is older than 5.4, which is when direct array dereferencing of function returns was added:
echo foo()[0]; // ok in 5.4, syntax error in older versions
Workaround, use a temporary variable to store the array:
$temp = foo();
echo $temp[0];
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 3 years ago.
How to get the date from database and echo on PHP page?
$query = $pdo->prepare('SELECT * FROM shop WHERE shopname=:shopname');
$query->bindParam(':shopname', $shopname, PDO::PARAM_STR);
$query->execute();
$result = $query->fetchAll(PDO::FETCH_ASSOC);
echo "$result['shopid']";
This gives me the following error:
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE),
expecting identifier (T_STRING) or variable (T_VARIABLE) or number
(T_NUM_STRING)
echo "$result['shopid']";
This line is incorrect
echo $result["shopid"];
// OR
echo "{$result['shopid']}";
remove the double quotes, change
echo "$result['shopid']";
with
echo $result['shopid'];