Jump to content

booxvid

Members
  • Posts

    32
  • Joined

  • Last visited

Everything posted by booxvid

  1. I was trying to make form wherein you give you a title and its description plus, you can upload photo with it. The problem is.. I had the difficulty in saving together the texts and also the photo my text and photo details are saved into one database table which is named, "texts" here's my controller: function addpost(){ /*ID IS THE BLOG PAGE ID*/ $id = $this->uri->segment(3); $username = $this->session->userdata('username'); $userid = $this->blog_model->get_id('username',$username); $this->form_validation->set_rules('blogtitle','Blog Title','is_unique[texts.text_title]'); $this->form_validation->set_rules('desc','Description','required'); $this->form_validation->set_error_delimiters(' ',''); if($this->form_validation->run()==FALSE){ echo ""; $this->view_posts(); } else{ $title =$this->input->post('blogtitle'); $desc = $this->input->post('desc'); $timezone = "Asia/Manila"; date_default_timezone_set ($timezone); $date = date("Y-m-d"); $timetoday = date("H:i:s"); $photo = $this->input->post('upload'); if ($photo) { /*UPLOAD IT AND SAVE IT TO THE PROFILE FOLDER AND ITS THUMBNAIL AS WELL*/ $data_second=$this->blog_model->do_uploadthispost($userid); print_r($data_second); } $data = array( 'text_title'=>$title, 'text_content'=>$desc, 'text_date'=>$date, 'text_time'=>$timetoday, 'text_user_id'=>$userid, 'text_blogpage_id'=>$id ); $userdata = array( 'username' => $username, 'logged_in' => TRUE, 'user_id' => $userid ); $new_data = $data + $data_second; $this->blog_model->create_new($newdata,'texts'); /*GIVES A PROMPT MESSAGE THAT YOU SUCCESSFULLY CREATED A BLOG*/ echo ""; $this->view_posts(); } } and here's the model: in my model i have these variable inside my construct : $this->photos_path = realpath(APPPATH. '../assets/img/posts/'); $this->photos_path_url = base_url().'assets/img/posts/'; wherein i have this variables before my construct: var $photos_path; var $photos_path_url; and this is my main function from my blog_model which it will upload the photo hopefully in the requested dir and its thumbnail also: function do_uploadthispost() { $config = array( 'allowed_types' => 'jpg|jpeg|gif|png', 'upload_path' => $this->photos_path, 'max_size' => 10000 ); $this->load->library('upload', $config); $this->upload->do_upload(); $image_data = $this->upload->data(); $config = array( 'source_image' => $image_data['full_path'], 'new_image' => $this->photos_path . '/thumbs', 'maintain_ratio' => true, 'width' => 690, 'height' => 900 ); $this->load->library('image_lib', $config); $this->image_lib->resize(); $filepath = $image_data['file_path']; $filename = $image_data['file_name']; $type = $image_data['file_type']; $size = $image_data['file_size']; $data = array(); /*SAVE IT INTO THE DATABASE*/ if($size<10000){ $data = array( 'filename'=>$filename, 'filepath'=>$filepath, 'type'=>$type, 'size'=>$size, ); //$this->update_this($data,); } return $data; } also: here's the portion where i placed my form: <div id="myModal" class="modal hide fade"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">×</button> <?php echo heading('Add Post',3); ?> </div> <div class="modal-body"> <hr> <?php $attributes = array('class'=>'form-inline','id'=>'thisForm'); echo form_open_multipart('posts/addpost/'.$idblog.'',$attributes); echo form_label('Title:','title'); $data_input_fname = array( 'class'=>'input-large', 'name'=>'blogtitle', 'id'=>'blogtitle', 'maxlength'=>'100', 'placeholder'=>'Insert you blog title here'); echo nbs(3); echo br(1); echo form_input($data_input_fname); echo br(2); echo form_upload('userfile',array('class'=>'btn btn-primary')); echo br(2); echo form_label('Content:','content'); $data_inputdesc = array( 'type'=>'textarea', 'style'=>'width: 500px; height: 150px', 'class'=>'input-large', 'name'=>'desc', 'id'=>'desc', 'placeholder'=>'Insert text here' ); echo nbs(2); echo form_textarea($data_inputdesc); ?> <br/><br/> <center> <?php $submit_data = array('type'=>'submit', 'class'=>'btn btn-large btn-primary', 'name'=>'submit_form', 'value'=>'Submit!'); echo form_submit($submit_data); echo nbs(5); $reset_data = array('type'=>'reset', 'class'=>'btn btn-large', 'name'=>'reset_form', 'value'=>'Reset!'); echo form_reset($reset_data); echo form_close(); ?></center> </div><!---modal body --> </div>
  2. Is there another way that I could separate the date and time because I have two columns in my mysql table the blog_date and blog_time
  3. public function create_blog(){ $this->load->view('header'); $this->form_validation->set_rules('blogtitle','Blog Title','required'); $this->form_validation->set_rules('desc','Description','required'); $this->form_validation->set_error_delimiters(' ',''); if($this->form_validation->run()==FALSE){ $this->load->view('view_dashboard_addblog'); } else{ $title =$this->input->post('blogtitle'); $desc = $this->input->post('desc'); $data = array( 'blog_title'=>$title, 'description'=>$desc, 'blog_date'=>CURDATE(), 'blog_time'=>CURTIME()); $this->blog_model->insert_posts($data); echo ""; $this->load->view('view_blog'); } } My problem is, curdate() and curtime() function for mysql doesn't work at all, it says an undefined function, how to get the current date and time in Codeigniter and insert it into my mysql table
  4. Here's the snippet code in controller: public function me_login(){ $this->load->view('header'); $this->form_validation->set_rules('username','First Name','required'); $this->form_validation->set_rules('password','Last Name','required'); $this->form_validation->set_error_delimiters(' ',''); if($this->form_validation->run()==FALSE){ $this->load->view('view_login'); } else{ $u= $this->input->post('username'); $p= $this->input->post('password'); $username = trim($u); $password = trim($p); //search same info from db $boolean = $this->blog_model->login($username,$password); if($boolean){ $userdata = array( 'username' => $username, 'logged_in' => TRUE ); $this->session->set_userdata($userdata); echo ""; $this->load->view('view_home',$userdata); } else{ echo ""; $this->load->view('view_login'); } } } here's my blog_model where my login function located: public function login($username,$password){ $encode = $this->encrypt->encode($password); $query = $this->db->get_where('blog_user', array('username' => $username, 'securepass' => $encode)); return $query->result(); } I don't know why my Login function will always be failed.
  5. How to set value in an input field? I'm using a codeigniter framework; <?php $data_input_fname = array('class'=>'input-large', 'name'=>'firstname', 'id'=>'firstname', 'value'=>set_value('<?php echo $fname;?>'), 'maxlength'=>'100'); echo form_input($data_input_fname); <?php $data_input_fname = array('class'=>'input-large', 'name'=>'firstname', 'id'=>'firstname', 'value'=>set_value($fname), 'maxlength'=>'100'); echo form_input($data_input_fname); i already tried those two, but nothing come out in my input field.
  6. I don't where this error come from \: The error was: my function update in my model [code=php:0] public function update_posts($data,$id){ $this->db->where('idblog_user', $id) ->update('blog_user',$data); return; } [/code] my two functions in my controller [code=php:0]public function updateform(){ $data = array(); $data['posts']=$this->blog_model->getthis_records(); $this->load->view('view_update',$data); } public function updatethis(){ $this->form_validation->set_rules('firstname','First Name','required|alpha_numeric'); $this->form_validation->set_rules('lastname','Last Name','required|alpha_numeric'); $this->form_validation->set_rules('gender','Gender','required'); $this->form_validation->set_rules('month','Month','required'); $this->form_validation->set_rules('month','Day','required'); $this->form_validation->set_rules('year','Year','required'); $this->form_validation->set_rules('email','Email Address','required|valid_email|is_unique[idblog_user.email]'); $this->form_validation->set_rules('username','Username','required|min_length[5]|max_length[12]|is_unique[idblog_user.username]|alpha_dash'); $this->form_validation->set_rules('password','Password','required|min_length[6]|max_length[12]'); $this->form_validation->set_error_delimiters('<br /><span class="error"> ','</span>'); if($this->form_validation->run()){ $fname =$this->input->post('firstname'); $lname = $this->input->post('lastname'); $gender = $this->input->post('gender'); $month = $this->input->post('month'); $day = $this->input->post('day'); $year = $this->input->post('year'); $date = sprintf('%s-%s-%s',$year,$month,$day); $eadd = $this->input->post('email'); $username = $this->input->post('username'); $password = $this->input->post('password'); $data = array('firstname'=>$fname,'lastname'=>$lname,'gender'=>$gender, 'birthday'=>$date,'email'=>$eadd,'username'=>$username,'password'=>$password); $id=$this->uri->segment(3); $printquery = $this->blog_model->update_posts($data,$id); echo $printquery; if($this->blog_model->update_posts($data,$id)){ redirect(); } else{ // $this->messages->error('There was an error updating this product\'s attributes...'); echo "UN"; } } } [/code] and in my view: [code=php:0] <div> <?php echo heading('Current Data:',3);?> <?php foreach ($posts as $p):?> <?php echo form_label('First Name:','firstname')." ". $p['firstname']; echo br(2);?> <?php echo form_label('Last Name:','lastname')." ". $p['lastname']; echo br(2);?> <?php echo form_label('Birthday:','birthday')." ". $p['birthday']; echo br(2);?> <?php echo form_label('Email Address:','email')." ". $p['email']; echo br(2);?> <?php echo form_label('Username:','username')." ". $p['username']; echo br(2);?> <?php endforeach; echo nbs(4);?> </div> <div> <div class="form"> <?php foreach ($posts as $p):?> <?php $attributes = array('class'=>'well form-inline','id'=>'thisForm'); echo form_open('blog/updatethis/'.$p['idblog_user'].'',$attributes)?> <?php endforeach;?> <table cellspacing="2" cellpadding="10" border=0> <tr> <td><?php echo heading('REGISTRATION FORM',3);?></td> </tr> <tr> <td><?php echo form_label('First Name:','firstname')?></td> <td><?php $data_input_fname = array('class'=>'input-large', 'name'=>'firstname', 'id'=>'firstname', 'maxlength'=>'100'); echo form_input($data_input_fname); ?> </td> </tr> <tr> <td><?php echo form_label('Last Name:','lastname')?></td> <td><?php $data_input_lname = array('class'=>'input-large', 'name'=>'lastname', 'id'=>'lastname', 'maxlength'=>'100'); echo form_input($data_input_lname); ?></td> </tr> <tr> <td><?php echo form_label('Gender:','gender')?></td> <td><?php $gender_f = array('name'=>'gender', 'type'=>'radio'); $gender_m = array('name'=>'gender', 'type'=>'radio' ,'value'=>'Male'); echo form_radio($gender_f).' Female'; echo nbs(3); echo form_radio($gender_m).' Male'; ?></td> </tr> <tr> <td><?php echo form_label('Birthday:','birthday')?></td> <td><?php $options = array(''=>'Month', '01'=>'January', '02'=>'February', '03'=>'March', '04'=>'April', '05'=>'May', '06'=>'June', '07'=>'July', '08'=>'August', '09'=>'Septembr', '10'=>'October', '11'=>'November', '12'=>'December'); echo form_dropdown('month',$options,''); $options2 = array(''=>'Day', '01'=>'1', '02'=>'2', '03'=>'3', '04'=>'4', '05'=>'5', '06'=>'6', '07'=>'7', '08'=>'8', '09'=>'9', '10'=>'10', '11'=>'11', '12'=>'12', '13'=>'13', '14'=>'14', '15'=>'15', '16'=>'16', '17'=>'17', '18'=>'18', '19'=>'12', '20'=>'20', '21'=>'21', '22'=>'22', '23'=>'23', '24'=>'24', '25'=>'25', '26'=>'26', '27'=>'27', '28'=>'28', '29'=>'29', '30'=>'30', '31'=>'31'); echo form_dropdown('day',$options2,''); $year = array(); for($i=1800;$i<=2012;$i++){ $year[$i]= $i; } $year_my = array_combine($year,$year); echo form_dropdown('year', $year_my); ?></td> </tr> <tr> <td><?php echo form_label('Email:','email address')?></td> <td><?php $data_inpute = array('class'=>'input-large', 'name'=>'email', 'id'=>'email', 'maxlength'=>'100'); echo form_input($data_inpute); ?></td> </tr> <tr> <td><?php echo form_label('Username:','username')?></td> <td><?php $data_input = array('class'=>'input-large', 'name'=>'username', 'id'=>'username', 'maxlength'=>'100'); echo form_input($data_input); ?></td> </tr> <tr> <td><?php echo form_label('Password:','password')?></td> <td><?php $data_pass = array('class'=>'input-large', 'name'=>'password', 'id'=>'password', 'maxlength'=>'100', 'type'=>'password'); echo form_password($data_pass); ?></td> </tr> <tr> <td colspan=2> <?php if(validation_errors()): echo validation_errors(); endif;?> </td> </tr> <tr> <td colspan="2"><center> <?php $submit_data = array('type'=>'submit', 'class'=>'white button', 'name'=>'submit_form', 'value'=>'Submit!'); echo form_submit($submit_data); $reset_data = array('type'=>'reset', 'class'=>'white button', 'name'=>'reset_form', 'value'=>'Reset!'); echo form_reset($reset_data);?></center> </td> </tr> <?php form_close();?> </table> </div> </div> [/code]
  7. I have an index function of my controller which it's the index page of my application, and in my reg_form function in my controller I load my view_registration.php the php file has a css design that's attached by the header.php already that's in my index function when I view the page of my registration form, there's no design? Is there a way that I can load my css file in a function from a controller?
  8. Using frameworks will avoid you in having a spaghetti code and having libraries of functions already that we always use in every web application.
  9. Requiring fields validation is already done but my other validations wouldn't work. Here's my controller: my validation process is placed with a validation function: public function reg_validation(){ $this->form_validation->set_rules('firstname','First Name','required|min_length[5]'); $this->form_validation->set_rules('lastname','Last Name','required'); $this->form_validation->set_rules('gender','Gender','required'); $this->form_validation->set_rules('course','Course','required'); $this->form_validation->set_rules('interest','Interest','required'); $this->form_validation->set_rules('desc','Description','required'); $this->form_validation->set_rules('username','Username','required|min_length[5]|max_length[12]|is_unique[user.username]'); $this->form_validation->set_rules('password','Password','required|min_length[6]|max_length[12]'); $this->form_validation->set_error_delimiters('<br /><span class="error"> ','</span>'); if($this->form_validation->run()==FALSE){ $this->load->view('view_registration'); } else{ $this->create(); redirect(); } } then here's my view_registration.php [code=php:0] <div> <div class="form"> <?php $attributes = array('class'=>'well form-inline','id'=>'thisForm'); echo form_open('',$attributes)?> <table cellspacing="2" cellpadding="10" border=0> <tr> <td><?php echo heading('REGISTRATION FORM',3);?></td> </tr> <tr> <td><?php echo form_label('First Name:','firstname')?></td> <td><?php $data_input_fname = array('class'=>'input-medium', 'name'=>'firstname', 'id'=>'firstname', 'maxlength'=>'100', 'value'=>set_value()); echo form_input($data_input_fname); echo br(1); if(!$this->input->post('firstname')){ echo form_error('firstname');}?> </td> </tr> <tr> <td><?php echo form_label('Last Name:','lastname')?></td> <td><?php $data_input_lname = array('class'=>'input-medium', 'name'=>'lastname', 'id'=>'lastname', 'maxlength'=>'100'); echo form_input('lastname'); echo br(1); if(!$this->input->post('lastname')){ echo form_error('lastname');}?></td> </tr> <tr> <td><?php echo form_label('Gender:','gender')?></td> <td><?php $gender_f = array('name'=>'gender', 'type'=>'radio' ,'value'=>'Female'); $gender_m = array('name'=>'gender', 'type'=>'radio' ,'value'=>'Male'); echo form_radio($gender_f).' Female'; echo nbs(3); echo form_radio($gender_m).' Male'; echo br(1); if(!$this->input->post('gender')){ echo form_error('gender');}?></td> </tr> <tr> <td><?php echo form_label('Course:','course')?></td> <td><?php $options = array(''=>'No Course', 'Bachelor of Science in Information Technology'=>'BSIT', 'Bachelor of Science in Computer Science'=>'BSCS', 'Bachelor of Science in Accountancy'=>'BSA', 'Bachelor of Science in Nursing'=>'BSN'); echo form_dropdown('course',$options,''); echo br(1); if(!$this->input->post('course')){ echo form_error('course');}?></td> </tr> <tr> <td><?php echo form_label('Interests:','interest')?></td> <td><?php echo form_checkbox('interest','Music','').' Music'; echo br(1); echo form_checkbox('interest','Art','').' Art'; echo br(1); echo form_checkbox('interest','Speech','').' Speech'; echo br(1); echo form_checkbox('interest','Logic','').' Logic'; echo br(1); if(!$this->input->post('interest')){ echo form_error('interest');}?></td> </tr> <tr> <td><?php echo form_label('Description:','desc')?></td> <td><?php $data_textarea = array('type'=>'textarea', 'name'=>'desc', 'row'=>5, 'cols'=>25); echo form_textarea($data_textarea); echo br(1); if(!$this->input->post('desc')){ echo form_error('desc');}?></td> </tr> <tr> <td><?php echo form_label('Username:','username')?></td> <td><?php $data_input = array('class'=>'input-large', 'name'=>'username', 'id'=>'username', 'maxlength'=>'100'); echo form_input($data_input); ?> <span id="usr_verify" class="verify"></span><?php echo br(1); if(!$this->input->post('username')){ echo form_error('username');}?></td> </tr> <tr> <td><?php echo form_label('Password:','password')?></td> <td><?php $data_pass = array('class'=>'input-large', 'name'=>'password', 'id'=>'password', 'maxlength'=>'100', 'type'=>'password'); echo form_password($data_pass); echo br(1); if(!$this->input->post('password')){ echo form_error('password');}?></td> </tr> <tr> <td colspan="2"><center> <?php $submit_data = array('type'=>'submit', 'class'=>'white button', 'name'=>'submit_form', 'value'=>'Submit!'); echo form_submit($submit_data); $reset_data = array('type'=>'reset', 'class'=>'white button', 'name'=>'reset_form', 'value'=>'Reset!'); echo form_reset($reset_data);?></center> </td> </tr> <?php form_close();?> </table> </div> </div> [/code] I don't know where I go wrong, it could give an error message for require fields but for the other rules that I set especially to the user and password, it won't display an error message
  10. Having problems in dealing with flexigrid with a CRUD CodeIgniter implementation. I've just discovered the grocery CRUD already, but still... i'm confuse all about it.
  11. I'm just a newbie with this CodeIgniter framework and I'm currently working on a simple registration form. Right now, I have a difficulty in displaying css designs. Where would be my css folder will be placed that can have a short location in placing the href tag?
  12. How do the tumblr or wix site do the customizing stuff? what kind of language did they in building their own website builder, just like wix.com
  13. I'm planning to make a simple website wherein users can have their own page with the help of my web service. Right now, I'm quite confuse of would be the exact term of this kind of function, wherein a certain user's page template design can be changed by choosing different themes that's given by the web site. Best example would be the tumblr: I want to edit my tumblr site to be edited through uploading images in header, or... just use the random templates that's given by the tumblr themes.
  14. I already do the same method but it isn't successful.
  15. Yeah, but for the meantime I would like to fix the error that I made from my program
  16. I already had this snippet code in adding users if(isset($_POST['add_user'])){ $passw = trim(htmlentities($_POST['password'])); $encrypted = enc_salt($passw); $con = "true"; $sql = "SELECT * FROM users WHERE username='".$_POST['user_name']."'"; $result = $database->query($sql); $row = $database->fetch_array($result); if($row!=""){ $con="false"; } if($con!="false"){ $sql = "INSERT INTO photo_gallery.users (username, password, first_name, last_name)"; $sql .= " VALUES ('".trim(htmlentities($_POST['user_name']))."','".$encrypted."', '".trim(htmlentities($_POST['first_name']))."', '".trim(htmlentities($_POST['last_name']))."')"; $result_set = $database->query($sql); echo '<script type="text/javascript">alert("Account Created!");</script>';} else{ echo '<script type="text/javascript">alert("This username already exist!");</script>'; } } where my function enc_salt is: function enc_salt($string){ //encrypting $pass_word = sha1($string); $salt = md5("user"); $pepper = "cxlkdawpoalsk"; $pass_encrypted = $salt.$pass_word.$pepper; return $pass_encrypted; } my problem right now is when it's time the user login to the website.
  17. How to have password encryption and password salting in your login?
  18. Been searching for days for this fix already but still can't manage to change function. here's the pagination happened: <?php require_once("../../includes/initialize.php"); ?> <?php if (!$session->is_logged_in()) { redirect_to("login.php"); } ?> <?php // Find all the photos //$photos = Photograph::find_all(); ?> <?php $id = isset($_GET['album_id']) ? $_GET['album_id'] : ""; $page = !empty($_GET['page']) ? (int)$_GET['page'] : 1; $per_page = 10; $total_count = Photograph::count_all_photosin_album($id); $pagination = new Pagination($page, $per_page, $total_count); $sql = "SELECT * FROM photo_gallery.photographs WHERE album_id='".$id; $sql .= "' LIMIT {$per_page} "; $sql .= "OFFSET {$pagination->offset()}"; $photos = Photograph::find_by_sql($sql); ?> <html lang="en"> <head> <meta charset="utf-8"> <title>Photo Gallery</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="description" content=""> <meta name="author" content=""> <!-- Le styles --> <link href="../stylesheets/bootstrap.css" rel="stylesheet"> <link href="../stylesheets/main.css" rel="stylesheet"> <style> body { padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */ } </style> </head> <body> <div class="navbar navbar-fixed-top"> <div class="navbar-inner"> <div class="container"> <a class="brand" href="index.php">Photo Gallery</a> <div class="nav-collapse"> <ul class="nav"> <li><a href="index.php">Home</a></li> <li><a href="../index.php">Gallery of Photos</a></li> <li class="active"><a href="list_photos.php">List of Photos</a></li> <li ><a href="manage_album.php">Albums</a></li> <li><a href="manage_account.php">Accounts</a></li> <li><a href="logfile.php">View Log File</a></li> <li><a href="logout.php">Logout</a></li> </ul> </div><!--/.nav-collapse --> </div> </div> </div> <div class="container"> <?php echo output_message($message); ?> <h2>Album "<?php $album_na = Album::get_album_name($id); echo $album_na; ?>"</h2> <br/> <ul class="gallery"> <?php foreach($photos as $photo): ?> <li> <div class=""> <a href="photo.php?id=<?php echo $photo->id; ?>"> <?php echo '<span></span> <img src="../images/'.$photo->filename.'"alt="image"/>'; ?> </a> </div></li> <?php endforeach; ?> </ul> <br /> <div id="number_of_photos"> <?php echo "There are <font color='red'>" . $total_count. "</font> photos"; ?> </div> <br/> <div id="pagination" style="clear: both;"> <?php if($pagination->total_pages() > 1) { if($pagination->has_previous_page()) { echo "<a href=\"photos_album.php?page="; echo $pagination->previous_page(); echo "\">« Previous</a> "; } for($i=1; $i <= $pagination->total_pages(); $i++) { if($i == $page) { echo " <span class=\"selected\">{$i}</span> "; } else { echo " <a href=\"photos_album.php?page={$i}\">{$i}</a> "; } } if($pagination->has_next_page()) { echo " <a href=\"photos_album.php?page="; echo $pagination->next_page(); echo "\">Next »</a> "; } } ?> </div><br/> </div> <?php include_layout_template('admin_footer.php'); ?> my pagination class: <?php class Pagination { public $current_page; public $per_page; public $total_count; public function __construct($page=1, $per_page=20, $total_count=0){ $this->current_page = (int)$page; $this->per_page = (int)$per_page; $this->total_count = (int)$total_count; } public function offset() { return ($this->current_page - 1) * $this->per_page; } public function total_pages() { return ceil($this->total_count/$this->per_page); } public function previous_page() { return $this->current_page - 1; } public function next_page() { return $this->current_page + 1; } public function has_previous_page() { return $this->previous_page() >= 1 ? true : false; } public function has_next_page() { return $this->next_page() <= $this->total_pages() ? true : false; } } ?> In the first page, it still display the photos on what my query had stated but when I click the next button already it went crazy! \:
  19. I'm having an album_id property in my photo table which is connected to my album table that has a album_id property as well (: Thanks for the help!
  20. I already transfer the deleting of photos in the database right after deleting the photos in the directory <?php require_once("../../includes/initialize.php"); ?> <?php if (!$session->is_logged_in()) { redirect_to("login.php"); } ?> <?php $photo = Photograph::count_all_photosin_album($_GET['album_id']); if(empty($_GET['album_id'])){ $session->message("No album ID was provided."); redirect_to('list_album.php'); } else{ if($photo>0){ echo "DELETE"; $sql="DELETE FROM album WHERE album_id='".$_GET['album_id']."'"; $result = $database->query($sql); $sql3 = "SELECT * FROM photographs WHERE album_id='".$_GET['album_id']."'"; $result3 = $database->query($sql3); while($row=mysql_fetch_array($result3)){ $target_path =SITE_ROOT.DS."public".DS. "images/".$row['filename']; unlink($target_path); echo "SUCCESS!"; $sql2="DELETE FROM photographs WHERE album_id='".$_GET['album_id']."'"; $result2 = $database->query($sql2); } } else{ } } ?> <?php if(isset($database)) { $database->close_connection(); } ?> but still, the same problem \:
  21. In this program, i would be deleting all images in an album if ever I would choose to delete an album where there's photos in it. <?php require_once("../../includes/initialize.php"); ?> <?php if (!$session->is_logged_in()) { redirect_to("login.php"); } ?> <?php $photo = Photograph::count_all_photosin_album($_GET['album_id']); //$album = Album::find_by_id($_GET['album_id']); if(empty($_GET['album_id'])){ $session->message("No album ID was provided."); redirect_to('list_album.php'); } else{ if($photo>0){ $sql="DELETE FROM album WHERE album_id='".$_GET['album_id']."'"; $result = $database->query($sql); $sql2="DELETE FROM photographs WHERE album_id='".$_GET['album_id']."'"; $result2 = $database->query($sql2); $sql3 = "SELECT * FROM photographs WHERE album_id='".$_GET['album_id']."'"; $result3 = $database->query($sql3); while($row=mysql_fetch_array($result3)){ $photo_id = Photograph::find_by_id($_GET['album_id']); if($photo_id && $photo_id->destroy()){ echo "SUCCESS!"; } } } else{ } } ?> <?php if(isset($database)) { $database->close_connection(); } ?> I already delete the images from my photo table in mysql and also the album record in my album table in mysql but I was unable to delete the images from that album in my directory \:
  22. So I was creating a simple photo gallery site, wherein users can upload their photos or delete their photos. While, I have a CRUD functions as well in the side of the users, where I can add users, delete users, update user's info and search user's info. Now, I want photos that will be organized by an album. And so I created a table in MySQL Database an 'album' table where there's album_id, album_name and album_desc propert in it. And, I also add a property to my photo class an album_id property. Also, I have an album class, which this is my problem. What should be the content of my album class? How will I organize those photos by an album? <?php require_once(LIB_PATH.DS.'database.php'); class Album extends DatabaseObject{ protected static $table_name="album"; protected static $db_fields=array('album_id', 'album_name', 'album_desc'); public $id; public $name; public $desc; public static function find_all() { return self::find_by_sql("SELECT * FROM ".self::$table_name); } public static function find_by_id($id=0) { $result_array = self::find_by_sql("SELECT * FROM ".self::$table_name." WHERE id={$id} LIMIT 1"); return !empty($result_array) ? array_shift($result_array) : false; } public static function find_by_sql($sql="") { global $database; $result_set = $database->query($sql); $object_array = array(); while ($row = $database->fetch_array($result_set)) { $object_array[] = self::instantiate($row); } return $object_array; } public static function count_all() { global $database; $sql = "SELECT COUNT(*) FROM ".self::$table_name; $result_set = $database->query($sql); $row = $database->fetch_array($result_set); return array_shift($row); } private static function instantiate($record) { $object = new self; foreach($record as $attribute=>$value){ if($object->has_attribute($attribute)) { $object->$attribute = $value; } } return $object; } private function has_attribute($attribute) { return array_key_exists($attribute, $this->attributes()); } protected function attributes() { // return an array of attribute names and their values $attributes = array(); foreach(self::$db_fields as $field) { if(property_exists($this, $field)) { $attributes[$field] = $this->$field; } } return $attributes; } protected function sanitized_attributes() { global $database; $clean_attributes = array(); foreach($this->attributes() as $key => $value){ $clean_attributes[$key] = $database->escape_value($value); } return $clean_attributes; } public function create_album() { global $database; $sql = "INSERT INTO ".self::$table_name." ("; $sql .= join(", ", array_keys($attributes)); $sql .= ") VALUES ('"; $sql .= join("', '", array_values($attributes)); $sql .= "')"; if($database->query($sql)) { $this->id = $database->insert_id(); return true; } else { return false; } } public function delete_album() { global $database; $sql = "DELETE FROM ".self::$table_name; $sql .= " WHERE id=". $database->escape_value($this->id); $sql .= " LIMIT 1"; $database->query($sql); return ($database->affected_rows() == 1) ? true : false; } } ?> Also, I have a album_view_this.php wherein. I have this snippet code and got an error with it. <?php $albums = Album::find_all(); ?> <table class="bordered" cellpadding="10"> <tr> <th>ID</th> <th>USER</th> <th>NAME</th> <th> </th> <th> </th> </tr> <tr> </tr> <?php $count=0; foreach($albums as $album): $count++; ?> <tr> <td><?php echo $albums->album_id;?></td> </tr> </table
  23. Actually, I didn't use the the binary data method in saving images into mysql. I just simple use the insert method w/o using the MEDIUMBLOB or blob at all.
  24. I have difficulty on what column or in what table will I add a column where photos of that certain users will be saved in MySQL I have already a table of ALBUM (where there's album id) and a table of PHOTOGRAPH (where there's album id also). What will I do for my Schema where I can save all those photos from this certain user?
×
×
  • 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.