Jump to content

designanddev

Members
  • Posts

    54
  • Joined

  • Last visited

designanddev's Achievements

Member

Member (2/5)

0

Reputation

  1. could you give an example, id be more than greatful
  2. Ok i have a class that uploads files, but i also would like it to submit without files being uploaded, the file only submits if a file has been uploaded, i want users to have the option not to upload if they didn't need to here is my code class class Photograph{ public $id; public $filename; public $type; public $size; public $content; public $caption; public $category_id; public $admin_id; public $created; private $temp_path; protected $upload_dir = "images"; public $errors = array(); protected $upload_errors = array( UPLOAD_ERR_OK => "NO errors", UPLOAD_ERR_INI_SIZE => "Larger than upload_max_filesize", UPLOAD_ERR_FROM_SIZE => "Larger than form MAX_FILE_SIZE", UPLOAD_ERR_PARTIAL => "Partal upload", UPLOAD_ERR_NO_FILE => "No file", UPLOAD_ERR_NO_TMP_DIR => "No temporary directory", UPLOAD_ERR_CANT_WRITE => "Can't write to disk", UPLOAD_ERR_EXTENSION => "File upload stopped by extension", ); //passes in $_FILE(['uploaded_file']) as an argument! public function attach_file($file="") { // Perform error checking on the form parameters if(!$file || empty($file) || !is_array($file)) { // error: nothing uploaded or wrong argument usage $this->errors[] = "No file was uploaded."; return false; } elseif($file['error'] != 0) { // error: report what PHP says went wrong $this->errors[] = $this->upload_errors[$file['error']]; return false; } else { // Set object attributes to the form parameters. $this->temp_path = $file['tmp_name']; $this->filename = basename($file['name']); $this->type = $file['type']; $this->size = $file['size']; // Don't worry about saving anything to the database yet. return true; } } public function getcontent(){ strlen($this->content) > 10; } public function save() { // A new record won't have an id yet. if(isset($this->id)) { // Really just to update the caption $this->update(); } else { // Make sure there are no errors // Can't save if there are pre-existing errors if(!empty($this->errors)) { return false; } // Make sure the caption is not too long for the DB if(strlen($this->caption) > 255) { $this->errors[] = "The caption can only be 255 characters long."; return false; } if(empty($this->caption)) { $this->errors[] = "please add a caption."; return false; } // Can't save without filename and temp location if(empty($this->filename) || empty($this->temp_path)) { $this->errors[] = "The file location was not available."; return false; } // Determine the target_path $target_path = "/home/designanddev.co.uk/public_html/blog/".$this->upload_dir."/".$this->filename; // Make sure a file doesn't already exist in the target location if(file_exists($target_path)) { $this->errors[] = "The file {$this->filename} already exists."; return false; } // Attempt to move the file if(move_uploaded_file($this->temp_path, $target_path)) { // Success // Save a corresponding entry to the database if($this->create()) { // We are done with temp_path, the file isn't there anymore unset($this->temp_path); return true; } } else { // File was not moved. $this->errors[] = "The file upload failed, possibly due to incorrect permissions on the upload folder."; return false; } } }
  3. Hi all can anyone spot what im doing wrong with this query? it keeps coming up with a mysql error. $result_set = self::find_by_sql("SELECT * FROM ".self::$table_name."ORDER BY 'photographs'.'id' DESC LIMIT 3 "); Kind Regards
  4. how do you grab facebook feeds
  5. this variables contain numbers when i hard code them into the string they work fine
  6. Can please someone help me by telling me what is wrong with this string i have wrote, were is the error what do i need to do to correct it. Kind Regards $json_content = file_get_contents('https://graph.facebook.com/'.$facebook_page_id.'/feed?access_token='.$access_token);
  7. i keep getting error messages when running this code below but it looks exactly the same as the tutorial i copied it from, i was wondering if someone could take a look and see if the can find my bug Kind Regards $facebook_pade_id = 'id'; $access_token = 'token'; $number_of_posts = 5; $json_content = file_get_contents('http://graph.facebook.com/'.$facebook_page_id.'/feed?access_token='.$access_token); $raw_data = json_decode($json_content); $i=0; foreach($raw_data->data as $feed) { $feed_id = explode("_", $feed->id); if (!empty($feed->message)) { $i++; if($i<($number_of_posts+1)) { ?> <div class="fb_update"> <?php if (!empty($feed->likes->count)) { ?> <div class="fb_likes"> <?php echo $feed->likes->count; ?> </div> <?php } ?> <?php if (!empty($feed->created_time)) {?> <div class="fb_date"> <?php echo date('F j, Y', strtotime($feed->created_time));?> </div> <?php } ?> <div class="fb_message"> <?php echo $feed->message; ?> </div> </div> <?php }?> <?php }?>
  8. Were i would begging to start access my Facebook posts to my personal website? Heres a good example... www.flo-skateparks.com Kind Regards Leo Scott
  9. Hi all i have nearly accomplish this registration form, i just have a minor problem with matching the post values to whats already stored in the database to then return back a message to the user letting them know whether someone has taken there input entry username/email Heres my code i can compare both username and email fields and also echo the message letting the user know if what soever has already been taken but when it queries the check for the username and i insert a a string that currently in the database it comes up with the error message and also ll does the elseif statement and inserted the records into the database even though its already taken. but the email check stops and doesn't insert the query if there a duplicate. public function Reg() { global $database; if(empty($this->username)){ $this->errors[1] = "You forgot to enter your Username."; } if(empty($this->email)){ $this->errors[2] = "You forgot to enter your email."; } if(empty($this->last_name)){ $this->errors[3] = "You forgot to enter your last name."; } if(empty($this->first_name)){ $this->errors[4] = "You forgot to enter your first name."; } if(empty($this->password)){ $this->errors[6] = "You forgot to enter your password."; } if ($this->password != $this->password2) { $this->errors[5] = 'Your password did not match the confirmed password.'; } elseif(empty($this->errors)){ // Register the user in the database... $match_user = "SELECT * FROM users WHERE username ='{$this->username}' LIMIT 1"; $result1 = mysql_query($match_user,$database->connection); $num1 = mysql_num_rows($result1); $match_email = "SELECT * FROM users WHERE email ='{$this->email}' LIMIT 1"; $result2 = mysql_query($match_email,$database->connection); $num2 = mysql_num_rows($result2); if($num1 > 0){ echo "username already exist"; } if($num2 > 0){ echo "email already exist"; } else{ $insert = "INSERT INTO users (username, password, first_name, last_name, email) VALUES ('{$this->username}','{$this->password}','{$this->first_name}','{$this->last_name}','{$this->email}')"; $r = mysql_query ($insert,$database->connection); } if($r){ echo "Thank you for registering"; } } }//End of Reg Kind Regards
  10. What i dnt get is that i have been using double quoutes for my queries all along, can someone explain why? Kind Regards
  11. I fixed the problem i by changing my query syntax to this... $sql = "SELECT * FROM users WHERE first_name ='{$this->first_name}' LIMIT 1"; But i am not sure why this works and the way i normally do my variables in queries did not work, would be nice to hear that explanation. Kind Regards Leo Scott
  12. Sorry ladies and gents i am still having trouble passing the posted form values into my method query, i can select all and it works fine but when i start to use WHERE clauses it goes all wrong here's my code please take a look. Kind Regards Submit if(isset($_POST['submit'])) { $new_user = new User(); $first_name = $new_user->first_name = $_POST['first_name']; $last_name = $new_user->last_name = $_POST['last_name']; if($new_user->reg()){ } else { $first_name = ""; $last_name = ""; } } Method public function Reg() { global $database; if(empty($this->last_name)){ $this->errors['one'] = "You forgot to enter your last name."; } if(empty($this->first_name)){ $this->errors['two'] = "You forgot to enter your first name."; } elseif(empty($this->errors)){ // Register the user in the database... $sql = "SELECT id FROM users WHERE first_name =".$this->first_name." LIMIT 1"; $result = mysql_query($sql,$database->connection); while($row = mysql_fetch_assoc($result)){ echo $row['first_name']; } } }//End of Reg
  13. ok could you show me an example, i can not structure this logic
  14. im not sure if that matters... i need this resolving
×
×
  • 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.