Jump to content

few questions about php INSERT INTO and check if exists


nade93

Recommended Posts

Hi All

 

I am working on some code and want to do some different things with it (please see code below)

 

What I want to be able to do:

1. Add directory to database

2. image1-6 should be converted to file paths and images inserted into directory (i.e. /directoryimages/)

3. before inserting into a directory, the code should check if the userid already exists in the form. If it does to return an error message

 

Can anyone give me some guidance please as its new terrritory for me!

 

INSERT INTO `directory` (`id`, `user_id`, `category`, `title`, `address`, `region`, `country`, `star_rating`, `website`, `email`, `telephone`, `short_desc`, `long_desc`, `image1`, `image2`, `image3`, `image4`, `image5`, `image6`, `latest_offers`, `payment`, `mainfeature`, `minifeature`, `meal_type`, `child`, `opening`) VALUES (`id`, `user_id`, `category`, `title`, `address`, `region`, `country`, `star_rating`, `website`, `email`, `telephone`, `short_desc`, `long_desc`, `image1`, `image2`, `image3`, `image4`, `image5`, `image6`, `latest_offers`, `payment`, `mainfeature`, `minifeature`, `meal_type`, `child`, `opening`)

 

Thanks in advance!!!

right pretty much got everything to work, however now i am trying to produce an if statement that will inset automatic image path in the mysql field if the field is left empty

 

the code below uploads the images into the databse and into a directory fine, however if the form field is left empty i want it to return /directory_images/noimage.jpg . Been fiddling round with if($image1=='') but not getting far at all

 

$image1 = '/directory_images/'.$_FILES["image1"]["name"];
move_uploaded_file($_FILES["image1"]["tmp_name"] , "$folder".$_FILES["image1"]["name"]);

by the way for people with a similar probel to check database find code i used below

 

$query = mysql_query("SELECT * from directory where user_id='$user_id'");
if(mysql_num_rows($query) != 0)
{
echo "You have already uploaded a listing. Please go to EDIT LISTING to amend your listing details";

} else {

 

thanks for the advise guys x ;)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.