This is a discussion on newbie: Unknown column 'image' in 'field list' within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hey This php (version 5.20) code: $sql = "insert into Picture(Property, Mime, Data) values (1 , $type, \"".$...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hey
This php (version 5.20) code: $sql = "insert into Picture(Property, Mime, Data) values (1 , $type, \"".$image."\")"; Generate this sql (MySql5) error: Unknown column 'image' in 'field list' Any suggestions on how to solve this are very welcome! Jeff |
|
|||
|
Jeff <it_consultant1@hotmail.com.NOSPAM> wrote:
> Hey > > This php (version 5.20) code: > $sql = "insert into Picture(Property, Mime, Data) values (1 , $type, > \"".$image."\")"; > > Generate this sql (MySql5) error: > Unknown column 'image' in 'field list' > > Any suggestions on how to solve this are very welcome! Euhm, echo $sql if you please... -- Rik Wasmus |
|
|||
|
"Rik" <luiheidsgoeroe@hotmail.com> wrote in message news:op.tmseqrmtqnv3q9@misant.kabel.utwente.nl... Jeff <it_consultant1@hotmail.com.NOSPAM> wrote: > Hey > > This php (version 5.20) code: > $sql = "insert into Picture(Property, Mime, Data) values (1 , $type, > \"".$image."\")"; > > Generate this sql (MySql5) error: > Unknown column 'image' in 'field list' > > Any suggestions on how to solve this are very welcome! Euhm, echo $sql if you please... -- Rik Wasmus Here is the echo of $sql: insert into Picture(Property, Mime, Data) values (1 , image/pjpeg, "????\0JFIF\0\0\0d\0d\0\0??\0Ducky\0\0\0\0\0 F\0\0??\0Adobe\0d?\0\0\0??\0?\0 P???")Unknown column 'image' in 'field list' From $sql above I removed many characthers... it was very very many special characters like wich I removed in this post to make it more readable Any suggestions? Jeff |
|
|||
|
"Rik" <luiheidsgoeroe@hotmail.com> wrote in message
news:op.tmseqrmtqnv3q9@misant.kabel.utwente.nl... Jeff <it_consultant1@hotmail.com.NOSPAM> wrote: > Hey > > This php (version 5.20) code: > $sql = "insert into Picture(Property, Mime, Data) values (1 , $type, > \"".$image."\")"; > > Generate this sql (MySql5) error: > Unknown column 'image' in 'field list' > > Any suggestions on how to solve this are very welcome! Euhm, echo $sql if you please... -- Rik Wasmus I post my code below just in case somebody else needs it.... I'm happy to share :-) This code works, but I'm a newbie so maybe you see some potential problems with my code... for example now I didn't use any "\"" for to include the $image... I simply used '$image'... may this cause problem???.. I haven't had any problems yet.. I just ask just in case.... I replaced my original code with this code: if ($_FILES['userfile']['size'] > 0) { $type = $_FILES['userfile']['type']; $instr = fopen($_FILES['userfile']['tmp_name'], "r"); $image = fread($instr, $_FILES['userfile']['size']); $image = addslashes($image); fclose($instr); @ $db = new mysqli('localhost', 'xxxxxr', 'xxxxxxxx', 'fffffff4ffffffffffffff'); $sql = "insert into Picture(Property, Mime, Data) values (57, '$type', '$image')"; //57 is just test data, will be replaced my a variable $result = $db->query($sql); if (mysqli_errno($db)) { echo mysqli_error($db); } else { echo "OKAY"; } $db->close(); } |
|
|||
|
Jeff wrote:
> "Rik" <luiheidsgoeroe@hotmail.com> wrote in message > news:op.tmseqrmtqnv3q9@misant.kabel.utwente.nl... > Jeff <it_consultant1@hotmail.com.NOSPAM> wrote: > >> Hey >> >> This php (version 5.20) code: >> $sql = "insert into Picture(Property, Mime, Data) values (1 , $type, >> \"".$image."\")"; >> >> Generate this sql (MySql5) error: >> Unknown column 'image' in 'field list' >> >> Any suggestions on how to solve this are very welcome! > > Euhm, echo $sql if you please... Jeff, This is what I do: $allowedtypes = array('image/jpg','image/jpeg','image/pjpeg','image/gif','image/png','image/x-png'); if (in_array($_FILES["file_$choice"]['type'], $allowedtypes)) { // we have an image file - that's all we want. // good upload - process file (store in database) $upload = str_replace('\\','\\\\',$_FILES["file_$choice"]['tmp_name']); $atype = $_FILES["file_$choice"]['type']; $aname = $_FILES["file_$choice"]['name']; $asize = $_FILES["file_$choice"]['size']; $query = "INSERT INTO picture SET Property = 1, Mime = $atype, Data = LOAD_FILE('$upload')"; $result = mysql_query($query,$dbc); } --- Now this is a really hacked excerpt from my code but you should get the idea. There are alot of other things to check for (filesize != 0, etc. Norm |
|
|||
|
..oO(Jeff)
>This php (version 5.20) code: >$sql = "insert into Picture(Property, Mime, Data) values (1 , $type, >\"".$image."\")"; > >Generate this sql (MySql5) error: >Unknown column 'image' in 'field list' $sql = " INSERT INTO Picture (Property, Mime, Data) VALUES (1, '$type', '$image')"; Watch the quoting when inserting strings. Micha |