Php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Fiona
Forum Newbie
Posts: 1
Joined: Mon Apr 13, 2009 12:11 am

Php

Post by Fiona »

Thanks
Last edited by Fiona on Mon Apr 13, 2009 6:16 am, edited 1 time in total.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Understanding PHP

Post by requinix »

All you want is to understand what it does?

Unfortunately the color for comments is a dark gray, makes them a bit harder to read.

Code: Select all

// this function takes two arguments: objArray (probably an array) and
// photo_name (probably a string)
function somefunction($objArray,$photo_name)
 {
// global is used to get to variables defined outside the function
// PHP won't let you do that automatically
// "objSmarty" is probably the main Smarty object
      global $objSmarty;
// get the month from the objArray
   $month=$objArray["month"];
// get the day number
  $day=$objArray["date"];
// this will add a leading zero to the day
// if it's less than 10 (one digit) it adds a zero, otherwise it doesn't
  if($day<10)
  $days="0".$day;
  else
  $days=$objArray["date"];
 
// get the year
  $year=$objArray["year"];
// turn those numbers into YYYY-M-DD format
// (we didn't pad the month with zeroes so it might be one digit!)
  $dob=$year."-".$month."-".$days;
   
// if the name is not empty
       if($photo_name!="")
    {
// run an UPDATE query
// I added spaces here and below so it doesn't mess up the page layout
   $UpQuery = "Update tbl_member set disp_name='" . addslashes($objArray['disp']) . "', first_name='" . addslashes($objArray['firstname']) . "', last_name='" . $objArray['lastname'] . "', zipcode='" . $objArray['post'] . "', user_photo_name='" . $photo_name . "', country='" . $objArray['country'] . "', state='" . $objArray['state'] . "', gender='" . $objArray['gender'] . "', date_birth='" . $dob . "' where user_id=" . $_SESSION['user_id'];
  $this->ExecuteQuery($UpQuery, "update");
 }
   else
   {
// run an almost identical query (no mention of user_photo_name in here)
   $UpQuery = "Update tbl_member set disp_name='" . addslashes($objArray['disp']) . "', first_name='" . addslashes($objArray['firstname']) . "', last_name='" . $objArray['lastname'] . "', zipcode='" . $objArray['post'] . "', country='" . $objArray['country'] . "', state='" . $objArray['state'] . "', gender='" . $objArray['gender'] . "', date_birth='" . $dob . "' where user_id=" . $_SESSION['user_id'];
  $this->ExecuteQuery($UpQuery, "update");
 }
    
// finally a return value. this function will always return true
    return true;
  
  
  }
I rate this script at 6/10. Insecure, wasteful, and a bit inconsistent in places.
Post Reply