nade93 Posted December 16, 2009 Share Posted December 16, 2009 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!!! Link to comment https://forums.phpfreaks.com/topic/185331-few-questions-about-php-insert-into-and-check-if-exists/ Share on other sites More sharing options...
nade93 Posted December 16, 2009 Author Share Posted December 16, 2009 I think i have the coding for the image upload (will post it when everything works) however, I am still stuck on the checking to see if user id already exists if so error message can anyone help with this please? Link to comment https://forums.phpfreaks.com/topic/185331-few-questions-about-php-insert-into-and-check-if-exists/#findComment-978438 Share on other sites More sharing options...
trq Posted December 16, 2009 Share Posted December 16, 2009 owever, I am still stuck on the checking to see if user id already exists if so error message Execute a SELECT query to see if a users exists before proceeding. Link to comment https://forums.phpfreaks.com/topic/185331-few-questions-about-php-insert-into-and-check-if-exists/#findComment-978439 Share on other sites More sharing options...
nade93 Posted December 16, 2009 Author Share Posted December 16, 2009 sorry going to have to be more specific, (imagine the most basic of users) Link to comment https://forums.phpfreaks.com/topic/185331-few-questions-about-php-insert-into-and-check-if-exists/#findComment-978451 Share on other sites More sharing options...
nade93 Posted December 16, 2009 Author Share Posted December 16, 2009 sorry to bump, are you meaning running an if statement? i am sorry i am pretty new to all this and would be grateful for a little more information! Link to comment https://forums.phpfreaks.com/topic/185331-few-questions-about-php-insert-into-and-check-if-exists/#findComment-978547 Share on other sites More sharing options...
rajivgonsalves Posted December 16, 2009 Share Posted December 16, 2009 Yep first run a select statement to see if data exists in the table then if it does not exists insert Link to comment https://forums.phpfreaks.com/topic/185331-few-questions-about-php-insert-into-and-check-if-exists/#findComment-978550 Share on other sites More sharing options...
nade93 Posted December 16, 2009 Author Share Posted December 16, 2009 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"]); Link to comment https://forums.phpfreaks.com/topic/185331-few-questions-about-php-insert-into-and-check-if-exists/#findComment-978646 Share on other sites More sharing options...
nade93 Posted December 16, 2009 Author Share Posted December 16, 2009 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 Link to comment https://forums.phpfreaks.com/topic/185331-few-questions-about-php-insert-into-and-check-if-exists/#findComment-978649 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.