Jump to content

jarvis

Members
  • Posts

    543
  • Joined

  • Last visited

Everything posted by jarvis

  1. Thanks for the reply. I've been playin around and have nearly got it working how I need it too. The current months shows and any articles from that month are listed. The previous months for that year are then shown, i.e. it shows August, then July -> January I'm stuck on getting the same to work for years. Below's my code if someone can assist? <?php // This page displays all articles within a specified category $page_title = 'View Featured News Articles'; require('includes/header.html'); require_once('../mysql_connect.php'); // Connect to the db // Set the category id $id="18"; // Set the sorting order by months if (isset($_GET['month'])) { // $month will be appended to the links $order_by = $_GET['month']; } else { // Set a default sorting month to current month $order_by= date('F'); } // Set the sorting order by years if (isset($_GET['year'])) { // $year will be appended to the pagination links $year = $_GET['year']; } else { // Set a default sorting year to current year $year= date('Y'); } $query = " SELECT articles.article_id, articles.title, LEFT(articles.description, 50) AS abbrev, articles.status, article_associations.article_id, article_categories.category, DATE_FORMAT(articles.date_entered,'%M') as month,DATE_FORMAT(articles.date_entered,'%Y') as year, DATE_FORMAT(articles.date_entered,'%d %M %Y') as date FROM articles INNER JOIN (article_categories INNER JOIN article_associations ON article_categories.article_category_id = article_associations.article_category_id) ON articles.article_id = article_associations.article_id WHERE articles.article_id = article_associations.article_id AND article_associations.article_category_id=$id AND article_associations.approved = 'Y' AND status='1' AND DATE_FORMAT(articles.date_entered,'%M') = '$order_by' AND DATE_FORMAT(articles.date_entered,'%Y') = '$year' ORDER BY date_entered DESC"; $result = @mysql_query ($query); // Run the query. $num = mysql_num_rows ($result); // How many users are there? if ($num > 0) { // If it ran OK, display the records. echo "<h1>There is currently $num new articles for the month of $order_by</h1>"; echo '<table cellpadding="3" cellspacing="3" border="0" align="center" width="100%">'; echo '<tr> <td><p><b>Title:</b></p></td> <td><p><b>Description:</b></p></td> <td> </td> <td> </td> </tr>'; // Fetch and print all the records. $bg = '#CCCCCC'; // Set the background color. while ($row = mysql_fetch_array($result, MYSQL_NUM)) { $category = '' .$row['5']. ''; $bg = ($bg=='#CCCCCC' ? '#FFFFFF' : '#CCCCCC'); // Switch the background color. echo '<tr bgcolor="' . $bg . '"> <td>' .$row['1']. '</td> <td>'; $extract = $row['2']; // find position of last space in extract $lastSpace = strrpos($extract, ' '); // use $lastSpace to set length of new extract and add ... echo substr($extract, 0, $lastSpace).'... '; echo '</td>'; echo '<td>'.$row['7'].'</td>'; echo "<td><a href=\"articles.php?aid={$row['0']}\">Read More...</a></td>"; echo '</tr>'; } echo '</table>'; echo '<h1 style="text-align: right; color: #AE0026;">'.$category.'</h1>'; echo '<p> </p>'; } else { // Not records in related to that category ID. echo '<p class="error">There are currently no news articles!</p>'; } echo '<p>Sort By:</p>'; $year = date("Y"); //get the current year $startDate = "1 january".$year; // set the end date to current year function printMonths($var) { $id="18"; //include the category id for the links $start = strtotime($var); //timestamp of the entered date $now = strtotime("Now"); //timestamp of now so it does not write anything in the future while ($now > $start) //while the start is less than now { echo '<a href="news_archive.php?s=&id=' . $id . '&month=' . date("F", $now) .'">'.date("F", $now).'</a>'; echo " | "; $now = strtotime("-1 month", $now); // subtract a month from the start timestamp } } printMonths($startDate); //execute the function ### YEARS - TEST ### echo '<hr>'; $startYear = "2005"; //get the current year echo $startYear; function printYears($var) { $id="18"; //include the category id for the links $start = strtotime($var); //timestamp of the entered date $now = strtotime("Now"); //timestamp of now so it does not write anything in the future while ($now > $start) //while the start is less than now { echo '<a href="news_archive.php?s=&id=' . $id . '&year=' . date("Y", $now) .'">'.date("Y", $now).'</a>'; echo " | "; echo date("Y", $now); $now = strtotime("-1 year", $now); // subtract a month from the start timestamp } } printYears($startYear); //execute the function mysql_close(); // Close the database connection. require('includes/footer.html'); ?> Thanks in advanced!
  2. Hi All, I'm in the process of building an article CMS and I'm after some advice please. At present, all articles are stored in the mysql db and have a date_entered column (type=timestamp). I then use PHP to reference the DB. What I'd like to do is have a page which sorts articles by month with the most relevant month first, then the other months listed underneath, so it would be August at present, any articles from Aug listed or message 'no articles this month' under this would be July, June, May etc.. and then an option to view previous years which would be in month order. So 2008, 2007, selecting that would then be Dec - Jan Where's the best place to start with this? Sorry if it's a daft question! Many thanks!
  3. Ah cool, good thinking! Is that something I can add into the above function as well? Thanks for your time and patience!
  4. Thanks ignace, I will replace my existing file with yours and test it. Will I need to make any other alterations elsewhere? Very much appreciated!
  5. Thanks all for you replies. So the method I used is not worthy? Is it best to alter the main resize function below rather than altering the scripts for adding and editing images? <?php function saveThumb($gal,$fn) { define("MAX_XY", 250); // maximum width or height of thumbnail image $fpath = "uploads/$gal/$fn"; //print $fpath."\n"; /* GetImageSize returns an array: * $info[0] - horizontal size of image in pixels * $info[1] - vertical size of image in pixels * $info[2] - type of image (1=GIF, 2=JPEG, 3=PNG) */ $info = GetImageSize("$fpath"); //print_r($info); // do we need to resize image? if ($info[0] > MAX_XY || $info[1] > MAX_XY) { // is image landscape? if ($info[0] >= $info[1]) { $width = MAX_XY; $height = $info[1]*MAX_XY/$info[0]; // or portrait? } else { $height = MAX_XY; $width = $info[0]*MAX_XY/$info[1]; } } else { // use original dimensions $width = $info[0]; $height = $info[1]; } // create new thumbnail image //echo "<br>$width - $height<br>"; $im = ImageCreateTrueColor($width, $height); /* determine image type and load original image. Notice new tests for image * types. The GD extension has changed a lot over the years, dropping GIFs * and adding PNG support. By testing, we avoid trying to process an image * PHP can't deal with */ $im_big = ""; // default is no image switch ($info[2]) { case 1 : if (ImageTypes() & IMG_GIF) // test for GIF support $im_big = ImageCreateFromGIF("$fpath"); break; case 2 : if (ImageTypes() & IMG_JPG) // test for JPEG support $im_big = ImageCreateFromJPEG("$fpath"); break; case 3 : if (ImageTypes() & IMG_PNG) // test for PNG support $im_big = ImageCreateFromPNG("$fpath"); break; case 4 : if (ImageTypes() & IMG_BMP) // test for BMP support $im_big = ImageCreateFromBMP("$fpath"); break; } if ($im_big) { /* resize original image into thumbnail - see PHP Manual for details on * the arguements ImageCopyResized takes */ ImageCopyResized($im,$im_big,0,0,0,0,$width,$height,$info[0],$info[1]); } else { // couldn't load original image, so generate 'no thumbnail' image instead $width = 100; $height = 100; $im = ImageCreate($width, $height); // create a blank image $bgc = ImageColorAllocate($im, 0, 0, 0); // background color = black $tc = ImageColorAllocate($im, 255, 255, 255); // text color = white ImageFilledRectangle($im, 0, 0, $width, $height, $bgc); // draw rectangle ImageString($im, 3, 9, 36, "No thumbnail", $tc); // add text ImageString($im, 3, 17, 48, "available", $tc); } /* save our image in thumb directory - if the second argument is left out, * the image gets sent to the browser, as in thumbnail.php */ ImageJPEG($im, "uploads/".$gal."/t_".$fn); // clean up our working images ImageDestroy($im_big); ImageDestroy($im); } ?> All help is very much appreciated! Thank you again
  6. Oh I see, thank you! I did the following although not sure if its 'ideal': Changed if (isset($_FILES[$filename]) && ($_FILES[$filename]['error'] != 4)) To if (isset($_FILES[$filename]) && ($_FILES[$filename]['error'] != 4) && ($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg") || ($_FILES["file"]["type"] == "image/bmp") ) Is that acceptable? Thanks all!
  7. Hi phpSensei, Thanks for the prompt response, would that go in the function? Thanks
  8. Hi all, hope someone can kindly assist. I've the following form: for ($i = 0; $i < MAX_IMAGE_UPLOADS; $i++) { echo '<tr> <td><p><b>File '.($i + 1).':</b> <input type="file" name="upload' . $i . '" /></p></td> <td><p><b>Image Description:</b> <textarea name="image_description' . $i . '" cols="25" rows="3"></textarea></p></td> </tr>'; } Which allows a set number of upload fields as defined by MAX_IMAGE_UPLOADS. The script then does it's thing using the following script to process the images: $article_insert_id = mysql_insert_id(); $image_path = 'uploads/'.$article_insert_id; if(isset($message)) die ($message); // CREATE NEW DIRECTORY TO STORE IMAGES if(!file_exists($image_path)) { if(mkdir($image_path)) { // MAKE NEW IMAGE DIRECTORY WRITABLE if(chmod($image_path, 0777)) { // HANDLE EACH UPLOADED FILE. for ($i = 0; $i < MAX_IMAGE_UPLOADS; $i++) { #echo $i; // Create index names to refer to the proper upload and description. $filename = 'upload' . $i; $image_description = 'image_description' . $i; // Check for a file. if (isset($_FILES[$filename]) && ($_FILES[$filename]['error'] != 4)) { // Check for a description (not required). if (!empty($_POST[$image_description])) { $d = "'" . escape_data($_POST[$image_description]) . "'"; } else { $d = 'NULL'; } /* if (!empty($_POST['$image_description'])) { $d = escape_data($_POST['$image_description']); } else { $d = 'NULL'; }*/ // Add the record to the database $query = "INSERT INTO uploads (article_id, file_name, file_size, file_type, image_description) VALUES (".$article_insert_id.", '{$_FILES[$filename]['name']}', {$_FILES[$filename]['size']}, '{$_FILES[$filename]['type']}', $d)"; $result = mysql_query ($query) or die(mysql_error()); if($result) { // Return the upload_id from the database. $upload_id = mysql_insert_id(); // Move the file over. if (move_uploaded_file($_FILES[$filename]['tmp_name'], $image_path.'/'.$_FILES[$filename]['name'])) { saveThumb($article_insert_id,$_FILES[$filename]['name']); //hidden as not required #echo '<p>File number ' . ($i + 1) . ' has been uploaded!</p>'; #echo '<p>' . mysql_error() . '<br /><br />Query: ' . $query . '</p>'; // Debugging message. //include ('./includes/footer.html'); } else { // File could not be moved. die('couldnt move file'); echo '<p>File number ' . ($i + 1) . ' could not be moved.</p>'; include ('./includes/footer.html'); // Remove the record from the database. $query = "DELETE FROM uploads WHERE upload_id = $upload_id"; $result = mysql_query ($query) or die(mysql_error()); } } else { // If the query did not run OK. echo '<p>Your submission could not be processed due to a system error. We apologize for any inconvenience.</p>'; // Print the query and invoke the mysql_error() function to debug. } //} else die('ERROR'); } else die(); } // End of FOR loop. // used for debugging } else die('could not chmod the image directory'); // used for debugging } else die('could not make new image directory'); // used for debugging } else die('could not make new image directory, directory exists. Please contact the administrator'); This then calls in the below function to resize and create the thumbnails: <?php function saveThumb($gal,$fn) { define("MAX_XY", 250); // maximum width or height of thumbnail image $fpath = "uploads/$gal/$fn"; //print $fpath."\n"; /* GetImageSize returns an array: * $info[0] - horizontal size of image in pixels * $info[1] - vertical size of image in pixels * $info[2] - type of image (1=GIF, 2=JPEG, 3=PNG) */ $info = GetImageSize("$fpath"); //print_r($info); // do we need to resize image? if ($info[0] > MAX_XY || $info[1] > MAX_XY) { // is image landscape? if ($info[0] >= $info[1]) { $width = MAX_XY; $height = $info[1]*MAX_XY/$info[0]; // or portrait? } else { $height = MAX_XY; $width = $info[0]*MAX_XY/$info[1]; } } else { // use original dimensions $width = $info[0]; $height = $info[1]; } // create new thumbnail image //echo "<br>$width - $height<br>"; $im = ImageCreateTrueColor($width, $height); /* determine image type and load original image. Notice new tests for image * types. The GD extension has changed a lot over the years, dropping GIFs * and adding PNG support. By testing, we avoid trying to process an image * PHP can't deal with */ $im_big = ""; // default is no image switch ($info[2]) { case 1 : if (ImageTypes() & IMG_GIF) // test for GIF support $im_big = ImageCreateFromGIF("$fpath"); break; case 2 : if (ImageTypes() & IMG_JPG) // test for JPEG support $im_big = ImageCreateFromJPEG("$fpath"); break; case 3 : if (ImageTypes() & IMG_PNG) // test for PNG support $im_big = ImageCreateFromPNG("$fpath"); break; case 4 : if (ImageTypes() & IMG_BMP) // test for BMP support $im_big = ImageCreateFromBMP("$fpath"); break; } if ($im_big) { /* resize original image into thumbnail - see PHP Manual for details on * the arguements ImageCopyResized takes */ ImageCopyResized($im,$im_big,0,0,0,0,$width,$height,$info[0],$info[1]); } else { // couldn't load original image, so generate 'no thumbnail' image instead $width = 100; $height = 100; $im = ImageCreate($width, $height); // create a blank image $bgc = ImageColorAllocate($im, 0, 0, 0); // background color = black $tc = ImageColorAllocate($im, 255, 255, 255); // text color = white ImageFilledRectangle($im, 0, 0, $width, $height, $bgc); // draw rectangle ImageString($im, 3, 9, 36, "No thumbnail", $tc); // add text ImageString($im, 3, 17, 48, "available", $tc); } /* save our image in thumb directory - if the second argument is left out, * the image gets sent to the browser, as in thumbnail.php */ ImageJPEG($im, "uploads/".$gal."/t_".$fn); // clean up our working images ImageDestroy($im_big); ImageDestroy($im); } ?> How and where is the best way to only allow for certain file types and to stop the script with a 'wrong file type' error message? Thank you in advanced!
  9. Thanks Tommyda, however, the standard/default keywords are pulled from the CMS as it allows them to be updated at any point. Hence why I push the values into the header via isset and then use if else. The issue seems to be with this block of code: $query = "SELECT articles.article_id, articles.description, articles.status, articles.meta_keywords, articles.meta_description, articles.title, article_categories.category, article_categories.article_category_id FROM articles INNER JOIN (article_categories INNER JOIN article_associations ON article_categories.article_category_id = article_associations.article_category_id) ON articles.article_id = article_associations.article_id WHERE articles.article_id = $aid AND status = '1'"; $result = mysql_query($query) or die( "Could not execute SQL query" ); if (mysql_num_rows($result) > 0) { // if the query ran ok continue... // Retrieve the info from the db $row = mysql_fetch_array ($result, MYSQL_ASSOC); # Include Page Title and Call to header here for dynamic pages # $page_title = $row['title'] .', '. $row['category'] .', LP Gas'; $meta_keywords = $row['meta_keywords']; $meta_description = $row['meta_description']; if (($row['meta_keywords']) !=""){ $meta_keywords = $row['meta_keywords']; echo $meta_keywords; } else { $meta_keywords = FALSE; echo $meta_keywords; } if (($row['meta_description']) !=""){ $meta_description = $row['meta_description']; echo $meta_description; } else { $meta_description = FALSE; echo $meta_description; } include ('./includes/header.html'); # Include Page Title and Call to header here for dynamic pages # # Create Breadcrumb # echo'<p><a href="index.php">Home</a> > <a href="article_list.php?id=' . $row['article_category_id'] . '">' . stripslashes($row['category']) . '</a> > ' . stripslashes($row['title']) . '</p>'; # /Create Breadcrumb # I believe it's because if the meta_keywords/description are empty when it retrieves the info for a given id, I need to make sure that either keywords/description are set to empty and use should then work in the header code i.e. if(!isset($meta_keywords) || empty($meta_keywords)) { Although am no whizz at PHP by any means! Cheers
  10. Thanks waynewex for the reply, can you explain? Sorry am massively recovering from a stag weekend and think all brain cells were killed off!
  11. Hi all, I'm creating an article CMS system. Each article can have it's own meta keywords and meta description, otherwise default ones are used which can be set via the CMS. The main article page itself calls in a global header with the following code: if(!isset($meta_keywords) || empty($meta_keywords)) { $meta_key = "SELECT keywords FROM meta_content"; $meta_key_result = mysql_query ($meta_key) or die( "Could not execute SQL query" ); while ($row = mysql_fetch_array ($meta_key_result, MYSQL_ASSOC)) { $meta_keywords =$row['keywords']; } } if(!isset($meta_description) || empty($meta_description)) { $meta_des = "SELECT description FROM meta_content"; $meta_des_result = mysql_query ($meta_des) or die( "Could not execute SQL query" ); while ($row = mysql_fetch_array ($meta_des_result, MYSQL_ASSOC)) { $meta_description =$row['description']; } } I then call this in using: <meta name="keywords" content="<?php echo $meta_keywords; ?>" /> <meta name="description" content="<?php echo $meta_description; ?>" /> So in theory, if $meta_keywords and $meta_description are empty from the article, it will use the default! This is the code I use on the article page to create the main page query & obtain the values for $meta_keywords and $meta_decription: $query = "SELECT articles.article_id, articles.description, articles.status, articles.meta_keywords, articles.meta_description, articles.title, article_categories.category, article_categories.article_category_id FROM articles INNER JOIN (article_categories INNER JOIN article_associations ON article_categories.article_category_id = article_associations.article_category_id) ON articles.article_id = article_associations.article_id WHERE articles.article_id = $aid AND status = '1'"; #$result = mysql_query($query) or die( "Could not execute SQL query" ); $result = mysql_query($query) or die(mysql_error()); if (mysql_num_rows($result) == 1) { // if the query ran ok continue... // Retrieve the info from the db $row = mysql_fetch_array ($result, MYSQL_ASSOC); # Include Page Title and Call to header here for dynamic pages # $page_title = $row['title'] .', '. $row['category']; #$meta_keywords = $row['meta_keywords']; //debug #$meta_description = $row['meta_description']; //debug if (($row['meta_keywords']) !=""){ $meta_keywords = $row['meta_keywords']; echo $meta_keywords; } else { $meta_keywords = FALSE; echo $meta_keywords; } if (($row['meta_description']) !=""){ $meta_description = $row['meta_description']; echo $meta_description; } else { $meta_description = FALSE; echo $meta_description; } include ('./includes/header.html'); # Include Page Title and Call to header here for dynamic pages # All good so far, or so I thought! If the article has the meta keywords and description set, the page loads fine. If they're blank, the default should show, instead, my page has the following: I cannot work out this simple piece of code & it's now driving me mad! Any help is very much appreciated!!! Thanks in Advanced!
  12. Sorry to bump, wondered if someone could point out the obvious! many thanks
  13. If I print that line from the db // Retrieve the date the member joined $joined_date = $row['date']; echo $joined_date .'- joined date<br/>'; I get Thanks and apologies
  14. Hi ignace, Many thanks for the reply. That does seem to work until I change: $joined_date = strtotime('01 Juli 2009'); To: $joined_date = strtotime($row['date']); I'm setting $joined date as follows: DATE_FORMAT(registration_date,'%d %M %Y') as date $joined_date = $row['date']; Do I need to alter this as registration_date is in my db as date_time Thanks again!
  15. Thanks ignace, do I need to do any of the following: echo $dateDiff .' date diff'; echo '<hr>'; $time_convert = (60*60*24); echo $time_convert . ' time convert'; $fullDays = floor($dateDiff/$time_convert); As changing that one line makes the following: Differernce is 14447 days Which isn't right. Sorry! :-\
  16. Hi All, Hope some kind soul can help!? I've a users table in a CMS i'm building. This users table has a registration_date that stores data in datetime format. When a user registers, they can select whether they want a normal or premium account. As such, they will need to pay for the premium account. I've built a script which list all users and the date joined using $query = "SELECT CONCAT(last_name, ', ', first_name) as name, DATE_FORMAT(registration_date,'%d %M %Y') as date, email FROM users ORDER BY $order_by LIMIT $start, $display"; I then show the date next to the username. All's ok so far. What I want to do is set it so that if a year has passed since the join date, an email is sent reminding them of payment is due and 30 days prior to this, a warning email is sent. I know a cron jobs used for automating, however, at the mo, I can't even get the date difference working. This is the code I've got so far: $todays_date = time(); echo $todays_date .' todays'; echo '<hr/>'; $joined_date = mktime($row['date']); echo $joined_date .' joined'; echo '<hr>'; $dateDiff = $todays_date - $joined_date; echo $dateDiff .' date diff'; echo '<hr>'; $time_convert = (60*60*24); echo $time_convert . ' time convert'; $fullDays = floor($dateDiff/$time_convert); echo '<hr>'; echo "Differernce is $fullDays days"; It keeps saying 0 days though! Once I can get the date calc working I can then start working on the email code & then a cron job to automate it all. Any help is much appreciated!
  17. Sorry, it's just where I've put the code in here! They should all be $query1 or $result1, that's what I've got on my PC. its just where I was using $query3 and $result3 for the third variation of testing on my PC and thought it'd put them to 1's to prevent confusion. Instead, created confusion!
  18. Hi, I've got trouble with a really simple IF ELSE statement, it works fine if theirs a value in the db, but the ELSE part of the statement doesn't function. Am going insane trying to work it out. Any help would be superb! [code] $query1 ="SELECT associations.a_id, events.event_id,events.event, associations.month_id,DATE_FORMAT(months.date,'%d %M %Y') as date FROM months INNER JOIN (events INNER JOIN associations ON events.event_id = associations.event_id) ON months.month_id = associations.month_id WHERE ((associations.month_id) BETWEEN '32' AND '59')"; $result1 = mysql_query ($query);   echo "<tr>     <td align=\"left\">February</td><td>&nbsp;</td><td>&nbsp;</td>";   echo'</tr>';   while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) {     if ($query >= 0) {       echo'<tr>';         echo'<td>' . $row['event'] . '</td><td>' . $row['date'] . '</td>';         echo "<td><a href=\"event_info.php?uid=" . $row['event_id'] . " \">details</a></td>";       echo'</tr>';             }else{       echo "<tr>         <td colspan=\"3\">no events this month</td>       </tr>";     }   } [/code] Is it something stupid I'm overlooking? The query works fine. Using another form, if I enter data, specific to a particular month, then the data is displayed. If I remove it, it should say 'no events this month'. But just appears blank. Any help gratefully receievd! jarvis
  19. Sorry, what was happening was that the rent side would work if you searched by rent but if you searched by no of rooms it wouldn't work. I want it to be an OR statement. I think it's a problem with syntax though they should be ..."WHERE (bedrooms='$bn' OR rent BETWEEN '$lo' and '$hi')"; I think this is the right way!
  20. Is this just due to the brackets in the wrong place? [code]WHERE  (rent BETWEEN $lo AND $hi) OR (bedrooms='$bn')"; [/code] Have tried moving the brackets about but still to no avail! Anyone?
  21. Hi All! I've managed to get an upload form to work but can't work out how to retrieve the images back out as I'm uploading multiple images. I'm using the below to get the info; [code]$first = TRUE;         //$query = "SELECT file_name, file_type, file_size FROM uploads WHERE property_id=$pid";         $query = "SELECT upload_id, file_name, image_description, property_id FROM uploads WHERE property_id=$pid";         $result = mysql_query ($query);                  while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)){             if($first){             echo "<td><img src=\"uploads/{$row['file_name']}\"></td>";             echo "<td class=\"bodytext\">File Name {$row['file_name']} </td>";                  $first = FALSE; [/code] I'm opening a page specific to a property by using GET $pid. I've 2 tables one called uploads and one call properties. The images are uploaded with time stamps and a property_id to uploads and other info is entered into the properties table. Surely by referencing the property_id that was entered into uploads, I should be able to pull out the images relating to that id? The uploads table shows entries in the db and I've an uploads folder too. Not sure if it helps but here's the form that enters the property details and images; [code] <?php // Set the page title and include the HTML header. $page_title = 'Add A Property'; require('../includes/header_logged_in.html'); $counter = 3; // Number of files to allow for. if (isset($_POST['submit'])) { // Handle the form.     require_once ('../../mysql_connect.php'); // Connect to the database.              $message = NULL; // Create an empty new variable     // Check for property type     if (empty($_POST['prop_type'])) {         $pro = FALSE;         $message .= '<p class="error">You forgot to add a property type!</p>';     } else {         $pro = escape_data($_POST['prop_type']);     }          // Check for a rental price     if (is_numeric($_POST['rent'])) {         $r = (float) $_POST['rent'];     } else {         $r = FALSE;         $message .= '<p class="error">Please enter the property\'s rental price!</p>';     }          // Check for a description - may not have one (optional)     if (!empty($_POST['des'])) {         $des = escape_data($_POST['des']);     } else {         $des = '<i>No description available!</i>';     }     // Check for number of rooms (optional)     if (!empty($_POST['bed_no'])) {         $bn = escape_data($_POST['bed_no']);     } else {         $bn = '<i>Number Of Bedrooms not specified!</i>';     }     // Check for full address     if (empty($_POST['add1'])) {         $ad1 = FALSE;         $message .= '<p class="error">Please enter the full address</p>';     } else {         $ad1 = escape_data($_POST['add1']);     }     // Check for postcode.     if (empty($_POST['pcode'])) {         $pc = FALSE;         $message .= '<p class="error">You forgot to enter a postcode!</p>';     } else {         $pc = escape_data($_POST['pcode']);     }          for ($i = 0; $i < $counter; $i++) { // Handle each uploaded file.              // Create index names to refer to the proper upload and description.         $filename = 'upload' . $i;         $image_description = 'image_description' . $i;              // Check for a file.         if (isset($_FILES[$filename]) && ($_FILES[$filename]['error'] != 4)) {             // Check for a description (not required).             if (!empty($_POST[$image_description])) {                 $d = "'" . escape_data($_POST[$image_description]) . "'";             } else {                 $d = 'NULL';             }                          // Add the record to the database.             $query = "INSERT INTO uploads (file_name, file_size, file_type, image_description) VALUES ('{$_FILES[$filename]['name']}', {$_FILES[$filename]['size']}, '{$_FILES[$filename]['type']}', $d)";             $result = mysql_query ($query);                      if ($result) {                                  // Return the upload_id from the database.                 $upload_id = mysql_insert_id();                                  // Move the file over.                 if (move_uploaded_file($_FILES[$filename]['tmp_name'], "../uploads/$upload_id")) {                                      echo '<p>File number ' . ($i + 1) . ' has been uploaded!</p>';                                      } else { // File could not be moved.                                      echo '<p><font color="red">File number ' . ($i + 1) . ' could not be moved.</font></p>';                              // Remove the record from the database.                     $query = "DELETE FROM uploads WHERE upload_id = $upload_id";                     $result = mysql_query ($query);                                          // Add more detailed error reporting, if desired.                                      }                              } else { // If the query did not run OK.                 echo '<p><font color="red">Your submission could not be processed due to a system error. We apologize for any inconvenience.</font></p>';                 // Print the query and invoke the mysql_error() function to debug.             }                          if ($pro && $r && $ad1 && $pc) { // If all's ok...         $query = "SELECT property_id FROM properties WHERE add1 ='$ad1'";                 $result = @mysql_query ($query); // if no duplicate addresses         if (mysql_num_rows($result) == 0) {             // Produce the query                 $query = "INSERT INTO properties (property_type, description, rent, bedrooms, add1, pcode) VALUES ('$pro', '$des', '$r', '$bn', '$ad1', '$pc')";                          $result = @mysql_query ($query); // Process the query             if ($result) { // if required is supplied                              // Display message if all ok                 echo '<p class="parabreak"><b>Property details have been added!</b></p>';                 require('../includes/footer.html'); // Include the HTML footer                 exit(); // Terminate the script                              } else { // inform the user if an error occured                 $message = '<p class="error">Property details could not be added. We apologize for any inconvenience.</p><p>' . mysql_error() . '</p>';             }                 } else {             $message = '<p class="error">That address already exists!</p>';         }         #mysql_close(); // Close the db connection     } else {         $message .= '<p class="parabreak">Please try again.</p>';             }                                   } // End of if (isset($the_file)...              } // End of FOR loop.          mysql_close(); // Close the database connection.          } // End of the main Submit conditional. // Inform the user if an error occured if (isset($message)) {     echo '<font color="#FFCC00">', $message, '</font>'; } ?> <form enctype="multipart/form-data" action="add_property_new.php" method="post">     <fieldset><legend>Fill out the form to upload a file:</legend>     <input type="hidden" name="MAX_FILE_SIZE" value="524288">     <table>             <tr>                 <td class="bodytext">Property Type: </td>                 <td><select name="prop_type">                 <option>Bungalow</option>                 <option>Chalet</option>                 <option>Flat</option>                 <option>House</option>                 <option>Studio</option>                 </select></td>             </tr>             <tr>                  <td class="bodytext">Rent PCM: </td>                 <td><input type="text" name="rent" size="30" maxlength="50" value="<?php if (isset($_POST['rent'])) echo $_POST['rent']; ?>" /></td>             </tr>             <tr>                 <td colspan="2"><small>Please do not include the £ sign</small></td>                 <td>&nbsp;</td>             </tr>             <tr>                 <td class="bodytext">Description:</td>                 <td><textarea rows="4" name="des" size="30" value="<?php if (isset($_POST['des'])) echo $_POST['des']; ?>" /></textarea></td>             </tr>             <tr>                 <td class="bodytext">No Of Bedrooms: </td>                 <td><select name="bed_no">                 <option>Zero</option>                 <option>1</option>                 <option>2</option>                 <option>3</option>                 <option>4</option>                 <option>5</option>                 <option>6</option>                 </select></td>             </tr>             <tr>                 <td class="bodytext">Full Address:</td>                             <td><textarea rows="4" name="add1" size="30" value="<?php if (isset($_POST['add1'])) echo $_POST['add1']; ?>" /></textarea></td>             </tr>             <tr>                 <td class="bodytext">Postcode:</td>                 <td><input type="text" name="pcode" size="10" maxlength="15" value="<?php if (isset($_POST['pcode'])) echo $_POST['pcode']; ?>" /></td>             </tr>                          <?php // Create the inputs.             for ($i = 0; $i < $counter; $i++) {                              echo '<tr><td>File:</b> <input type="file" name="upload' . $i . '" /></td>             <td>Image Description:</b> <textarea name="image_description' . $i . '" cols="25" rows="3"></textarea></td></tr>             ';             }             ?>             <tr>                 <td></td>             </tr>             </table>     </fieldset>     <input type="hidden" name="submit" value="TRUE" />     <div align="center"><input type="submit" name="submit" value="Submit" /></div> </form> <?php include ('../includes/footer.html'); ?> [/code] Thanks again! Thanks in advanced
  22. Wow! Thanks, I never knew you could do that! Am now trying to make my statement with this [code] $query = "SELECT add1, property_id, property_type,rent,bedrooms, image_name,pcode FROM properties           WHERE  (rent BETWEEN $lo AND $hi) OR (bedrooms='$bn')";[/code] The first part works thanks to Barands switch case statement. I've this for the bedrooms drop down [code]      if (empty($_POST['beds'])) {         $bn .="'" . escape_data             ($_POST['beds']) . "' ";     }else{         $bn = escape_data($_POST['beds']);     }  [/code] And this for the drop down [code]      <tr>         <td class="bodytext">           <select name="beds">             <option></option>             <option>Zero</option>             <option>1</option>             <option>2</option>             <option>3</option>             <option>4</option>             <option>5</option>             <option>6</option>           </select></td>       </tr> [/code] Am I missing the obvious?
  23. Hi, I've a menu that creates a drop down of prices from a db. The field is called rent. People add in the rental amount for example, 130.00 or 750.00 or 1000.00 I'm having trouble trying to get the drop down to work though. What I want is the drop down to display options of 0 -500 501 - 750 751 - 1000 I've put the details in the options but can't work out how to do the select statement to do the between part e.g. [code]$query = "SELECT add1, property_id, property_type,rent,bedrooms, image_name,pcode FROM properties WHERE  ((rent < '$r1') OR  (rent BETWEEN '$r1' AND '$r2')) ";[/code] I've got the values from [code]    //check for rental amount no (optional)     if (empty($_POST['rent'])) {         $r .="'" . escape_data             ($_POST['rent']) . "' ";     }else{         $r = escape_data($_POST['rent']);     }     $r1 = 500;     $r2 = 750;     $r3 = 1000; [/code] My drop down is this [code]      <tr>         <td class="bodytext">           <select name="rent">             <option></option>             <option value="$r1">0 - 500</option>             <option value="$r2">501 - 750</option>             <option value="$r3">751 - 1000</option>             <option>1000+</option>           </select></td>       </tr> [/code] Can someone please help? Thanks in advanced!
×
×
  • 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.