使用函数substr()后,我的查询无法更新到数据库中[关闭]

not sure why, after i'm using function substr() i cannot update my value to database, when i check in database no value(blank).

$result = '000603040000000000GL17KWJ10881011215000000000100';
$invoice = substr($result, 8, 20);  //output 0000000000GL17KWJ108

//update
$sql="UPDATE `order` SET invoice_pbb='$invoice' WHERE order_id=108";
$result=mysql_query($sql);  

if($result){
    echo "Successful";
}       
else {
    echo "ERROR";
}

column = invoice_pbb
type = varchar (100)

*if i change the value with hardcode , i can update(not sure why).

$invoice = '0000000000GL17KWJ108';

*i'm using https

Thank if you can help me.

Actually i cannot see an obvious error in your code, but i don't know the context and maybe this steps can help finding the error.

First i would not reuse the variable $result, instead use a new variable. This avoids misunderstandings, if some code could be not executed.

$queryResult = mysql_query($sql);

Then it is better to check the result correctly, because mysql_query() can return mixed types. Note the === operator, you cannot reliably check the result with a simple if statement.

if ($queryResult === false)
  echo "ERROR";
else
  echo "Successful";

Then i would turn error reporting on, this may give you a hint about the actual problem.

error_reporting(E_ALL);

Check what $invoice really contains before using it to do the query.

var_dump($invoice);

Edit:

Just one suggestion more, absolutely try to find another name for your table, using reserved words as tablename, is inviting trouble of all kind.

I think the above post was right. $sql="UPDATE order SET invoice_pbb='".$invoice."' WHERE order_id=108";

because variable name in single quotes will not render any value because it reads character by characer.

Or,

you can check datatype,lengths etc in database