473,569 Members | 2,782 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

update mysql blob with another blob using php

Hi,

I have a blob field in a mysql database table. I want to copy a blob
from one record to another. I am having trouble transferring the data
via a php variable. Maybe I need to addslashes or convert to Hex or
something. I've tried a few things but can't quite get it. Here is
simplified code.

mysql_select_db ($dbname, $connection);

$query = "SELECT blobthing
FROM mytable
WHERE id = 1;";

$results = mysql_query ($query, $connection);
$row = (mysql_fetch_as soc($result));
$varblobthing = $row['blobthing']; //put the blob in a variable

$query = "UPDATE mytable
SET blobthing = ".$varblobthing .",
WHERE id = 2;";

mysql_query ($query, $connection);
I would love any advice I can get. Thanks in advance.
Simon

Sep 10 '05 #1
7 11446
sime said the following on 10/09/2005 18:36:
Hi,

I have a blob field in a mysql database table. I want to copy a blob
from one record to another. I am having trouble transferring the data
via a php variable. Maybe I need to addslashes or convert to Hex or
something. I've tried a few things but can't quite get it. Here is
simplified code.

mysql_select_db ($dbname, $connection);

$query = "SELECT blobthing
FROM mytable
WHERE id = 1;";

$results = mysql_query ($query, $connection);
$row = (mysql_fetch_as soc($result));
$varblobthing = $row['blobthing']; //put the blob in a variable

$query = "UPDATE mytable
SET blobthing = ".$varblobthing .",
WHERE id = 2;";

^
^
You forgot quotes
--
Oli
Sep 10 '05 #2
sime wrote:
mysql_select_db ($dbname, $connection);
mysql_select_db ($dbname, $connection)
or die ( 'Unable to select database.' );
$results = mysql_query ($query, $connection);
$results = mysql_query ($query, $connection)
or die ( 'Unable to execute query.' );
$row = (mysql_fetch_as soc($result));
$varblobthing = $row['blobthing']; //put the blob in a variable


$varblobthing = $row['blobthing']; //put the blob in a variable
mysql_free_resu lt($result);
....
Sep 10 '05 #3
sime wrote:
Hi,

I have a blob field in a mysql database table. I want to copy a blob
from one record to another. I am having trouble transferring the data
via a php variable. Maybe I need to addslashes or convert to Hex or
something. I've tried a few things but can't quite get it. Here is
simplified code.

mysql_select_db ($dbname, $connection);

$query = "SELECT blobthing
FROM mytable
WHERE id = 1;";

$results = mysql_query ($query, $connection);
$row = (mysql_fetch_as soc($result));
$varblobthing = $row['blobthing']; //put the blob in a variable

$query = "UPDATE mytable
SET blobthing = ".$varblobthing .",
WHERE id = 2;";

mysql_query ($query, $connection);
I would love any advice I can get. Thanks in advance.
Simon


Sime,

Three problems here. First of all, since $varblobthing is non-numeric,
you need to enclose it with "'" characters. Also, a blob can, by
definition, contain any character - including "special" ones like "'".
You need to use mysql_escape_st ring (or mysql_real_esca pe_string,
depending on your version of PHP and MySQL) to escape it.

Finally, get rid of the trailing ';' after the 2. You don't need a ';'
at the end of the SQL statement.

Try something like:

$query = "UPDATE mytable SET blobthing = '" .
mysql_escape_st ring($varblobth ing) .
"' WHERE id=2";

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Sep 10 '05 #4
Jerry Stuckle wrote:
sime wrote:
Hi,

I have a blob field in a mysql database table. I want to copy a blob
from one record to another. I am having trouble transferring the data
via a php variable. Maybe I need to addslashes or convert to Hex or
something. I've tried a few things but can't quite get it. Here is
simplified code.

mysql_select_db ($dbname, $connection);

$query = "SELECT blobthing
FROM mytable
WHERE id = 1;";

$results = mysql_query ($query, $connection);
$row = (mysql_fetch_as soc($result));
$varblobthing = $row['blobthing']; //put the blob in a variable

$query = "UPDATE mytable
SET blobthing = ".$varblobthing .",
WHERE id = 2;";

mysql_query ($query, $connection);
I would love any advice I can get. Thanks in advance.
Simon


Sime,

Three problems here. First of all, since $varblobthing is non-numeric,
you need to enclose it with "'" characters. Also, a blob can, by
definition, contain any character - including "special" ones like "'".
You need to use mysql_escape_st ring (or mysql_real_esca pe_string,
depending on your version of PHP and MySQL) to escape it.

Finally, get rid of the trailing ';' after the 2. You don't need a ';'
at the end of the SQL statement.

Try something like:

$query = "UPDATE mytable SET blobthing = '" .
mysql_escape_st ring($varblobth ing) .
"' WHERE id=2";


P.S. You should check the result of each mysql operation per the manual.
In this case I suspect the mysql_query is returning false and
checking the error with mysql_error() would give you information on why
it didn't work.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Sep 10 '05 #5
On 10 Sep 2005 10:36:06 -0700, "sime" <ge************ *@hotmail.com> wrote:
I have a blob field in a mysql database table. I want to copy a blob
from one record to another. I am having trouble transferring the data
via a php variable. Maybe I need to addslashes or convert to Hex or
something. I've tried a few things but can't quite get it. Here is
simplified code.

mysql_select_db ($dbname, $connection);
You've said you are "having trouble", yet you have not described what
"trouble" you're having, you've only posted some code.
mysql_query ($query, $connection);

I would love any advice I can get.
MySQL and PHP can give you advice for starters; make sure error_reporting is
set to E_ALL, and check the result code of every mysql_* call; if it returns
false, use mysql_error() to print a full error message.
$query = "UPDATE mytable
SET blobthing = ".$varblobthing .",
WHERE id = 2;";


You're missing quotes around the value, escaping using mysql_escape_st ring,
and what's that comma at the end of the second line for?
Or, an alternative approach:
(http://dev.mysql.com/doc/mysql/en/ex...variables.html)

mysql> create table t (id int, b blob);
Query OK, 0 rows affected (0.09 sec)

mysql> insert into t values (1, 'one');
Query OK, 1 row affected (0.06 sec)

mysql> select * from t;
+------+------+
| id | b |
+------+------+
| 1 | one |
| 2 | two |
+------+------+
2 rows in set (0.00 sec)

mysql> insert into t values (2, 'two');
Query OK, 1 row affected (0.00 sec)

mysql> select @b:=b from t where id=1;
+-------+
| @b:=b |
+-------+
| one |
+-------+
1 row in set (0.08 sec)

mysql> update t set b=@b where id=2;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from t;
+------+------+
| id | b |
+------+------+
| 1 | one |
| 2 | one |
+------+------+
2 rows in set (0.00 sec)

--
Andy Hassall :: an**@andyh.co.u k :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Sep 10 '05 #6
Jerry, you set me straight. mysql_escape_st ring() did the trick. I
had read about it at the mysql site but couldn't fathom it - especially
when they start talking about magic quotes.

Can I please apologise to you and other polite posters for the other
flaws in my sample. This is the poor form of a php newbie.

Many Thanks, Simon

Sep 11 '05 #7
sime wrote:
Jerry, you set me straight. mysql_escape_st ring() did the trick. I
had read about it at the mysql site but couldn't fathom it - especially
when they start talking about magic quotes.

Can I please apologise to you and other polite posters for the other
flaws in my sample. This is the poor form of a php newbie.

Many Thanks, Simon


No problem, Glad to help.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Sep 11 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
43427
by: barmaley | last post by:
how do I allow access to mySQL from another computer on local network? when I am trying to connect from MySQL Studio on Windows XP, I get error "Host '192.168.0.100' is not allowed to connect to this MySQL server"
4
3261
by: James E Koehler | last post by:
I can't get the WHILE statement to work in MySQL. The version of MySQL that I am using is: Ver 12.16 Distrib 4.0.6-gamma, for Win95/Win98 (i32) running on Windows MX. Here is the relevant section from the manual: 20.1.9.7 WHILE Statement
4
3160
by: whitemoss | last post by:
Hi, I've made some changes to my coding..but unfortunately, there were errors when compiling it..dunno how to solve it..hope anyone can help me...the errors: client.c: In function senddata: client.c:147: error: incompatible implicit declaration of function UpdateStatus client.c:37: error: previous implicit declaration of UpdateStatus was...
4
2155
by: geof | last post by:
Hi ! this is my first post where is my error code in line 15 ($sql ) <html> <head><title> update MySQL Data </title></head> <body bgcolor="#FFFFFF"> <?
1
2105
by: shaji66 | last post by:
how to update values in HTML page using java script: hi all , I want to update some text fields in html , and display these values in another page .... can you please help me in writing java script can you please post code for it or give me perticular sites that can help me... thank you in advance...
3
9306
by: ma | last post by:
Hello, I have two update Panel in my page. I want to update one of these update panels from another one. How can I do this? How can I force the whole page to be updated from a button inside an update panel? Regards
11
4259
by: OllyJ | last post by:
Hi experts, I'm hoping you can help me with this.. I have recently found out how to use the INSERT INTO statement to add multiple records from a listbox to a table, I now need to UPDATE records in another table using a multi-select listbox. Problem: I want to present a template of working hours of staff by showing 48 x 30minute intervals,...
1
1486
by: krishemanth | last post by:
sir, I want to update a value in dropdown using ajax i had a listing of some categories in dropdown along with that i had an add category in that dropdown box when select that addcategory option It opens a popup and add a new category and while submitting it popup closes and it automatically appends that value in drop down using ajax can...
0
2194
by: Serenityquinn15 | last post by:
Hi! I have two Table names: tblupdate tblDetails What i want to do is to update the table tblupdate from tblDetails using the button in Visual basic Interface.
11
3604
donilourdu
by: donilourdu | last post by:
hi, I am trying to retrive data from MYSQL database.I am using limit to fetch the data.It will fetch two rows instead of fetching ten rows.But when i try to debug it fetches eight rows instead of ten rows.The codes are given below for your reference. private void data(string slimit,string elimit) { MySqlConnection conn = new...
0
7697
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8120
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7672
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7968
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5512
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.