我正在做一个注册表单,我也将图像保存到数据库,以及图像以LONGBLOB格式存储。我能够添加和查看接受图像部分的所有数据。
这是我的product_register.php
代码:
<form role="form" method="post" action="product_register.php">
<fieldset>
<div class="form-group">
<input class="form-control" placeholder="Product Name" name="product_name" type="text" autofocus>
</div>
<div class="form-group">
<input class="form-control" placeholder="Product Code" name="product_code" type="text" autofocus>
</div>
<div class="form-group">
<input class="form-control" placeholder="Product Image" name="product_image" type="file" value="">
</div>
<div class="form-group">
<input class="form-control" placeholder="Purchase Date" name="date" type="date" autofocus>
</div>
<div class="form-group">
<input class="form-control" placeholder="Time Guarantee" name="time_guarantee" type="text" autofocus>
</div>
<input class="btn btn-lg btn-success btn-block" type="submit" value="submit" name="submit" >
</fieldset>
</form>
<?php
include("db_conection.php");//make connection here
//mysql_close();
if(isset($_POST['submit']))
{
$usern = $_SESSION['sess_username'];
$product_name = $_POST['product_name'];
$product_code = $_POST['product_code'];
$product_image = $_POS['product_image'];
$date = $_POST['date'];
$time_guarantee = $_POST['time_guarantee'];
$insert_user = "insert into product (product_name,product_code,product_image,date,time_guarantee,usern) VALUE ('$product_name','$product_code','$product_image','$date','$time_guarantee','$usern')";
if(mysqli_query($dbcon,$insert_user))
// $result = mysql_query($insert_user);
{
echo "<script type='text/javascript'>alert('Product added successfully !!!')</script>";
// echo"<script>window.open('product_register.php','_self')</script>";
// mysql_close();
}
}
?>
以下是查看view_product.php
代码的代码:
<table class="table table-bordered table-hover table-striped" style="table-layout: fixed">
<thead>
<tr>
<!-- <th>User Id</th> -->
<th>Product Name</th>
<th>Product Code</th>
<th>Product Image</th>
<th>Date of Purchase</th>
<th>Time Guarantee</th>
<!-- <th>Delete User</th> -->
</tr>
</thead>
<?php
mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("gmgmt") or die(mysql_error());
// $view_users_query="select * from users WHERE role='user'"; //select query for viewing users.
// $view_users_query="select * from users WHERE role='admin'"; //select query for viewing users.
$view_users_query="select * from 'product' WHERE 'usern' = 'demo'"; //select query for viewing users.
// $run=mysql_query($view_users_query);//here run the sql query. // '".$_SESSION['userid']."'
$check = mysql_query("SELECT * FROM product WHERE usern = '".$_SESSION['sess_username']."' ") or die(mysql_error());
while($row=mysql_fetch_array($check)) //while look to fetch the result and store in a array $row.
{
$id=$row[0];
$product_name=$row[1];
$product_code=$row[2];
$product_image=$row[3];
$date=$row[4];
$time_guarantee=$row[5];
// $usern=$row[6];
?>
<tr>
<!--here showing results in the table -->
<!-- <td><?php echo $id; ?></td> -->
<td><?php echo $product_name; ?></td>
<td><?php echo $product_code; ?></td>
<td><?php echo "<img src='php/imgView.php?imgId=".$product_image."' />"; ?></td>
<td><?php echo $date; ?></td>
<td><?php echo $time_guarantee; ?></td>
<!-- <td><a href="delete.php?del=<?php echo $id ?>"><button class="btn btn-danger">Delete</button></a></td> -->
</tr>
<?php } ?>
</table>
我搜索了很多,但我没有找到适合我需要的代码或方法。
答案 0 :(得分:0)
echo '<img src="data:image/jpeg;base64,' . base64_encode( $row['imageContent'] ) . '" />';
使用上面的代码在mysql数据库中显示图像存储。希望这会对你有所帮助