Jump to content

Silence~

Members
  • Content Count

    21
  • Joined

  • Last visited

Community Reputation

0 Neutral

About Silence~

  • Rank
    Newbie
  • Birthday 12/21/1996

Profile Information

  • Gender
    Male
  • Location
    SG
  1. I'm having trouble with getting the image in the right order. I'm trying to filter images gotten from the database based on the button link. I got the reference from http://www.evoluted.net/thinktank/web-development/jquery-filtering. I have about 20+- buttons and for each button, I am getting all the picture that is being under that filter button through database. (Not sure where to post this, but I think it's more suited to be under css). Basically, I have gotten the css all wrong (my css is basic too ><), so I hope you could help me(where i have gone wrong) and give some pointers. Here is css: /*- FILTER OPTIONS -*/ul#filterOptions { width: auto; height: auto; margin-top: 60px ; ; overflow: hidden; list-style: none;}ul#filterOptions li { height: 52px; margin-right: 2px; float: left;}ul#filterOptions li a { height: 50px; padding: 0 20px; border: 1px solid #999; background: #cfcfcf; color: #fff; font-weight: bold; line-height: 50px; text-decoration: none; display: block; list-style: none;}ul#filterOptions li a:hover { background: #c9c9c9; list-style: none;}ul#filterOptions li.active a { background: #999; list-style: none;}/*- -*//*- OUR DATA HOLDER -*/#filterBody { width: 100%; height: 100%; overflow: hidden; list-style: none;}#filterBody div.item { width: 200px; height: 200px; float: left; text-align: center;}#filterBody div.item h3 { margin-top: 10px; font-size: 16px; line-height: 20px;}/*- -*/ My html/php code looks like this (example of 1 button): <!----------------- The filter buttons will be these--------------------------> <ul id="filterOptions"> <li class="active"><a href="#" class="all">All</a></li> <li><a href="#" class="IS_1">C#</a></li> <li><a href="#" class="IS_2">PHP/MySQL</a></li> <li><a href="#" class="IS_3">HTML/CSS</a></li> <li><a href="#" class="IS_4">Java Enterprise Development</a></li> <li><a href="#" class="IS_5">Mobile Application Development</a></li> <li><a href="#" class="IM_1">Web Design</a></li> <li><a href="#" class="IM_2">3D Modelling & Animations</a></li> <li><a href="#" class="IM_3">Graphic Design</a></li> <li><a href="#" class="IM_4">Video Editing</a></li> <li><a href="#" class="IM_5">Motion Graphics & Effects</a></li> <li><a href="#" class="CNET_1">Network Security</a></li> <li><a href="#" class="CNET_2">RB Network Design & Implementation</a></li> <li><a href="#" class="CNET_3">Broadband Access & WAN</a></li> <li><a href="#" class="CNET_4">ICT Infrastructure Management</a></li> <li><a href="#" class="CNET_5">Technopreneurship Project</a></li> <li><a href="#" class="ITSM_1">Virtualisation & Cloud Computing</a></li> <li><a href="#" class="ITSM_2">IT Service Operation & Management</a></li> <li><a href="#" class="ITSM_3">Server Administration & Security</a></li> <li><a href="#" class="ITSM_4">Database Administration & Management</a></li> <li><a href="#" class="ITSM_5">Internet of Things App Development</a></li> <!--<li><a href="#" class=""><?php ?></a></li>--> </ul><!--------------Filtered contents to be through the button--------------------><div id="filterBody"> <!----Filter contecnt of C#------> <div class="item IS_1"> <p> Hello everybody!</p><?php try{ //connect to the database require("Connections/database.php"); // array to hold errors $errors = array(); if(empty($errors)){ //select portfolio picture from database $query = "SELECT p.*, u.skillset FROM portfolio p INNER JOIN userProfile u ON p.user_id = u.user_id WHERE u.skillset LIKE '%C#%' "; //var_dump($query); $stmt = $database->query($query); foreach ($stmt as $row) { //print out the data ?> <div id= "imagesPortfolio"> <img src="<?php print htmlspecialchars($row['imagePath']); ?>" width="100" height="100"> </div> <?php //print $row['imageName'] . "t"; //print $row['Name'] . "t"; //foreach($row['picPath'] as $picURL) { //$picURL = $row['picPath']; //'<img src="'. $dir. '/'. $file. '" alt="'. $file. $ //} // print '<img src="'. $picPath. '/'. $file. '" alt="'. $file; //print $row['introduction'] . "n"; } } foreach($errors as $error) { printf("<li>%s</li>", $error); //exit(); } } //end of try block catch(PDOException $e){ // end of database dependent code, handle any errors $status = empty($query) ? 'Connection failed':" Query failed: $query"; // application message trigger_error("$status, Error: {$e->getMessage()}, File: {$e->getFile()}, Line: {$e->getLine()}"); // user message $errors[] = 'Sorry, this page is not working at this time.';}?> <!---The like system implementation----><!-- <div class="like-btn">Like</div> <div class="dislike-btn"></div>--> </div><!------Other buttons same as this buttons, only filter name different--------></div> Is my concept wrong? >< I think i have misinterpreted somewhere, I just can't point out whether it's the css, the php or both ;-; I need to put 6 images in a row, and I'm not sure how to do this in the foreach loop too ><
  2. ...There's no errors, it works fine now. Somehow my data got deleted away in my database.. :| So, it was actually my data that is not there in the first place? But it was there when i tried yesterday ><
  3. I'm not sure what you mean by this, I put var_dump($database) and var_dump($statement) and this is the results: object(PDOStatement)#2 (1) { ["queryString"]=> string(99) "SELECT * FROM userProfile WHERE user_id in ( select id from users where id = 1)" }
  4. Hmm it still give the same dump: object(PDO)#1 (0) { } ;-; I'm confused why though
  5. Nope I didn't. I get the error message beside the one I stated above: if (!$row = $statement->fetch(PDO::FETCH_ASSOC)) { print_r ("No Data to show. Please add in your profile. Navigate your way through the left side of the page where the navigations are.");} Oh okay, thanks for the explanation
  6. My database file looks like this: try {$user = ""; //taken out just in case$pass = "";$database = new PDO('mysql:host=localhost;dbname=final_year_project_1;charset=utf8', $user, $pass, array(PDO::ATTR_EMULATE_PREPARES => false,PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));}catch (PDOException $ex) { echo 'Connection failed: ' . $ex->getMessage();} When you mean open the connection, i just have to require the file right? Must I put it in the try catch?(because I already put it in the database file?) or like put the search code and the select code together? I close it because i thought that it can be sql inject(or something like that) ? ;-;
  7. Ah yes, thank you! This was one of the cause >< But why would that affect though? I thought by requiring the database connection again, it should be okay?Anyways, it gives this: object(PDO)#1 (0) { } for the vardump. I have data inside though?
  8. Tried it and it says null. Does that mean my database connection being null or my query being null? It works though if i didn't put the search code in.. o.o
  9. I'm receiving this error 'Call to a member function prepare() on null' if I were to put this search code into the page. It works fine if i were to put at other pages(for inserting to database).Here's my search code that I've put before the html tags: <?php//echo '<pre>';//echo $_POST;//echo '</pre>';//declare the form name//$searchForm = htmlentities($_SERVER['PHP_SELF']);try { //inserts database connections require('Connections/database.php'); if (($_SERVER['REQUEST_METHOD'] == 'POST') && isset($_POST['search'])) { // array to hold errors $errorsSearch = array(); //create a bad word array $badwords = array('######','damn','mother######er','###### you'); //Declare variables $search = $_POST['search']; //Validations for the $_POST //check if it's blank if (trim($search) == "" || !isset($search)) { $errorsSearch[] = ("Search is blank!"); } //Check if the text to search is too long if (isset($search) && strlen(trim($search)) > 50) { $errorsSearch[] = ("The text to search is too long!"); } //Check for any vulgarities if (isset($search) && in_array($search,$badwords)) { $errorsSearch[] = ("No vulgarities!"); } if (empty($errorsSearch)) { //Declare the sql query $query = "SELECT * FROM portfolio WHERE nameOfPortfolio LIKE '%$search%'"; //var_dump($query); $stmt = $database->query($query); $number_of_rows = $stmt->fetchColumn(); if ($number_of_rows == 0) { $errorsSearch[]= ("No results! Sorry, please try again!"); } if ($number_of_rows > 0) { //$errors[] = "There is an existing record. You cannot insert another profile! Either update the old one, or delete to insert again."; header("Location:searchResults.php"); exit; }} if (isset($errorsSearch) == true) //foreach($errors as $error){ echo "<div id=search_errors>" .implode("<br>", $errorsSearch) . "</div>"; //printf("%s",$error);}} //end of form processing} //end of try methodcatch(PDOException $e){ // end of database dependent code, handle any errors $status = empty($query) ? 'Connection failed':" Query failed: $query"; // application message trigger_error("$status, Error: {$e->getMessage()}, File: {$e->getFile()}, Line: {$e->getLine()}"); // user message $errorsSearch[] = 'Sorry, this page is not working at this time.';}// done with the database, destroy any pdostatment resource and close connection$stmt = null;$database = null; //the html document that uses any data from the above code starts here -?> This is my code for getting the data: <table width="379" border="0" cellspacing="0" cellpadding="0" style=" border-style: solid" > <?php try { //connect to database require_once('Connections/database.php'); //Selecting a single row! $sql = "SELECT * FROM userProfile WHERE user_id in ( select id from users where id = ".($_SESSION['user_id']).")"; //Prepare our SELECT statement. $statement = $database->prepare($sql); //Execute our SELECT statement. $statement->execute(); if (!$row = $statement->fetch(PDO::FETCH_ASSOC)) { print_r ("No Data to show. Please add in your profile. Navigate your way through the left side of the page where the navigations are."); } if (isset($errors) == true) { echo "<div id=add_port_errors>" .implode("<br>", $errors) . "</div>"; }// get method/display code (if any) - get/produce data that's needed to display the page// to edit existing data, if the $data array is empty at this point, retrieve any existing data from the database table?> <tr> <th width="auto" scope="row"><div align="left">Profile Picture:</div></th> <td width="auto"><img src="<?php print htmlspecialchars($row['picPath']); ?>" width="82" height="72"> </td> <td width="auto"><form name="editProfile" method="post" action="editProfile.php"> <input type="submit" name="edit" id="edit" value="Edit"> </form></td> </tr> <tr> <th scope="row"><div align="left">Username:</div></th> <td><label><?php print htmlspecialchars($row['username']); ?></label></td> <td><form name="editProfile" method="post" action="editProfile.php"> <input type="submit" name="edit" id="edit" value="Edit"> </form></td> </tr> <tr> <th scope="row"><div align="left">Name:</div></th> <td><label><?php print htmlspecialchars($row['Name']); ?></label></td> <td><form name="editProfile" method="post" action="editProfile.php"> <input type="submit" name="edit" id="edit" value="Edit"> </form></td> </tr> <tr> <th scope="row"><div align="left">Email:</div></th> <td><label><?php print htmlspecialchars($row['Email']); ?></label></td> <td><form name="editProfile" method="post" action="editProfile.php"> <input type="submit" name="edit" id="edit" value="Edit"> </form></td> </tr> <tr> <th scope="row"><div align="left">ContactNo:</div></th> <td><label><?php print htmlspecialchars($row['ContactNo']); ?></label></td> <td><form name="editProfile" method="post" action="editProfile.php"> <input type="submit" name="edit" id="edit" value="Edit"> </form></td> </tr> <tr> <th scope="row"><div align="left">Skillset:</div></th> <td><label><?php print htmlspecialchars($row['skillset']); ?></label></td> <td><form name="editProfile" method="post" action="editProfile.php"> <input type="submit" name="edit" id="edit" value="Edit"> </form></td> </tr> <tr> <th scope="row"><div align="left">Specialization:</div></th> <td><label><?php print htmlspecialchars($row['Specialization']); ?></label></td> <td><form name="editProfile" method="post" action="editProfile.php"> <input type="submit" name="edit" id="edit" value="Edit"> </form></td> </tr> <tr> <th scope="row"><div align="left">Introduction:</div></th> <td><label><?php print htmlspecialchars($row['introduction']); ?></label></td> <td><form name="editProfile" method="post" action="editProfile.php"> <input type="submit" name="edit" id="edit" value="Edit"> </form></td><?php } //catch(PDOException $e){ // end of database dependent code, handle any errors$status = empty($query) ? 'Connection failed':" Query failed: $query";// application messagetrigger_error("$status, Error: {$e->getMessage()}, File: {$e->getFile()}, Line: {$e->getLine()}");// user message$errors[] = 'Sorry, this page is not working at this time.';}// done with the database, destroy any pdostatment resource and close connection$stmt = null;$database = null; ?> </tr> </table> My database is correct though, I'm using $database for all the connections, i didn't change the variable name. I'm not sure why it wouldn't initialized. Is my select query wrong? ;-;
  10. My apologies. It actually does show the errors, just that it was hiding under my navigation bar. I sorted it out already. Thank you for all the help I need ^^ [is there any way I can mark this as answered?]
  11. Okay, I found out the solution to that error.. I utterly embarrassed myself for not looking through thoroughly >< With the help of this post : http://w3schools.invisionzone.com/index.php?showtopic=47997&p=265892 , I realised I had moved my coding to the starting of html form and that what caused the error since the header location must be located before the html tag. Thanking Ingolme indirectly (Thanks a bunch ) . Anyways, I still can't validate if the file is not image. It won't show the $errors[] either. >< I'm not sure where i go wrong o,o
  12. I'm not sure if i understand it correctly. This is what I've added in : //Allowed typpes to pass through validation $allowedTypes = array('image/jpg', 'image/jpeg', 'imagae/jpe', 'image/png', 'image/gif'); $allowedExtensions = array('jpg', 'jpeg', 'jpe' , 'png', 'gif'); //$ext = explode(".", $filename); // $extension = strtolower(end($ext)); //gets the info of ther file, in this case, extension $extension = pathinfo($filename, PATHINFO_EXTENSION); //return the file mime type $finfo = new finfo(FILEINFO_MIME_TYPE); //check th file for the information (tmp or name) $mimetype = $finfo->file($filetmp); var_dump($mimetype); //Check mimetype and extensions if ((!in_array($mimetype, $allowedTypes)) || (!in_array($extension, $allowedExtensions))) { $errors[] = 'File uploaded does not meet the Type criteria(PNG/JPG/GIF). Please check.'; } else { if (!move_uploaded_file($filetmp,$uploadfile)) { $errors[] = 'File uploaded DOES NOT move to another folder.'; } if(move_uploaded_file($filetmp,$uploadfile)) { return $uploadfile; } } Since I have to compare mimetype and extension, shouldn't this works too? You have put the commented validation $extension below the validation $mimetype, I'm just wondering why though, it can be put together in one line doesn't it? It still shows the $errors inside, still not getting it >< I also have a problem about the move_uploaded_file after playing with the codes(the one you give as an example. I uncomment it). It would trigger the cannot modify headers, headers not sent errors. I have 2 headers , one before validating the user's inputs and another one after inserting it to database: // if no errors at this point, redirect to the exact same url of this page to prevent the browser from resubmitting the data by causing a get request for the page if(empty($errors)){ $host = $_SERVER['HTTP_HOST']; $uri = $_SERVER['REQUEST_URI']; header("Location:addProfile.php?success=1"); exit; } It will always point out the error at the beginning of this code: <?php //This must be out of that form validation. //set error array $errors = array(); if (( isset($_GET['success']) && $_GET['success'] == 1 )) { echo "Successfully added your profile! Please check out your updated profile page."; // if(empty($errors)){ // include ('mailer.php'); // // } } if (( isset($_GET['failure']) && $_GET['failure'] == 1 )) { echo "You have an existing record. Either delete your record, or update/edit your record."; } foreach($errors as $error) { printf("<li>%s</li>", $error); //exit(); } ?> EDIT: I actually am able to save the picture name and path in the database and also in the relative folder. However, it keeps sends the error :" Warning: Cannot modify header information - headers already sent by (output started at... ". I'm not sure what had happen as I only changed this particular codes and the relative path to this: //create the relative folder$uploaddir = 'profilePics/'; //<-- Found a / in the front of /profilePics/ , which keeps giving error that could not move upload file.. (It's gone now though, after I fix it)$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);if ($_FILES['userfile']['error'] === UPLOAD_ERR_OK) { $allowedTypes = array('image/jpg', 'image/jpeg', 'imagae/jpe', 'image/png'); $allowedExtensions = array('jpg', 'jpeg', 'jpe' , 'JPEG', 'JPG', 'JPE', 'PNG', 'png'); //$ext = explode(".", $filename); // $extension = strtolower(end($ext)); //gets the info of ther file, in this case, extension $extension = pathinfo($filename, PATHINFO_EXTENSION); //return the file mime type $finfo = new finfo(FILEINFO_MIME_TYPE); //check th file for the information (tmp or name) $mimetype = $finfo->file($filetmp); var_dump($mimetype); //Check mimetype and extensions in the arrays. if ((!in_array($mimetype, $allowedTypes)) || (!in_array($extension, $allowedExtensions))) { $errors[] = 'File uploaded does not meet the Type criteria(PNG/JPG). Please check.'; } else { if (!move_uploaded_file($filetmp,$uploadfile)) { $errors[] = 'File uploaded DOES NOT move to another folder.'; } if(move_uploaded_file($filetmp,$uploadfile)) { //get the destination now $errors[] = 'File uploaded is '.$filetype.' to another folder.'; //return $uploadfile; } }} I've googled for answers (Here is the reference I checked :http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php/8028979#8028979 , but I am still clueless as ever. There were no missing ; or any whitespaces at the php tags as far as I've checked >< Could anyone tell me what is wrong here? I really suspect the error would've been the move_uploaded_file , but it did save it to the folder/database so I can't say that my suspicion is correct ><
  13. I did another try(before you posted this) and I'm stuck at the same place where they would not detect the extension. Here's my tries : //First Try//tried with 'jpg','png' and 'gif' for both too$allowedTypes = array('image/jpg', 'image/png', 'image/gif'); $ext = explode(".", $filename);$extension = strtolower(end($ext));$finfo = new finfo(FILEINFO_MIME_TYPE);$mimetype = $finfo->file($filetmp);var_dump($mimetype);if (!in_array($mimetype, $allowedTypes) || !in_array($extension, $allowedTypes)) { $errors[] = ('File uploaded does not meet the types criteria(PNG/JPG/GIF). Please check.');}else { move_uploaded_file($filename,$uploadfile); }//Second Try$allowedTypes = array('image/jpg', 'image/png', 'image/gif');$fileInfo = pathinfo($filename, PATHINFO_EXTENSION);if (!in_array($fileInfo,$allowedTypes)) { $errors[] = ('File uploaded does not meet the types criteria(PNG/JPG/GIF). Please check.');}else { move_uploaded_file($filename,$uploadfile); } I tried uploading a png file but I'm not sure where I go wrong, there's no errors except for the $errors I declared in that code. Perhaps I'm missing something logical? ><
  14. So, I tried coding for the image uploading and I have some difficulty on the MIME type. If I did not declare anything of that, I am able to insert to the database(the directory and the name of the file) but the picture would not be inserted to the folder. This are my code: //Declare variables and start validation $fileMaxSize = $_POST['MAX_FILE_SIZE']; $filename = $_FILES['userfile']['name']; $filetype = $_FILES['userfile']['type']; $filesize = $_FILES['userfile']['size']; $filetmp = $_FILES['userfile']['tmp_name']; $fileError = $_FILES['userfile']['error']; $uploaddir = '/profilePics/'; $uploadfile = $uploaddir . basename($_FILES['userfile']['name']);//Check if file is uploaded/issetswitch ($fileError) { case UPLOAD_ERR_OK: //no error, so move on to the uploading process break; case UPLOAD_ERR_INI_SIZE: //This is from the php max size $errors[] = ('The file you attempt to upload exceeds the max size. Please upload a smaller size'); break; case UPLOAD_ERR_FORM_SIZE: //This is from the html form max size we declared. $errors[] = ('The file you attempt to upload exceeds the max size. Please upload a smaller size'); break; case UPLOAD_ERR_PARTIAL: $errors[] = ('The file is partially uploaded. Please try again.'); break; case UPLOAD_ERR_NO_FILE: //no file is uploaded $errors[] = ('File is not uploaded.'); break; case UPLOAD_ERR_NO_TMP_DIR: $errors[] = ('Temporary folder is missing or do not exist. Please contact administrator.'); break; case UPLOAD_ERR_CANT_WRITE: $errors[] = ('Unable to write into the folder. Please try again.'); break; case UPLOAD_ERR_EXTENSION: $errors[] = ('Unable to detect the cause of error. Please try again and if error persist, contact the administrator.'); break;}// if the upload is okay, proceed to move the file.if ($_FILES['userfile']['error'] === UPLOAD_ERR_OK) { //check if the type is correct $finfo = finfo_open(FILEINFO_MIME); // return mime type ala mimetype extension//if not able to return mime typeif (!$finfo) { $errors[] = ('Opening fileinfo database failed');}/* get mime-type for a specific file *///$filename = "/usr/local/something.txt";if (!finfo_file($finfo, $filename)) { $errors[] = ('not sure what to do here.'); }else { move_uploaded_file($filename,$uploadfile); }/* close connection */finfo_close($finfo);}//Insert statement after checking if no errors if(empty($errors)){ $stmt = $database->prepare("INSERT INTO userProfile (picName,picPath,username, Name, introduction, Specialization,skillset, Email, ContactNo, user_Id) VALUES (:picName, :picPath,:username,:Name,:introduction,:Specialization,:skillset,:Email,:ContactNo,:user_Id)");$stmt->bindValue(':picName',$_FILES['userfile']['name']);$stmt->bindValue(':picPath', $uploadfile);$stmt->bindValue(':username',$username);$stmt->bindValue(':Name', $name);$stmt->bindValue(':introduction',$introduction);$stmt->bindValue(':Specialization',$specialization);$stmt->bindValue(':skillset',$skillset);$stmt->bindValue(':Email',$email);$stmt->bindValue(':ContactNo',$contactNo);$stmt->bindValue(':user_Id',$_SESSION['user_id']);$stmt->execute(); I am not sure how to validate the type in line 51. Since this is for profile picture, I wanted it to validate PNG and JPG/jpeg only. I can't seem to achieve that either. My HTML Form: <tr> <th scope="row"><div align="left">Profile Picture:</div></th> <td><!-- MAX_FILE_SIZE must precede the file input field --> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> <!-- Name of input element determines name in $_FILES array --> Send this file: <input name="userfile" type="file" /></td> </tr> (PS: I'm not sure if I should continue posting here since it will get lengthy, but my title already includes the image.. ;-; )
×
×
  • Create New...