Jump to content

kee2ka4

Members
  • Posts

    68
  • Joined

  • Last visited

    Never

Posts posted by kee2ka4

  1. Hey Guys,

     

    I am fixing someone else's code, so please bear with me on this one. Basically the site has an application form and once the user has submitted the form, they get an automated email with an induction date, and the date is taken from the admin panel where the admin user puts in the date and time and number of applicants. So basically the if the admin user puts in Date: 23th Sept 2011 Time: 9:30 Number of Applicants: 30, the next 30 successfull applicants will get that date and time.

     

    The problem with the code is that now whenever the user fills in the application and their application is successfull, they are getting an induction date of Thursday, 1 January 1970 and no time. I am not sure why this happens if someone could point me in the right direction.

     

    Here is the snipet of the code where it prints out the date:

    Your Induction date is <?php echo (date("l, j F Y", strtotime($array_result_ind['date'])))." at ".$array_result_ind['hour'];?>
    

     

    The code at the top of the page is:

    <?php 
    
    //include('browser_redirect.php');
    
    //Start session and page 
    session_start();
    
    $induction = isset($_GET['id'])?$_GET['id']:'';
    $_SESSION['change_ind_date_app_ID'] = $induction;
    
    $db_leafletj_jobs = mysql_connect("localhost", "leafletj_jobs", "t10872") or die(mysql_error());
    $sel_leafletj_jobs = mysql_select_db("leafletj_jobs") or die(mysql_error());
    $query_str = "SELECT applicants.id, applicants.unique_ref, applicants.app_date, applicants.fname, applicants.surname, applicants.ind_date, applicants.ind_ord_no, inductions.date, inductions.hour FROM (applicants JOIN inductions ON (applicants.ind_date = inductions.date)) WHERE applicants.id=".$induction;
    $result_ind = mysql_query($query_str, $db_leafletj_jobs) or die(mysql_error());
    //$count = mysql_num_rows($result_ind);
    $array_result_ind = mysql_fetch_array($result_ind, MYSQL_BOTH);
    ?>
    

     

    Also the database for the induction date and time is blank. I haven't designed the application so I am a little lost. I the system was all working a couple of weeks ago but now all of a sudden it prints out that 1970 date with no time. Is this a quick fix?

     

    Thanks,

    Ken

  2. Hey Peeps,

     

    What is the best way to access the session id of a logged in user in the header.ctp file which is in the views/element directory. Basically I have a link called My Account in the header file, and I want to display the logged In user info, once the user logs in.

     

    I have the following link in the code:

    <li><?php echo $html->link('My Account', '/users/view/'); ?></li>

     

    But I want to pass the logged in user id in the view?

     

    I have included the following 

    var $helpers = array('Session');

    in the app_helper file but don't know how to get the session id and pass it to the view.

     

    Thanks,

    Ket

  3. Hey guys,

     

    I am a newbie in cakePHP and need some help. I have the following code in the add() function of the invoices_controller:

    function add() {
    	if (!empty($this->data)) {
    		$this->Invoice->create();
    		if ($this->Invoice->save($this->data)) {
    			$this->Session->setFlash(__('The Invoice has been saved', true), 'success');
    			$this->redirect(array('action' => 'index'));
    		} else {
    			$this->Session->setFlash(__('The Invoice could not be saved. Please, try again.', true));
    		}
    	}
    
    }
    

     

    The data is collected from the form in the add view, but I also have a field called "TransactionNum" which needs to store a random generated Number along with the id generated after adding a new record in the database. So say the add(), successfully added the following record: invoice.id = 12, I want to immediately update the TransactionNum with "random number + id" to give it a unique transaction number.

     

    Any Ideas?

     

  4. Hey Guys,

     

    I am a newbie in cakephp and wanted some guidance in the model associations before I bake the application. I have identified three entities called Users, Assessors and Invoices but couldn't figure out the correct associations since their logic is a lill different. Here is a brief summary of the web app:

     

    1. Users login to the system and can search for Assessors. Users can select an Assessor and can only select one Assessor. If they want to select another Assessor then they need to first remove their current Assessor. Once the user selects an Assessor, their selected Assessor can create an Invoice that the user can view. Users can have multiple Invoices created by their selected Assessor.

     

    2. Assessor’s can login to the system and view list of users that have selected them. They can create Invoices for their users. So Assessor can create zero or many invoices for their users.

     

    I have done some research on model associations and was thinking of using the one to one relationship where dependence is equal to "False" on Users and Assessors so:

     

    User has one Assessor but that would make the belongsTo association as a natural complement to the hasOne, so Assessor belongsTo Users - this is not necessarily true since an Assessor many not have any users or a User may not have any Assessor. Can someone provide me with some light here, I am confused :-)

     

    I think I am clear with the association of Invoices with Users and Assessors, which is

     

    Users has many Invoices

    Assessors has many Invoices

    Invoices belong to Users

    Invoices belong to Assessors

     

    Correct me if I am wrong but I am not very clear on what association to use between Users and Assessors?

     

    Thanks,

    Ket

     

  5. Hey peeps,

     

    I have the following regular expression rule, that validates the email address:

    'email' => '/^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z.]{2,4}$/',

     

    But when I input test@test.com it passes but when I input test@test.co.uk it fails. Is my regular expression incorrect? Could anyone plz show me some light here..

     

    Thanks :-)

     

  6. Hey peeps,

     

    I use two functions called

     

    1. element_value($error, $row, $param) that returns the correct value for a form element!

    Here is the code:

    /**
     * returns the correct value for our form element
     * @param bool $error
     * @param string $row
     * @param string $param
     * @return string
     */
    function element_value($error, $row, $param)
    {
    	if ($error){ return ''; }
    	if ($row) {  return $row;  }
    	if ($param) { return $param; }
    	return '';
    }

     

    and 2. error_msg($error, $msg) which returns the error message of a form element if there is an error. Here is the code:

     function error_msg($error, $msg)
      {
        if($error) { return $msg; }
    	return '';
      }

     

    My question is, this works fine with an input box or a text box field but I cannot make it to work for a dropdown. So if I don't make a selection for a dropdown, it does not echo out the error. Here is my form element...

    Code for the input box, this validates correctly!

    div class="elementPost">
    <label for="title" class="smlText"><strong>Title: <img src="/public/images/required.gif" width="8" height="8" /> </strong><span class="helpMsg"> <?php echo error_msg($errors['title'], 'Oops! Title must be atleast 5 chars.');  ?></span></label>
    <br/>
    <input class="textpost" type="text" value="<?php echo element_value($errors['title'], $postAd['title'], $params['postAd']['title']);  ?>" name="postAd[title]" onFocus="javascript:toggleMsg('msg-2')" onBlur="javascript:toggleMsg('msg-2')"/> 
    <span id="msg-2" class="smallmsg" style="visibility:hidden;">Minimum 5 characters </span>
    </div>
    

     

    Form element for the dropdown - this doesnt work,  it doesn't give out the error when I do not make a selection in the dropdown:

    <div class="elementPost">
    <label for="email" class="smlText"><strong>Country: <img src="/public/images/required.gif" width="8" height="8" /> </strong><span class="helpMsg"> <?php echo error_msg($errors['cid'], 'Oops! Please select a Country.');  ?></span></label>
    <br/>
    <select name="postAd[cid]">
    <option value="">Select Country</option>
    <?php $countryList = getCountryList(); foreach($countryList as $countryName): ?>
    <option value="<?php echo element_value($errors['cid'], $countryName['cid'], $params['postAd']['cid']);  ?>" <?php echo (($countryName['cid'] == $params['postAd']['cid']) ? ' selected="selected"' : null) ?>><?php echo $countryName['country_name'] ?></option>
    <?php endforeach; ?>
    </select>
    </div>
    

     

    Any Ideasss?

  7. I have the following regular expression for the body field which is a Textbox in a Form, that accept minimum 15 characters and maximum 2000 characters:

     

    $post_validation = array('body'  => '/^.{15,2000}$/');
    

     

    The issue I have having is, whenever I paste a large text from another website into my textbox that is below the 2000 characters, the $post_validation returns an error. I can't make out why this happens.

     

    Has anyone faced a similar problem?

     

    Thanks,

    Ket

  8. Hey peeps,

     

    I have a question with regards to loading my site from a sub folder. At the moment, I place my entire site in the www folder provided by my hosting company and when i type my url, my site works fine.

     

    But I want to place my site in a folder within www and load my site from there. So for example, if I place my site in a folder called siteone within www and when I type in my url, say www.domain.com, I want the site to load.

     

    I am not sure how to do that. Can someone plz point me in the right direction.

     

    Thanks,

    Ket

  9. Hey peeps,

     

    I have a question as why Internet explorer never displays my error messages the frist time I run my code and always displays it the second time. I am using $_SESSION['flash']['warning'] to displays messages.

     

    Here is the breakdown of my code. I am using the function below to display error messages:

    function flash_warning($msg) 
    {
        if(!$msg) { return false; }
        $_SESSION['flash']['warning'] = $msg;
        return true;
    }
    

    In my controller file I have the following code that simply decides if the condition in false then display the message.

    if(!formSent($params))
    {flash_warning("Sorry your message cannot be sent");}
    

    In the view file, I display the error mesage(if there is any) using a  simple if statement:

    <?php if($_SESSION['flash']['warning']) { ?>
    <span class="helpMsg"><?php echo $_SESSION['flash']['warning']; ?></span>
    

     

     

    The above code works fine the with Firefox but with Internet Explorer it never displays the error message the frist time and always displays it the second time. Can anyone please guide me why this happens?

     

    Thanks,

    Zub

  10. Hey peeps,

     

    I am using the following function below, that uses trim(), strip_tags() and htmlspecialchars() so that I can make my site secure from users entering invalid data.

     

    But I would like to have basic html tags to be allowed such as <p>, <b>, <a href>. Is there any way I can allow basic html tags but still make my site secure.

     

    function safe_output($value)
    {
    	$value = trim($value);
    	$value = strip_tags($value);
    	$value = htmlspecialchars($value);
    	return $value;
    
    }

     

    I would appreciate advise or pointers on how you guys make your site secure and yet allow users to enter value html tags.

    Thanks,

    Zub

  11. Hey peeps,

     

    I wanted to create a Random and a Unique Number of 8 digits that will represent each unique advert posted by users. I have an advert_id in the database that is the primary key but I do not want to use that on the site for security reasons. So each advert_id will have a unique 8 digit number which will be stored in the table under column name Ad_num. Could anyone guide me how to do this.

     

    The 8 digit number has to be unique and random and no fields in the database can have the same number.

     

    Thanks,

    Zub

  12. Hello Peeps,

     

    I have use the following regular expression to validate my fields.

     

    $post_validations = array('body'  => '/^[[:alnum:][:punct:][:space:]]{1,2000}$/');

     

    Where the body field can start with any characters including space and punct and must have a minimum of one character to avoid empty values. My question is how can I add more validation to the regular exp so that if someone enters only a space character followed by no text, then the reg ex fails. So if I have the text '  this is an Example' then the reg exs passes as the character can start with a space but if I have the text '  ' then it should fail, since it only contains space tabs and no text, how can I add that validation to the reg ex

     

    Thanks,

    Zub

  13. Hello Peeps,

     

    I have a question regarding the select tag in a form. I have a php ForEach loop that loops throught a database an gets the value and the name of the select tags for the dropdown list. Here is the code:

    <select name="c">
         	<option value="">ALL</option>
            <?php foreach($catList as $catName): ?>
    	<option value="<?php echo $catName['id'] ?>"><?php echo $catName['name'] ?></option>
            <?php endforeach; ?>
    </select>
    

     

    I needed to include a selected = "" tag if the $catName['id'] == $_GET['c']; I am not sure how to code this in the loop. Can anyone plz guid me on this.

     

    Thanks,

    Zub

  14. Ok I will explain, I am trying to query the database using two options:

     

    1. Search Form, where users can type in a keyword and the function find_ad($q) queries the database and returns a result in form of an array

    2. Search Tags, that are hyperlinked. So what I want is clicking on the hyperlinks again runs the fucntion find_ad($q).

     

    The user an use "Any" of the two options. Here is my code of function find_ad($q)

    function find_ad($query_str = null)
    {
      db_connect();
      $select = "SELECT
       				advertdy.id,
       				advertdy.title,
       				advertdy.description,
       				advertdy.price,
       				advertdy.location, ";
       $from = "FROM
       				advertdy ";
       
       $where = "WHERE 
       			advertdy.id > 0 AND advertdy.delete_flag = 0 ";
       
       $order = " ORDER BY advertdy.id DESC";
       if (!empty($query_str))
       {
       		$select .= sprintf("
    				match(ad_ID,title,description,location)
    				against('%s' IN BOOLEAN MODE)
    				as relevance ",
    				mysql_real_escape_string($query_str)
    				);
    		$where .= sprintf("
    				AND match(ad_ID,title,location,description) against('%s' IN BOOLEAN MODE) ", 
    				mysql_real_escape_string($query_str)
    				);
    		$order = " ORDER BY relevance DESC";
    
    
       }
       
    	    
       $query = $select.$from.$where.$order;
       $result = mysql_query($query);
       $result = db_result_to_array($result);
       return $result;
       
    }
    
    

     

    I wanted to know how to pass the value of the search tags (as in the name) into $q variable. So for example if the search tag name is "Test", how do I pass it to the variable $q. My question is related to option 2, how to passes the hyperlink tag name into the function find_ad($q);

     

    Thanks,

    Zub

  15. Hi peeps,

     

    I am currently querying a database that displays results on the search.php from index.php. I have a form that uses the "Get" Method and saves the value in "q". Here is my form code:

    <form method="get" action="search.php">
          <input id="mainSearchInput" type="text" value="" size="40" name="q"/>
          <input size="40" value="Search" type="submit" />
    </form>

     

    On presses the "SEARCH", the controller file saves the value of q and queries the database. Here is the php code:

    case 'search':
    
      $q = $_GET['q'];
      $results = find_ad($q);
    
    break;

     

    Above code, runs the find_ad($q) function and saves the value in $results and loads the search.php page.

     

     

    The above works fine and my question is I would also like to pass the value of q using a hyperlink. So for example if I have the following:

    <a href="search.php?q=<?php echo $cat['name'] ?>">

    , how can I save the value of "q" from the link to the variable $q in the controller file.

     

    Just to be more clear, the get method from the form saves the value of q into variable $q via $q = $GET['q'], my question is if someone clicks the hyperlink how can I save the value of q into the same variable $q.

     

    Can someone plz guide me, I hope I am making sense.

     

    Thanks,

    Zub

  16. I have figured it out how to set the minimum lenght of char's. Here is the process for setting it for everyone:

     

    1. Add the following line to the bottom of my.ini file,

    [mysqld]

    ft_min_word_len=2

    (if you are using WAMP, then you can locate this file by clicking on the wamp icon at the bottom and go to the MySQL tab and you will find the my.ini file)

     

    2. Then restart your server

    3. Go to PhpMyAdmin, and redefine your index's

    4. And lastly run another SQL script that is:

    REPAIR TABLE tbl_name QUICK

     

    And then it will work.

    Thanks,

    Zub

×
×
  • 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.