html - Insert and retrieve image in php mysql -


whenever tried insert data image database, image not submitted or saved. gives [blob-0b] data (text) sucessfully saved.

external.php

class dbother {      private $host = 'localhost';     private $user = 'root';     private $password = '';     private $dbname = 'pcnl';     private $conn = '';      function connect() {         $this->conn = mysql_connect($this->host, $this->user, $this->password) or die (mysql_error());         mysql_select_db($this->dbname, $this->conn) or die(mysql_error());     }      function addevent($title, $place, $date, $people, $content, $eventimg, $eventext) {         $sql = "insert tbl_event values('$title', '$place', '$date', '$people', '$content', null, null, '$eventimg', '$eventext', null)";         mysql_query($sql) or die (mysql_error());         mysql_close();     }  } 

event.php

<?php require_once 'dbother.php'; $object = new dbother(); $object->connect(); if(isset($_post['title'])){             $title = $_post['title'];             $place = $_post['place'];             $date = $_post['date'];             $people = $_post['people'];             $content = $_post['content'];              $eventimg=file_get_contents($_files['pic']['tmp_name']);             $eventimg=mysql_escape_string($eventimg);              @list(, , $imtype, ) = getimagesize($_files['pic']['tmp_name']);              if ($imtype == 3){                 $eventext="png";              }elseif ($imtype == 2){                 $eventext="jpeg";             }elseif ($imtype == 1){                 $eventext="gif";             }              $object->addevent($title, $place, $date, $people, $content, $eventimg, $eventext);             header('location: events.php');             exit;             }     ?>         <div>         <h4>new event</h4>         <form name="eventform" id="eventform" method="post" action="events.php">         <p> title: <input type="text" name="title" id="title" required pattern="[a-za-z0-9 ,.)(*!?|<>:]{5,80}" title="please enter valid title of event."/></p>         <p> where:  <input type="text" name="place" id="place" required pattern="[a-za-z0-9 ,.)(*!?|<>:]{5,100}"/></p>         <p>when:  <input type="date" name="date" id="date" width="40px;" required /></p>         <p>people involved: <input type="text" name="people" id="people" required/></p>         <p>content:</p>         <textarea rows="4" cols="50" required name="content"></textarea>         <p><input type="file" name="pic" id="file" style="float:left">         <a href ="events.php"><input name="btnexit" type="button" id="btnexit" value="cancel" style="width:80px; height:30px; margin:5px; border:2px solid #757575; font-family:'trebuchet ms', arial, helvetica, sans-serif; float:right"></a>         <input name="btnfinish" type="submit" class="btnfinish" value="done" style="width:80px; height:30px; margin:5px; border:2px solid #757575; font-family:'trebuchet ms', arial, helvetica, sans-serif; float:right"></p>         </form> 

sorry long lines of codes, hope me.

first of all, recommend use folowing insert into syntax, in-which absolute determination of every column value:

insert table_name (column1, column2, column3, ...) values (value1, value2, value3, ...); 

second: form tag should has following attribute enctype="multipart/form-data", allow file uploading, form should like:

<form name="eventform" id="eventform" method="post" action="events.php" enctype="multipart/form-data"> 

the last thing have migrate mysql_ functions other commenters said. may checkout tag , @ question's answer know why: why shouldn't use mysql_* functions in php?


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -