-
Posts
17 -
Joined
-
Last visited
Posts posted by louie35
-
-
Is the directory created and if YES, does it have the write permission 0777?
-
if you don't want to upload the image because it's already there, just use the browse field form option but do nothing with the image itself but just grab the name of the image and insert it into the DB
this will be your form...<form action="upload_file.php" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file" id="file"><br> <input type="submit" name="submit" value="Submit"> </form>
php code for getting the file name...
//GRAB THE FILE NAME $imgName = $_FILES["file"]["name"];
... and store it into the DB without the uploading feature
-
good point and thanks again.
Find this classes thing really frustrating.
I can do anything with the old functions style and I am pretty good at it, the reason I never moved to the new version , but I kind of have to... I suppose.
I can also work with classes from a framework, but just never created my own.
-
That result, I suppose is coming for a database so you need to put the code in the while... loop before it gets echoed into the page
Also, it depends how you store it as well, 1 = true ...... y = y so you can modify my code to:$result = $result['isProcessed'] || $result['isProcessed'] == "y" ? "yes" : "n/a";
-
print the array and let me see it
print_r($result['isProcessed']);
-
unset($phrases[$ran_Num]); -
$result = $result['isProcessed'] ? "yes" : "n/a";
echo "<td>".$result."</td>"; -
First I don't get "atitle" and "acontent" in your code
Second use this function and see if it works better:
function cleanStr($str){ $str = trim($str); if($str == "") return; $str = stripslashes($str);//STRIP \ slashes if (function_exists(mysqli_real_escape_string)){ $str = mysqli_real_escape_string($str); }else{ $str = mysql_real_escape_string($str); } //CONVERT TO HTML $str = htmlspecialchars($str); //LAST CLEAN UP $str = preg_replace("#\'#","",$str); return $str; }
usage:
$error = array(); $title = !empty($_POST['title']) ? cleanStr($_POST['title']) : ""; $content= !empty($_POST['content']) ? cleanStr($_POST['content']) : "your text here"; if($title == ""){ $error[] = "Title required"; } if(count($_POST)>0 && !empty($error)){ foreach($error as $x=>$y){ echo $y."<br />"; } }else{ //EXECUTE THE INSERT CODE HERE.... }
Let me know how it's working for you
-
I rec the best approach is a cookie or a database table... the second being more robust
-
You have 2 options here:
strip them off using preg_replace
$field_name = preg_replace("#\'#","",$_POST['field_name']);
or convert them to html characters
$field_name = htmlspecialchars($_POST['field_name']);
-
http://stackoverflow.com/questions/1200972/mysql-real-escape-string-and-single-quote
have a look at the options here and use best one that suit you
-
your use of properties is suspect. the point of properties (class variables) are for things that must be referenced from outside of where they are assigned. this includes values that are used in more than one method inside the class and values you want to reference in the scope of where your class is called. none of your properties are referenced outside the method where they are created. you don't need to use a property for every variable. local variables inside of methods are perfectly valid. in the code you posted, there's no need for any of the properties you have shown.
the only thing that is dynamic in the code you posted is the content section (though the <title> ... </title> should be.) the rest of your code is just a page layout/template that you have broken up and wrapped class methods around, requiring more code to produce the result. your class methods/properties should be concerned with accepting the input that is dynamic, preforming the processing you need on that input (using htmlentities() on the text you output on a page would be some good processing to include in your code), and returning the result.
the main code that uses your class should be only concerned with USING your class and it should be as simple as possible. your main code should not care about things that don't involve information that doesn't change. your header/footer add code is completely static and your main code shouldn't know or care about that. you main code should only be -
<?php include " your class definition file "; $mob_page = new create_page(); //add dynamic content to the page template and echo the result echo $mob_page->new_page("page1", "content - can be dynamic or static :)", "footer");
I thought it will be good practice to set the variables in advance, even if they are empty values.
For the last part, I see your point of the header & footer but this 2 parts contains the main html block of creating a page and also the incuded files needed to make it work.
The reason I used it to create them separate is because in the case of jquery mobile pages, the could be more than one page id accessed by hash key using ajax and cant have 2 doctype in my code, if you know what I mean.
<?php include("_funct_header.php"); $page1 = new create_page(); //add doctype & includes echo $page1->add_header_mob(); //add content to the page $page1->title = '<h1>Home</h1>'; echo $page1->new_page("page1",$page1->title, "content - can be dynamic or static :)", "footer"); /* PAGE 2 */ $page2 = new create_page(); //PAGE HEADER & BACK BUTTON $page2->title = $page2->add_back_btn().'<h1>Header 2</h1>'; //page 2 content echo $page2->new_page("page2", $page2->title, "Content 2", "Footer 2"); //add closing HTML footer echo $page1->add_footer(); ?>
-
first upload the image into a folder, store the image name into the DB.
As the folder will always be the same, you can just define the path
define("IMG_PATH","http://www.website.com/img_folder_path", true);
... usage
<?php $file_name = $rs['file_name'];//coming form your DB table echo '<img src="'.IMG_PATH.$file_name.'" alt="" />'; ?>
-
Thanks cyberRobot...
Got that and changed it to public instead
-
Hi,
I am trying to get the hang of php classes and I thought the best way is to get your hands dirty
I am good at the old php style, functions, array, etc... but when it comes to classes, for some reason i get frustrated and lost
Anyway, I have a website that I want to create a mobile section for it and I am doing that using jquery mobile framework, therefore, i created a small class to create the pages on the fly, based on dynamic content or static, trying to save time and writting the same thing over and over again.
Everything works fine, but I have a feeling my class is not ok so any suggestion will be appreciated.This is the class:
<?php class create_page{ var $_header; var $_includes; var $_footer; var $_page; var $title; var $content; var $footer_txt; function __construct(){ } function add_header_mob(){ $this->_header = '<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Mobile Compare Ireland</title>'.$this->include_files().' </head> <body>'; return $this->_header; } //INCLUDES function include_files(){ $this->_includes = ' <link href="jquery-m/jquery.mobile-1.3.1.min.css" rel="stylesheet" type="text/css"/> <script src="jquery-m/jquery.js" type="text/javascript"></script> <script src="jquery-m/jquery.mobile-1.3.1.min.js" type="text/javascript"></script>'; return $this->_includes; } //FOOTER function add_footer(){ $this->_footer = ' </body> </html>'; return $this->_footer; } //CREATE PAGE CONTENT SHELETON function new_page($title,$content,$footer_txt){ $this->title = $title; $this->content = $content; $this->footer_txt = $footer_txt; $this->_page = ' <div data-role="page" id="page"> <div data-role="header"> <h1>'.$this->title.'</h1> </div> <div data-role="content">'.$this->content.'</div> <div data-role="footer"> <h4>'.$this->footer_txt.'</h4> </div> </div> '; return $this->_page; } } ?>
... and this is the implementation of it
<?php include("_funct_header.php"); $mob_page = new create_page(); //add doctype & includes echo $mob_page->add_header_mob(); //add content to the page echo $mob_page->new_page("page1", "content - can be dynamic or static :)", "footer"); //add footer echo $mob_page->add_footer(); ?>
...So what am I missing?
-
After fetching a page I use preg_match to get all the links from it and I end up with this arrays:
$urlpattern = "/<a[\s]+[^>]*?href[\s]?=[\s\"\']+(.*?)[\"\']+(.*?)>([^<]+|.*?)?<\/a>/"; //match the links preg_match_all($urlpattern, $str, $matches); //using foreach.... [0] => <a href="http://www.domain.com/" title="title text">link text</a> [1] => <a href="http://www.domain.com/" title="title text">link text</a> [2] => <a href="http://www.domain.com/" title="title text">link text</a> [3] => <a href="http://www.domain.com/" title="title text">link text</a> [4] => <a href="http://www.domain.com/" title="title text">link text</a>
What I need to donow is extract each part and check the values as listed below:
1. href value
2. title value
3. link text value
and display them one by one:
link: href - title (if any): title - anchor text: link text
but I can not seem to get my head arround it. Any Pointers?
Storing image path for retrieval and display using php
in PHP Coding Help
Posted
Write and SQL INSERT query
http://www.w3schools.com/php/php_mysql_insert.asp