Asked  2 Years ago    Answers:  5   Viewed   64 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

2

try this

echo $sqlupdate1 = "UPDATE table SET commodity_quantity=$qty WHERE user='".$rows['user']."' ";
Monday, October 31, 2022
3

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, November 23, 2022
5

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.

Monday, December 5, 2022
 
2

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?

Friday, December 2, 2022
 
2

The error message is pretty self-explanatory: your application needs the Oracle Client installed on the machine it's running on. Your development PC already has it. Make sure your target PC has it, too.

Edit: The System.Data.OracleClient namespace is deprecated. Make sure you use the driver native to your database system, that would be ODP.NET from Oracle.

Wednesday, August 3, 2022
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 

Browse Other Code Languages