0

By reading the contents of a binary file (image) to a $banner

$banner = addslashes (fread (fopen ( $mysql_banner, "r"),filesize($mysql_banner)))

You can then easily put it in a MySQL database table. It works perfect. But when you do a extra step by loading the contents of a binary file (image) to a associative array $final for later insertion from it into the database, a problem appears - that you can not insert it into the database table. Let's put the same content into associative $final

$final["banner"] = addslashes( fread( fopen( $mysql_banner,"r"), filesize($mysql_banner)

and decomposing it into components

 while ( list($name, $value) = each($final) )  {**
     $values_fields .= "$name, "; 
      $values .= "'$value', ";
}
$query1 = "INSERT INTO $banery ($values_fields) VALUES('$values')";
$res = mysql_db_query( $db, $query1)**

Although the original $banner and its copy a variable $value (taken from associative array $final) have the same content, (a binary content of image), only the original $banner can be inserted into database. When I try to insert $value, the following warning is displayed: "- CAN NOT insert into the database. MySQL Insert - Something wrong ..." (enigmatic hint) Why?enter code here

1

1 Answer 1

1

You never defined

$banery

therefor you can't insert into it.

You have to do something like

INSERT INTO table_name (...

But you're doing

INSERT INTO $table_name (...

Without defining what $table_name (in your case, $banery) is

Sign up to request clarification or add additional context in comments.

3 Comments

All needed variables are defined elswhere in the script and they work well. The problem is in retrieving data $value from associative $final. I put there good working $final["banner"] containg binary string and get back $value after the decomposition of $final, it contains the same binary string as stored original but it can be inserted. It is weird, maybe inside the "php is lost some pointer when apply the well-known syntax of "each decomposition.
To all GUYS to intrigue I say simplified: I put the coin into the box ($final) and I get back (list..=..equal) a coin which looks identical but the system doesn't accept it.
The script executes the insertion very good if the inserted values is precisely named the concrete variable. AFTER when the same value is extracted from the associative $final , a name of field and a name of value are generalized and I think this may be the reason that the same value is no 100% identical when read from the computer's memory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.