Page 1 of 1

upload binary data to mysql

Posted: Mon Sep 06, 2004 2:44 pm
by cmetzke
feyd | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Hi all,
Im trying to create a form that will upload it data to a mysql database, all works except when i try to upload a picture as well and i could really use some help. when i check phpmyadmin to see the results all the results are there but in the blob field i get [BLOB - 0 Bytes]

sql:

Code: Select all

CREATE TABLE `messages` (
  `id` int(11) NOT NULL auto_increment,
  `time` timestamp(14) NOT NULL,
  `name` varchar(30) NOT NULL default '',
  `message` text NOT NULL,
  `file` longblob NOT NULL,
  PRIMARY KEY  (`id`)
) TYPE=MyISAM AUTO_INCREMENT=5 ;
html:

Code: Select all

<form action="amb.php" method="post" enctype="multipart/form-data" name="form1">
  <table width="38%" border="2" align="center" cellpadding="2" cellspacing="2" bordercolor="#999999">
    <tr> 
      <td width="80%"><input type="text" name="name"> </td>
      <td width="20%">Name</td>
    </tr>
    <tr> 
      <td><textarea name="message" cols="30" rows="5"></textarea></td>
      <td>Message</td>
    </tr>
    <tr> 
      <td><input type="file" name="file"></td>
      <td>Upload</td>
    </tr>
    <tr> 
      <td><input type="submit" name="Submit" value="Submit"></td>
      <td> </td>
    </tr>
  </table>
</form>

Code: Select all

<?php
$db = mysql_connect("localhost","username","cam"); 
mysql_select_db ("database"); 
$query = "INSERT INTO messages(name, message, file) 
VALUES('".$_POSTї'name']."','".$_POSTї'message']."','".$_POSTї'file']."')"; 
$result = mysql_query($query); 
echo 'Information entered.'; 
?>
Any help would be very much appreciated :D


feyd | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Mon Sep 06, 2004 2:54 pm
by anjanesh

Posted: Mon Sep 06, 2004 11:31 pm
by cmetzke
Thanks for that Anjanesh but it doesnt seem to work for me. any chance its how php is setup on my server?

Posted: Tue Sep 07, 2004 12:40 am
by cmetzke
This is really starting to do my head in here. Anyone lend a hand? or a tip ?

Posted: Tue Sep 07, 2004 12:54 am
by feyd
be patient. Some of us have lives outside of lurking the forums.

did you check the $_FILES variable?