Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
How to Update blob image?... not working :s
Old 06-16-2008, 11:55 AM How to Update blob image?... not working :s
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Hey all,

Okay so i never bothered with BLOBs before and i been playing with them but one of the problems is it dont seem to update properly...

but adding is all fine

(edit script)
PHP Code:
<?php
$id 
$db->escape($_GET['id']);
$result $db->query("SELECT * FROM shop_products WHERE product_id='$id'") or $db->query_error();
$row $db->fetch_row($result);
if(isset(
$_POST['submit']))
{
$name $db->escape($_POST['name']);
$desc $db->escape($_POST['desc']);
$size $db->escape($_POST['size']);
$options $db->escape($_POST['options']);
$price $db->escape($_POST['price']);
$pnp $db->escape($_POST['pnp']);
$total_stock $db->escape($_POST['total_stock']);
$comment $db->escape($_POST['comment']);
$status $db->escape($_POST['status']);
if(
$_FILES)
{
$pic $db->escape(file_get_contents($_FILES['pic']['tmp_name']));
$pictype $_FILES['pic']['type'];
} else {
$pic $row['product_picblob'];
$pictype $row['product_pictype'];
}
$db->query("UPDATE shop_products SET 
product_name='
$name', product_desc='$desc', 
product_size='
$size', product_option='$options', 
product_price='
$price', product_pnp='$pnp',
product_picblob='
$pic', product_pictype='$pictype',
product_total_stock='
$total_stock', product_status='$status',
comment='
$comment' WHERE product_id='$id'") or $db->query_error();

echo 
'<div class="info_box">Product Changes Successfully Saved. <a href="javascript: history.go(-2)">Back</a></div>';
/*else {*/
?>
<div style="float:left">
<form action="" method="post">
<label class="label" for="name">Product Name: </label>
<input type="text" name="name" size="30" value="<?=$row['product_name']?>" /> <br />
<label class="label" for="desc">Description: </label> 
<textarea name="desc" cols="25" rows="5"><?=$row['product_desc']?></textarea> <br />
<label class="label" for="size">Size:</label>
<input type="text" name="size" value="<?=$row['product_size']?>" /><br />
<label class="label" for="options">Options: </label>
<input type="text" name="options" value="<?=$row['product_option']?>"  /> <br />
<label class="label" for="price">Price: </label>
<input type="text" size="4" name="price" value="<?=$row['product_price']?>" /><br />
<label class="label" for="pnp">P&amp;P: </label>
<input type="text" size="4" name="pnp" value="<?=$row['product_pnp']?>" /><br />
<label class="label" for="total_stock">Total Stock: </label>
<input type="text" size="4" name="total_stock" value="<?=$row['product_total_stock']?>" /><br />
<label class="label" for="pic">Picture: </label>
<input type="file" name="pic" /><br />
<label class="label" for="desc">Comment: </label> 
<textarea name="comment" cols="25" rows="5"><?=$row['comment']?></textarea> <br />
<br /><br />
<label class="label" for="status">Status: </label>
<select name="status">
<option value="1" <? if($row['status'] == '1'){echo 'selected="selected"';}?>>In Stock</option>
<option value="2" <? if($row['status'] == '2'){echo 'selected="selected"';}?>>Out of Stock</option>
<option value="3" <? if($row['status'] == '3'){echo 'selected="selected"';}?>>Unavalible</option>
<option value="4" <? if($row['status'] == '4'){echo 'selected="selected"';}?>>Discontinued</option>
</select>
<br />

<p class="submit">
<input type="submit" name="submit" value="Save" />
<input type="reset" name="reset" value="Reset" />
</p>
</form>
</div>
<div style="float:right; margin-top:150px">
<div class="info_box" style="width: 90%">
<h2 style="text-align:center">Info:</h2>
Current Picture: <img src="/modules/shop/product_pic.php?id=<?=$row['product_id']?>" style="height:200px" />
</div>
</div>
<?
#} // end else if post
Why dont it work :s

Dan
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
 
Register now for full access!
Old 06-16-2008, 01:10 PM Re: How to Update blob image?... not working :s
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
Try base64'ing it before it goes in (and decoding it on the way out). Also make sure that there is enough space in your database for it, for example it should be TEXT (600000) not VARCHAR (255)
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 06-16-2008, 01:25 PM Re: How to Update blob image?... not working :s
shivaji's Avatar
Ultra Talker

Posts: 321
Trades: 0
Your code is lookin good but I have the same problem ones before and I solve it with creating string before mysql query. For example (I will use only two of your column):

PHP Code:
$update"UPDATE shop_products SET product_name='" $name "', product_desc='" $desc "' WHERE product_id='" $id "'"
and query is:

PHP Code:
$db->query($update) or $db->query_error(); 
Shivaji
__________________

Please login or register to view this content. Registration is FREE
- uncommon free scripts

Please login or register to view this content. Registration is FREE
- Städte, Sport, Party, Gourment, Apartments, Hotels
shivaji is offline
Reply With Quote
View Public Profile Visit shivaji's homepage!
 
Old 06-16-2008, 08:17 PM Re: How to Update blob image?... not working :s
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Quote:
Originally Posted by rogem002 View Post
Try base64'ing it before it goes in (and decoding it on the way out). Also make sure that there is enough space in your database for it, for example it should be TEXT (600000) not VARCHAR (255)
The field type is BLOB... i will try changing it to longblob.. see if that works but i really dont think it is, when i add it first it works completely fine but when i use update and have the exact same script (accept the SQL is update not INSERT) but when it updates (dont show error) it just blanks the pic type and pic blob fields

I dont get it :S
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Reply     « Reply to How to Update blob image?... not working :s
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.78150 seconds with 12 queries