View Full Version : BLOB/TEXT prob
Hi guys, im really a newbie when it comes to PHP/SQL, i was about to try using BLOBS for storing URL`s for images, but i ran into errors straight away, table info as follows:
CREATE TABLE `members` (
`name` TEXT,
`games` VARCHAR( 100 ) ,
`age` BIGINT( 3 ) ,
`email` VARCHAR( 200 ) ,
`gender` TEXT,
`country` VARCHAR( 100 ) ,
PRIMARY KEY ( `name` )
)
MySQL said: Documentation
#1170 - BLOB/TEXT column 'name' used in key specification without a key length
altho for the name field i have length 20 and for gender i put in 10, i have messed around with this and no matter what i put in for length i get the same msg, any info would be appreciated...
( is it ok for name to be primary key as i dont want 2 use `id` i wanni be able 2 search by name..
thx in advance..
mitchind
3-27-05, 05:45 PM
Well for starters - you don't need BLOB fields to store URLs - just use a varchar.
As for creating the table, if you don't have much SQL experience, you'll find it a lot less painful process if you use phpMyAdmin to build your table - much easier with drop down options.
You can always see the SQL afterwards if you want to learn what the syntax looks like.
thx for the info but i am using PhpmyAdmin, and its just givin me those errors all the time...
ianmkerr
3-28-05, 05:24 AM
The MySQL manual implies that it is not a good idea to use BLOBs as the primary key - many other database systems do not permit this either.
Therefore, the simple answer to your problem is to either change the 'name' field to a varchar type or to use another field to hold the primary key and create an index on the 'name' field for searching purposes.
RTH10260
3-28-05, 08:04 AM
Hi guys, im really a newbie when it comes to PHP/SQL, i was about to try using BLOBS for storing URL`s for images, ..
- BLOBS are 'large Binary Objects, and are intended to store the image file itself (or similar unstructured content), not an URL to an image file.
- TEXT is a synonym for a BLOB and for both you need to sepcify which maximum size the text could become:
The four TEXT types, TINYTEXT, TEXT, MEDIUMTEXT, and LONGTEXT, correspond to the four BLOB types and have the same maximum lengths and storage requirements.
- The manual specifies for TEXT or BLOB: For indexes on BLOB and TEXT columns, you must specify an index prefix length.
As already mentioned by another poster, use a CHAR or VARCHAR, with size; an URL is not huge. Sample of TEXT usage would be to store email content or news articles, or message content on a forum.
thx fellas thats great, i will mess about with this tonight after i get home from work..
thx again for the replys..
ok guys i can get my database set up, so in the fields i want to store image paths i put:
/images/image1.gif
but in the calling file all it does is display the image paths, so im kinda stumped as what to do...
any help wud be much appreciated,, thx in advance
mitchind
3-31-05, 11:40 AM
Not much to work with - maybe you could include your code?
Instead of echoing the image field you need to wrap it in a <img src="$image"> tag
where $image = $row["my_image_field_name"];
RTH10260
3-31-05, 02:46 PM
ok guys i can get my database set up, so in the fields i want to store image paths i put:
/images/image1.gif
but in the calling file all it does is display the image paths, so im kinda stumped as what to do...From your description it seems to me, that you only pull a name from the database and put the name into the webpage, rather than generating the full IMG element required in HTML.echo '<img src="http://www.yourdomain.tld' . $pathfromdb . '">';
vBulletin v3.6.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.