
Originally Posted by
alexjewell
I have several fields that are being dropped into a mysql database. These are the fields:
Img, Title, Description, Size1, Size2, Medium, Year
image = the id given to the image?
title / description = one of those being alt one being title?
size 1 / size 2 = width and height?
medium = ???
year = ???
Img is a number and I want to check to see if it already exists in the table, and if it does to just replace those fields rather than add the information on? For example, if Img 37 already exists and all this information is submitted for 37, I want 37's information (already in the table) to be edited rather than a another row of information be added on, thus repeating 37 in the table when I'd like it to only appear once.
that is very confusing can you explain it more using a html example ? and remember to wrap your code in [code] tags
I also want to know if there's any particular way HTML should be handled with MySQL because Description will have HTML when submitted. I would like the HTML to be saved along with the field and I'm wondering if that causes any issues, like added backslashes and stuff.
you are talking about 2, no 3 different languages. PHP / MYSQL both have their special wildcards, so you really just need to add the appropriate modifications before evaluating with that languages... now on that note, unless you are inserting html as a whole into the database you could really create different fields in your image table and populate them with the values...
example
Code:
<img src="/images1.jpg" width="100" height="30" alt="This is the first Image" title="This is the first image">
in your image database table you could have
Code:
TABLE images
img_id
img_url
img_width
img_height
img_description
img_title
so you would check to see if the url exists in the table and if it does you would update the rest of the fields. if no you would create a new record putting the values of the fields in place
Code:
INSERT INTO images VALUES('','/image1.jpg',100,30,'This is the first Image','This is the first Image');
then when you are grabbing the information from php you would parse it soemthing like
PHP Code:
<?php
_connect_
$res = mysql_query("SELECT * FROM images WHERE img_id = '___'");
if( $row = mysql_fetch_array($res) )
{
?>
<img src="<?php echo $row['img_url']; ?>" width="<?php echo $row['img_width']; ?>" height="<?php echo $row['img_height']; ?>" alt="<?php echo $row['img_description']; ?>" title="<?php echo $row['img_title']; ?>">
<?php }
... rest of your code...
?>
which would be shown on the page back as
Code:
<img src="/images1.jpg" width="100" height="30" alt="This is the first Image" title="This is the first image">
Bookmarks