Jump to content

fife

Members
  • Posts

    381
  • Joined

  • Last visited

Everything posted by fife

  1. Ok I have this form with 6 fields that the user enters a geocaching code. In the database I have a table called cacheinfo. There are 6 enteries in the database in this table. Now Im trying to confirm that each field entered matches the right geo code. I have it working but I feel that its a very bad way of doing it my way. can someone please show me a better way as I have other situations I do something simliar and its just getting silly. Here is the code; if(isset($_POST['nextbtn'])){ $cache1 = trim($_POST['cache1']); $cache2 = trim($_POST['cache2']); $cache3 = trim($_POST['cache3']); $cache4 = trim($_POST['cache4']); $cache5 = trim($_POST['cache5']); $cache6 = trim($_POST['cache6']); $cache1 = mysql_real_escape_string($cache1); $cache2 = mysql_real_escape_string($cache2); $cache3 = mysql_real_escape_string($cache3); $cache4 = mysql_real_escape_string($cache4); $cache5 = mysql_real_escape_string($cache5); $cache6 = mysql_real_escape_string($cache6); $FetchCache = mysql_query("SELECT * FROM cacheInfo WHERE cacheInfoID='1'") or die('can not find cache information'); $cache1 = mysql_fetch_array($FetchCache); if($cache1 !==$cache1['cacheCode']){ $url = "/register-cache.php?error=true"; header("Location: $url"); } $FetchCache = mysql_query("SELECT * FROM cacheInfo WHERE cacheInfoID='2'") or die('can not find cache information'); $cache2 = mysql_fetch_array($FetchCache); if($cache2 !==$cache2['cacheCode']){ $url = "/register-cache.php?error=true"; header("Location: $url"); } $FetchCache = mysql_query("SELECT * FROM cacheInfo WHERE cacheInfoID='3'") or die('can not find cache information'); $cache3 = mysql_fetch_array($FetchCache); if($cache3 !==$cache3['cacheCode']){ $url = "/register-cache.php?error=true"; header("Location: $url"); } $FetchCache = mysql_query("SELECT * FROM cacheInfo WHERE cacheInfoID='4'") or die('can not find cache information'); $cache4 = mysql_fetch_array($FetchCache); if($cache4 !==$cache4['cacheCode']){ $url = "/register-cache.php?error=true"; header("Location: $url"); } $FetchCache = mysql_query("SELECT * FROM cacheInfo WHERE cacheInfoID='5'") or die('can not find cache information'); $cache5 = mysql_fetch_array($FetchCache); if($cache5 !==$cache5['cacheCode']){ $url = "/register-cache.php?error=true"; header("Location: $url"); } $FetchCache = mysql_query("SELECT * FROM cacheInfo WHERE cacheInfoID='6'") or die('can not find cache information'); $cache6 = mysql_fetch_array($FetchCache); if($cache6 !==$cache6['cacheCode']){ $url = "/register-cache.php?error=true"; header("Location: $url"); } // If all match now run the rest of my code...... }
  2. Guys thank you very much for your help and both your solutions work nicely.
  3. Hi all. I have this code. <?php $ext = ' <form action="/members/clubs/view-activity.php" method="post" name="venuefrm"> <button type="submit" id="close" class="link"><span>View Activity</span></button> <input name="activity" type="hidden" value="<?php echo $activites['activityID']; ?>" /> </form>'; ?> The code falls down at the value="<?php echo $activites['activityID']; ?>" part. Can someone please show me how I break into php to write this part properly as I dont understand an it is obviously wrong. Thanks Danny
  4. thanks matey that works perfectly!!!!!!!!!!!!!!
  5. Hi. I am try to implement a go dynamic google maps feature into my website. If i put a static address into my code it works great. If then I use a variable it all goes wrong. Here is the line Im having trouble with. $address = ' address'; $address = urlencode($address); //so here is the static version that works great!!!!!!!!!!!!!!!!!!! $address = ' 45 chapel road, preston, lancashire, pr4 6rt, uk'; $address = urlencode($address); // and a version that does not work. $address = '$addressL1, $area, $county, $postcode, $country'; $address = urlencode($address); // another that does not work $address = ' {$addressL1}, {$area}, {$county}, {$postcode}, {$country}'; $address = urlencode($address); If I view the source code when i load the page in the browser its obvious why the code is not working. See below. <iframe width="193px" height="160px" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=+%24addressL1%2C+%24area%2C+%24county%2C+%24postcode&aq=0&ie=UTF8&hq=&hnear=+%24addressL1%2C+%24area%2C+%24county%2C+%24postcode&t=m&ll=,&z=12&iwloc= &output=embed"></iframe> As you can see the variable's are echoing wrong. Can someone please tell me how to write them within the string so they output their actual values. I know they have value as they are also echod on the page else where. Thanks Danny
  6. cool thanks guys. I honestly thought you had to go over board with this sort of thing on a users area. I manage to fix it by removing the function and doing what Psycho said with the strip_tags() and htmlspecialchars()
  7. I have a function that removes html, javascript and php from a text box that users of my site can write in. The problem is when a user types say; hello. My name is Danny And I love php freaks into my text box. Its also removing the new line entry's. I would very much stop to stop it doing that so it looks like I have paragraphs. Can someone please help me. Here is how I call the function. $description = strip_word_html($_POST['description'], $allowed_tags = '<b><i><sup><sub><em><strong><u><br><br/><br />'); And the function itself with notes. //remove html java and php function strip_word_html($text, $allowed_tags = '<b><i><sup><sub><em><strong><u><br><br/><br />') { mb_regex_encoding('UTF-8'); //replace MS special characters first $search = array('/‘/u', '/’/u', '/“/u', '/”/u', '/—/u'); $replace = array('\'', '\'', '"', '"', '-'); $text = preg_replace($search, $replace, $text); //make sure _all_ html entities are converted to the plain ascii equivalents - it appears //in some MS headers, some html entities are encoded and some aren't $text = html_entity_decode($text, ENT_QUOTES, 'UTF-8'); //try to strip out any C style comments first, since these, embedded in html comments, seem to //prevent strip_tags from removing html comments (MS Word introduced combination) if(mb_stripos($text, '/*') !== FALSE){ $text = mb_eregi_replace('#/\*.*?\*/#s', '', $text, 'm'); } //introduce a space into any arithmetic expressions that could be caught by strip_tags so that they won't be //'<1' becomes '< 1'(note: somewhat application specific) $text = preg_replace(array('/<([0-9]+)/'), array('< $1'), $text); $text = strip_tags($text, $allowed_tags); //eliminate extraneous whitespace from start and end of line, or anywhere there are two or more spaces, convert it to one $text = preg_replace(array('/^\s\s+/', '/\s\s+$/', '/\s\s+/u'), array('', '', ' '), $text); //strip out inline css and simplify style tags $search = array('#<(strong|b)[^>]*>(.*?)</(strong|b)>#isu', '#<(em|i)[^>]*>(.*?)</(em|i)>#isu', '#<u[^>]*>(.*?)</u>#isu'); $replace = array('<b>$2</b>', '<i>$2</i>', '<u>$1</u>'); $text = preg_replace($search, $replace, $text); //some MS Style Definitions - this last bit gets rid of any leftover comments */ $num_matches = preg_match_all("/\<!--/u", $text, $matches); if($num_matches){ $text = preg_replace('/\<!--(.)*--\>/isu', '', $text); } return $text; }
  8. Ive solved it with a new operator I'd never used or seen before. Here is the fixed query SELECT posts.*, users.*, countries.countryID, countries.country FROM posts INNER JOIN users ON users.userID = posts.postUserID INNER JOIN countries ON countries.countryID = users.userCountry WHERE posts.cityID = '".$row_rs_city['cityID']."' AND posts.type IN ('sightseeing', 'Inner city sightseeing', 'Outer city sightseeing') ORDER BY posts.postID DESC Thanks anyway guys
  9. I have a query that is very messy. I have tried using () to seperate everything and when I do it just all goes wrong. here is the query SELECT posts.*, users.*, countries.countryID, countries.country FROM posts INNER JOIN users ON users.userID = posts.postUserID INNER JOIN countries ON countries.countryID = users.userCountry WHERE posts.cityID = '".$row_rs_city['cityID']."' AND posts.type = 'sightseeing' OR posts.cityID = '".$row_rs_city['cityID']."' AND posts.type = 'Inner city sightseeing' OR posts.cityID = '".$row_rs_city['cityID']."' AND posts.type = 'Outer city sightseeing' ORDER BY posts.postID DESC Is there a way of re-writing this so that it has brackets seperating everything and it will still work. It works for the minute but re- writing posts.cityID = '".$row_rs_city['cityID']."' inbetween every OR just seems wrong. Thanks for your help guys
  10. thankyou works great!!
  11. I have a variable on my page called, $recipe['ingredients']; inside the var you have for example.... 100ml milk, 350ml double cream, 150ml water and so on. Now Im trying to split it up so it looks as follows <ul> <li>100ml milk</li> <li>350ml double cream</li> <li>150ml water</li> </ul> So far I have the following code..... $ingredientsParts = explode(',', $row_rs_recipes['ingredients']); $ingredients = array($ingredientsParts); while (! $ingredients) { echo" <li>$ingredients</li>";} But for some reason it doesnt work and I do not have the exp with explode to fix it.
  12. ok now i see the error and my code makes no sense. Other than creating an images table separate from the posts table and storing up to 5 in there per post is there any way of fixing this?
  13. ok yes right im trying to check if image2 is empty if it is run the code if its not leave it and check image3, if its empty run the code if its not leave it and so on. $cityq = mysql_query(SELECT * from cities WHERE citiesID = '$city'); $city = mysql_fetch_array($cityq); [code=php:0] if($city ['image2']!=""){ //add picture and update field image2 $fileName9 = $_FILES['image']['name']; $tmpName = $_FILES['image']['tmp_name']; $fileSize = $_FILES['image']['size']; $fileType = $_FILES['image']['type']; $randName = md5(rand() * time()); $fileName9 = $randName.$fileName9; $limit_size=2097152; $folder = "{$_SERVER['DOCUMENT_ROOT']}/images/memberImages/"; if ($fileSize >= $limit_size){$msg1="Your uploaded file size is more than 2MB so please reduce the file size and then upload. Visit the help page to know how to reduce the file size.<BR>"; $success=0;} elseif ($fileName9=="") {$error = "Please choose a file to upload"; $success=0;} //elseif ($fileType!== 'image/jpeg' || 'image/gif' || 'image/png' || 'image/JPG') {$error = "false";} $types = array('image/jpeg', 'image/gif', 'image/png', 'image/JPG', 'image/pjpeg', 'image/x-png'); if (in_array($fileType, $types)) { if(move_uploaded_file($tmpName , $folder.$fileName9)) { $Fnew1 = $fileName9; $cityname = $_POST['city']; $post =mysql_real_escape_string($city['postID']); $imageName = mysql_real_escape_string($_POST['imageName']); $UpdateImageq = mysql_query("UPDATE posts SET image2 ='$Fnew1', imageName2 = '$imageName' WHERE postID ='$post' ") or die('error 2'); $url = "/view.php?city=$cityname"; header("Location: $url"); } } else{echo"Move fail2"; } //end add picture } // now if image2 is full run this code if($city['image3']!="") { //add picture $fileName9 = $_FILES['image']['name']; $tmpName = $_FILES['image']['tmp_name']; $fileSize = $_FILES['image']['size']; $fileType = $_FILES['image']['type']; $randName = md5(rand() * time()); $fileName9 = $randName.$fileName9; $limit_size=2097152; $folder = "{$_SERVER['DOCUMENT_ROOT']}/images/memberImages/"; if ($fileSize >= $limit_size){$msg1="Your uploaded file size is more than 2MB so please reduce the file size and then upload. Visit the help page to know how to reduce the file size.<BR>"; $success=0;} elseif ($fileName9=="") {$error = "Please choose a file to upload"; $success=0;} //elseif ($fileType!== 'image/jpeg' || 'image/gif' || 'image/png' || 'image/JPG') {$error = "false";} $types = array('image/jpeg', 'image/gif', 'image/png', 'image/JPG', 'image/pjpeg', 'image/x-png'); if (in_array($fileType, $types)) { if(move_uploaded_file($tmpName , $folder.$fileName9)) { $Fnew1 = $fileName9; $cityname = $_POST['city']; $post =mysql_real_escape_string($city['postID']); $imageName = mysql_real_escape_string($_POST['imageName']); $UpdateImageq = mysql_query("UPDATE posts SET image3 ='$Fnew1', imageName3 = '$imageName' WHERE postID ='$post' ") or die('error 3'); $url = "/view.php?city=$cityname"; header("Location: $url"); } } else{echo"Move fail3"; } } the user can only upload 5 photos in total so the script repeats 4 times as the 1st image is uploaded else where
  14. put this code at the top of the page and load the page again. Should give you the errors error_reporting(E_ALL); ini_set("display_errors", 1);
  15. ok ive changed the code so it reads... if($row['image2']!=""){ //run this code } elseif($row['image3']!=""){ //run this code } elseif($row['image4']!=""){ //run this code } elseif($row['image5']!=""){ //run this code } but its still only uses the image2 field I have even tried if($row['image2']!=""){ //run this code } if($row['image3']!=""){ //run this code } if($row['image4']!=""){ //run this code } if($row['image5']!=""){ //run this code } but that doesnt work either
  16. Hi All Basically I have 4 fields in my database image2, image3, image4, image5 I have an image uploader to upload the files but I need what I need is if image2 is empty put in image3, if image3 is empty put in image4 so far I have this //so first is the query to find the right row which gives the variable $row //now here is what im doing if($row['image2']!==""){ //run this code } elseif($row['image3']!==""){ //run this code } elseif($row['image4']!==""){ //run this code } elseif($row['image5']!==""){ //run this code } Now the problem I'm having is the code that is always executing is the first one of $row['image2'] even if image2 has a value in the database it still runs that code and over writes the field in the database. It never moves on to field 3 or 4. Can someone please tell me if I've done something wrong. I'm not storing the image in the database just the name. Thanks Danny
  17. Hi. I have a piece of code that uploads an image. It works great. Ive added it to some more coding inserting information into a database. Now the code doesn't work. I have used some error reporting and i get Notice: Undefined index: newImage in /home/sites/submitpost.php on line 9 Notice: Undefined index: newImage in /home/sites/submitpost.php on line 10 Notice: Undefined index: newImage in /home/sites/submitpost.php on line 11 Notice: Undefined index: newImage in /home/sites/submitpost.php on line 12 Here is the code. Can someone explain whats wrong? include('database.php'); session_start(); //another photo uploader $fileName9 = $_FILES['newImage']['name']; $tmpName = $_FILES['newImage']['tmp_name']; $fileSize = $_FILES['newImage']['size']; $fileType = $_FILES['newImage']['type']; //$randName = md5(rand() * time()); //$fileName9 = $randName + $fileName9; $limit_size=2097152; $folder = "{$_SERVER['DOCUMENT_ROOT']}/images/memberImages/"; if ($fileSize >= $limit_size){$msg1="Your uploaded file size is more than 2MB so please reduce the file size and then upload. Visit the help page to know how to reduce the file size.<BR>"; $success=0;} elseif ($fileName9=="") {$error = "Please choose a file to upload"; $success=0;} //elseif ($fileType!== 'image/jpeg' || 'image/gif' || 'image/png' || 'image/JPG') {$error = "false";} $types = array('image/jpeg', 'image/gif', 'image/png', 'image/JPG', 'image/pjpeg', 'image/x-png'); if (in_array($fileType, $types)) { if(move_uploaded_file($tmpName , $folder.$fileName9)) { $Fnew1 = $fileName9; $place=mysql_real_escape_string($_POST['place']); $cityname=mysql_real_escape_string($_POST['cityname']); $city=mysql_real_escape_string($_POST['city']); $title=mysql_real_escape_string($_POST['ComTitle']); $message=mysql_real_escape_string($_POST['commentDescrip']); $member=mysql_real_escape_string($_POST['member']); $time=time(); mysql_query("INSERT INTO posts (type, title, message,postUserID, time, cityID, status, place, image) VALUES('$type','$title','$message','$member', '$time', '$city', '1', '$place', '$Fnew1')") or die('post error'); $id = mysql_insert_id(); $url = "/view-thankyou.php?city=$cityname&type=$type#name"; header("Location: $url"); } else {echo"Move fail"; } } ?>
  18. Cool ok thank you. That makes sense. However in this case the administrator comes along and adds say a message saying "there have been changes to our terms click here to close" the ID of that message upon creation will have to be added to all of the users accounts within the database. Is this standard practise? I really have no idea about this part of a website as I have never done it before.
  19. Hey Guys Im just after advice really with this question Basically I'm trying to design my first message system. One that once a user has read the message you can tick ok and its then gone forever. Now my boss says you have the message table MESSAGE messageID, Message then within the members table you have a field called messageID. Within this field you will store the ID's of all the messages the user has read. Upon login to the website you will check for ID's in the message table that do not exist in the messsageID of the users table. Is this correct or a really bad way of doing this? If I have to do it this way there will be a massive learning curve on my php knowledge. Does anybody know of a better way of doing this or a cool website to learn from? Thanks Danny
  20. Thanks mjdamato, You were correct. the variable $user was empty because I had not started the page with session_start(); so none of my functions were not working Again thank you so much.
  21. ok Im building a search page. The user can enter a name, county, category, address into my search field. The results page will show the details based on that. It works great so here is a snippet of the working code. $result = "-1"; if (isset($_POST['searchField'])) { $result = $_POST['searchField']; } $result = sprintf("SELECT Clubs.clubID, Clubs.name, Clubs.county, Clubs.logo, Clubs.postcode, Clubs.intro, Clubs.thumbsup, Clubs.cat, Category.*, County.*FROM Clubs INNER JOIN Category ON Clubs.cat = Category.catID INNER JOIN County ON Clubs.county = County.countyID WHERE ((Clubs.name Like %s) OR (Clubs.cat LIKE %s) OR (County.county LIKE %s) OR (Clubs.area LIKE %s) OR (Clubs.postcode LIKE %s) OR (Category.categorys LIKE %s)) " , String($result . "%", "text"), String($result . "%", "text"), String($result . "%", "text"), String($result . "%", "text"), String($result . "%", "text"), String($result . "%", "text")); This code works great no matter what I enter. the problem Im having is I only want to show results based on the logged in users county. I have a variable stored under $user['county'] which is the ID found in the County table under countyID I have tried writing the code so many different ways. Here is my latest attemped but it doesnt work. It breaks the whole query and nothing is displayed. $result = "-1"; if (isset($_POST['searchField'])) { $result = $_POST['searchField']; } $County= "-1"; if (isset($user['county'])) { $County= $user['county']; } $result = sprintf("SELECT Clubs.clubID, Clubs.name, Clubs.county, Clubs.logo, Clubs.postcode, Clubs.intro, Clubs.thumbsup, Clubs.cat, Category.*, County.* FROM Clubs INNER JOIN Category ON Clubs.cat = Category.catID INNER JOIN County ON Clubs.county = County.countyID WHERE ((Clubs.name Like %s) OR (Clubs.cat LIKE %s) OR (County.county LIKE %s) OR (Clubs.area LIKE %s) OR (Clubs.postcode LIKE %s) OR (Category.categorys LIKE %s)) AND County.countyID = %s" , String($result . "%", "text"), String($result . "%", "text"), String($result . "%", "text"), String($result . "%", "text"), String($result . "%", "text"), String($result . "%", "text") String($County. "%", "int")); Thanks Danny
  22. ok thanks guys Ive done everything that has been said and addapted my code accordingly. Thanks for the help. Unfortunately however the upload is still not working. I have no errors with error reporting switched on, when I upload an image the page just refreshes and no image is on the server. Am I even doing this correctly. Im trying to save a resized image to the server (for obvious space saving reasons) I will then store its name in the database. Ive googled every possible solution but none seem to do what I need. Here is the code as it stands. I cant see any errors myself and none output but no file gets uploaded to the server or anything. <?php error_reporting(-1); ini_set('display_errors', 1); if($_SERVER['REQUEST_METHOD']=='POST'){ if(isset($_FILES) && $_FILES['file']['error']==UPLOAD_ERR_OK){ // the upload worked, use the uploaded file information here... $fileName = $_FILES['file']['name']; $tmpName = $_FILES['file']['tmp_name']; //where to save the image $folder = "{$_SERVER['DOCUMENT_ROOT']}/members/images/Merseyside/"; //get original width and height $size = GetImageSize($tmpName); $width = $size[0]; $height = $size[1]; // auto adjust width of image according to predetermined height $new_height = 500; $new_width = $width * ($new_height/$height); // Resample image $image_resized = imagecreatetruecolor($new_width, $new_height); $image = imagecreatefromjpeg($tmpName); imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); //// New image $tmpName = $image_resized; $move = move_uploaded_file($tmpName , $folder.$fileName); if($move) { $url = "/members/clubs/image.php?pic=$image"; header("Location: $url"); } } else { echo "Error"; } } ?>
  23. Yes I agree but as soon as I remove the createimagefromjpeg function that error goes an I jus get the not a valid resource error.
  24. ok added that line an all my errors have started coming back now. error_reporting(-1); ini_set('display_errors', 1); if(isset($_POST['submit'])){ $fileName = $_FILES['imagefile']['name']; $tmpName = $_FILES['imagefile']['tmp_name']; //where to save the image $folder = "{$_SERVER['DOCUMENT_ROOT']}/members/images/Merseyside/"; //get original width and height $size = GetImageSize($tmpName); $width = $size[0]; $height = $size[1]; // auto adjust width of image according to predetermined height $new_height = 500; $new_width = $width * ($new_height/$height); // Resample image $image_resized = imagecreatetruecolor($new_width, $new_height); $image = imagecreatefromjpeg($tmpName); imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); //// New image $tmpName = $image_resized; $move = move_uploaded_file($tmpName , $folder.$fileName); if($move) { $url = "/members/clubs/image.php?pic=$image"; header("Location: $url"); } } my error list from entering that line. Warning: getimagesize() [function.getimagesize]: Filename cannot be empty in /home/sites/image.php on line 255 Warning: Division by zero in /home/sites//image.php on line 261 Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in /home/sites/image.php on line 264 Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: Filename cannot be empty in /home/sites/image.php on line 266 Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/sites/image.php on line 268 where as before there was only the other error.
  25. Ok i have read that info but I really dont know what you mean by GD image resource. That info goes way over my head. Can someone explain please?
×
×
  • 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.