Hi, need help with inputing images to mysql. I read lots of previous thread about it but couldn't find the proper answer. this is code for my basic form:

<form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>" enctype="multipart/form-data">
       <table width="100%" border="1" cellspacing="1" cellpadding="1">
        <tr>
          <td>tytul</td>
          <td><label>
            <input type="text" name="tytul" id="tytul" />
          </label></td>
        </tr>
        <tr>
          <td>opis</td>
          <td><textarea name="opis" id="opis" cols="45" rows="5"></textarea></td>
        </tr>
        <tr>
          <td>telefon</td>
          <td><label>
            <input type="text" name="telefon" id="telefon" />
          </label></td>
        </tr>
        <tr>
          <td>email</td>
          <td><label>
            <input type="text" name="email" id="email" />
          </label></td>
        </tr>
        <tr>
          <td>image</td>
          <td><label>
            <input type="file" name="image" id="image" />
          </label></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td><label>
            <input type="submit" name="submit" id="submit" value="Wyƛlij" />
          </label></td>
        </tr>
      </table>
       <input type="hidden" name="MM_insert" value="form1" />
      </form>

this is my insert code:

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO oferujeP (tytul, opis, telefon, email, image) VALUES (%s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['tytul'], "text"),
                       GetSQLValueString($_POST['opis'], "text"),
                       GetSQLValueString($_POST['telefon'], "text"),
                       GetSQLValueString($_POST['email'], "text"),
                       GetSQLValueString($_POST['image'], "text"));

  mysql_select_db($database_hull, $hull);
  $Result1 = mysql_query($insertSQL, $hull) or die(mysql_error());

  $insertGoTo = "ogloszenia1.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));

and after submitting - "Column 'image' cannot be null" that column is set as BLOB what did i wrong? - plzzz HELP

Could you please post your create table statement so we may get a better understanding of your table structure

Also, are trying to store the image itself, or the url to the image?

image itself, table structure in mysql is just few varchars and binary blob for image plus id as AI primary key

image itself, table structure in mysql is just few varchars and binary blob for image plus id as AI primary key

Could you please post the full table structure in the CREATE TABLE format.

regards,
TC

I know it might not be what you were exactly looking for, but here is a good tutorial i found which details how to create an image upload with MySQL using BLOB type datatypes.

It seems to be very well documented so that following the instructions should not be a problem.

http://www.phpriot.com/articles/images-in-mysql/

oferujeP_id - int(11) auto_increment primary key,
tytul -	varchar(50) ,	 	 
opis - text,
telefon	- varchar(30)	, 	 	 	 	 	 
email - varchar(30),
image - blob BINARY 		 	 	 	 	 	 	 
 czas -	timestamp CURRENT_TIMESTAMP

I even alter image to VARCHAR(150) and error is the same then i add DEFALUT " " to it and the same

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.