Jump to content

jarvis

Members
  • Posts

    543
  • Joined

  • Last visited

Posts posted by jarvis

  1. 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!

  2. 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!
  3. 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
  4. 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!
  5. 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
  6. 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?
  7. 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.