Why I cant to retreive image from database via php?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • uzphpcoder
    New Member
    • Jun 2015
    • 1

    Why I cant to retreive image from database via php?

    This is my code. Could you correct? Thanks in advance
    Code:
    <?php
    echo <<<_END
    <DOCTYPE html><html><head><meta charset="utf-8"></head>
    _END;
    
    require_once'login.php';
    $connection=new mysqli($db_hostname, $db_username, $db_password, $db_database);
    
    if($connection->connect_error) die($connection->connect_error);
    
    if (
    	isset($_POST['title'])&&
    	isset($_POST['category'])&&
    	isset($_POST['name'])&&
    	isset($_POST['telno'])&&
    	isset($_POST['price'])&&
    	isset($_POST['info']))
    {
    	$title=get_post($connection, 'title');
    	$category=get_post($connection, 'category');
    	$name=get_post($connection,'name');
    	$telno=get_post($connection,'telno');
    	$price=get_post($connection,'price');
    	$info=get_post($connection,'info');
    	
    		if (is_uploaded_file($_FILES['img1']['tmp_name']))
    	{
    		
    				$imgData=addslashes(file_get_contents($_FILES['img1']['tmp_name']));
    					$query="INSERT INTO avto(title, category, img1,  name, telno, price, info) VALUES" . 
    					"('$title', '$category', '$imgData',  '$name', '$telno', '$price', '$info')";
    	
    				$result = $connection->query($query);
    	
    				if(!$result)
    					echo "Кушиб булмаяпти: $query<br>".
    					$connect_error. "<br><br>";
    		
    	}
    	
    
    }
    
    echo <<<_END
    	<form action="index.php" method="post" enctype="multipart/form-data"><pre>
    	Title <input type="text" name="title">
    	Category <input type="text" name="category">
    	Main img <input type='file' name='img1' >
    
    	Name <input type="text" name="name">
    	Tel NO <input type="text" name="telno">
    	Price <input type="text" name="price">
    	Info <textarea rows="6" cols="30" name="info"></textarea>
    	<input type="submit" value="Submit">
    	</pre></form>
    _END;
    
    
    $query="SELECT * FROM avto";
    $result=$connection->query($query);
    
    If (!$result) die ($connection->error);
    $rows=$result->num_rows;
    
    for ($j=0;$j<$rows;++$j)
    {
    $result->data_seek($j);
    $row=$result->fetch_array(MYSQLI_NUM);
    	
    	echo <<<_END
    		<pre>
    		$row[0]
    		$row[1]
    		$row[2]
    		$row[3]
    		$row[9]
    		$row[10]
    		$row[11]
    		$row[12]
    		$row[13]
    		</pre>
    _END;
    }
    $result->close();
    $connection->close();
    function get_post($connection, $var)
    {
    	return $connection->real_escape_string($_POST[$var]);
    }
    echo <<<_END
    </html>
    _END;
    ?>
  • computerfox
    Contributor
    • Mar 2010
    • 276

    #2
    Where did you find this code? This doesn't look like valid PHP code.

    Comment

    Working...