Asked  7 Months ago    Answers:  5   Viewed   34 times

i've been staringly blanky at this error and can't seem to know what the problem is.When i run the query i get this error:

unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING at this line:

$sqlupdate1 = "UPDATE table SET commodity_quantity=$qty WHERE user=$rows['user'] ";

 Answers

64

try this

echo $sqlupdate1 = "UPDATE table SET commodity_quantity=$qty WHERE user='".$rows['user']."' ";
Wednesday, March 31, 2021
 
osondoar
answered 7 Months ago
19

You are doing too much actually:

$query = $dbh->prepare("SELECT * FROM students");
$query->execute();
$result = $dbh->query($query);

The problematic line is:

$result = $dbh->query($query);

Check with http://php.net/pdo.query, the parameter is a string, actually the SQL string you already use above, not the result value of a PDO::prepare() call.

For your simple query you can just do:

$result = $dbh->query("SELECT * FROM students");

Or if you like to prepare:

$query = $dbh->prepare("SELECT * FROM students");
$query->execute();
$result = $query;

The later is some boilerplate if you want to insert variables into the query, that's why you prepare it.


The next problem is with the foreach line:

foreach($result as $row);

You are terminating the loop immediately because of the semicolon ; at the end. Remove that semicolon so that the following angle-bracketed code-block becomes the body of the foreach-loop.

Wednesday, March 31, 2021
 
anjan
answered 7 Months ago
69

Running on PHP4 by any chance? That's what the error message at this location would usually indicate.

Remove all public and private attributes. Though it's unlikely the plugin will work perfectly with the older object instance handling.

Saturday, May 29, 2021
 
madphp
answered 5 Months ago
37

There's no way to do exactly what you're trying to. You could do another query first to fetch all the column names, then process them in PHP and build the second query, but that's probably more complex than just writing out the names that you want.

Or is there a reason this query needs to be dynamic? Will the table's structure change often?

Monday, June 14, 2021
 
kinske
answered 5 Months ago
12

You can not put

$connection = sqlite_open("[path]/data/users.sqlite", 0666);

outside the class construction. You have to put that line inside a function or the constructor but you can not place it where you have now.

Monday, August 2, 2021
 
ttran4040
answered 3 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :