Jump to content

fastsol

Moderators
  • Posts

    827
  • Joined

  • Last visited

  • Days Won

    9

Everything posted by fastsol

  1. Are you sure you are actually getting more than a single row? If you do a print_r($ids) at the bottom outside the while(), does it show more than a single id? As for the delete, you're not running a mysql_query, you only made the sql string. Plus if the intention is to run the delete only once using the IN() in the query, then you need to move it outside the while() also. The placement now has it run with every loop of the while(), which is fine to do also but pointless then to use the IN().
  2. You forgot to change the row var on this line to rdate $rdate = $row['date'];
  3. What are the data types of the date and time columns in your DB. If they are normal varchar, then you can't compare dates accurately or time accurately. The column types would need to be in the DATE and TIME format. Also, although they are not mysql reserved words, using date and time for column names isn't a great idea in my opinion. Because they have specific values and/or funcitons in php it can get messy trying to debug when you're calling things the same names as reserved words/thing in the programming language. Assigning such things to variables is different, but using them as static names is bad. My 2 cents worth.
  4. Why is the date and time stored separately in the db? Usually they are stored together as they tend to be the same thing. Maybe it would be helpful for us to see an example of a few rows from the db and how/why the rows should be "SELECT" together in your mind.
  5. Wow that is weird. I tried to make it work too and I can't figure out why it won't. It works in normal chrome and firefox. I found this post about the possible issue iwth the chrome emulator http://stackoverflow.com/questions/26888751/chrome-device-mode-emulation-media-queries-not-working So I don't think it's your code, but rather the browser.
  6. There's a lot more code needed to achieve what you want. If you don't understand how to upload files via a form, I would suggest checking out phpacademy on youtube and watch some of his tutorials on the subject. Once you understand how to actually upload the file, then I would suggest simply storing the file on your server and just use a <img> tag with an absolute url in the href to view the image rather than sending the file in the email too. Sending email file attachments is a whole other subject in itself. One key piece of info, you'll want to set a couple additional headers in the email code. One specific would be the Content-Type of text/html. You can google stuff on that. But if you really want to make it easier in the long run and learn some too, get PHPMailer and use that to send your emails. It will automatically include all the needed things to properly send an email, it will also allow you to do easy attachments if you really wanted.
  7. With this method though, I'm not using it to get the array based on the request method, but rather the ability to get any or the arrays at any time. Hence the reason for the $name.
  8. It's a bit hard to figure out from what you've provided in the code files. In one function page you are using mysql and connecting with in each function, which is not a wise idea. Then in the search file you seem to be using PDO, but I can't know for sure cause there isn't any connection info in that page or the other function page. So why the 2 different connection types? As for your problem at hand, have you tried echoing the $sql var just before this line to see if the query string is constructed properly and has the values you expect it to? $searchResults = $db->query($sql); Plus you're not sanitizing the search data in any way, so you're wide open for sql injection. You should be using PDO and prepared statements, not mysql since those functions are now deprecated as of PHP5.5 and honestly haven't been a normal used group of functions for several years now.
  9. There isn't really any other way when using something like tinymce texteditor, at least from what I know.
  10. I have run into the same thing before and this is how I did it. Granted with this method you would need to always format the portion you want to show in it's own <div> or <p>. preg_match("/<p>(.*)<\/p>/U", $a['art_body'], $matches); echo '<p>'.$matches[1].'..... </p>'; This basically finds the first <p> and </p> and grabs everything inside of it and assigns it to $matches. If you want it to find the div instead then just change that in the preg_match expression.
  11. Yes you certainly could create the file on the fly, you just need to provide the entire code for the file in the setup.php. In the end, either way produces the same result.
  12. Your assumption is most likely correct, but it's impossible for us to say for sure with a single line of code. Typically vars like POST, GET and REQUEST are wrapped in an if() block or checked with isset() before setting their value to another var. The error is just saying that there is no global / superglobal set with the name of "movement".
  13. I don't believe that's how it works. It would be easier to just use set_cookie() and assign the according info you need. Obviously with cookies (granted it would be the same if your original method had worked) you can't trust the values, so they would need to be validated in any instance.
  14. Well after a couple weeks of messing around and reconstructing my cms to use the new Input class and working out the bugs, I have a final product (at least for now, always improving ). class Input { protected $post = array(); protected $get = array(); protected $_p = 'post'; protected $_g = 'get'; protected $_casts = array('int', 'integer', 'string', 'object', 'float', 'array', 'null', 'boolean', 'bool'); function __construct() { $this->post = $_POST; $this->get = $_GET; } public static function super($name) { switch($name) { case 'post': $array = $_POST; break; case 'get': $array = $_GET; break; } return $array; } // Checks is the given $name isset(). Defaults to $_POST unless $type is given // Returns TRUE if the var IS set, FALSE if NOT set. // Type can be post or get public function is_set($name, $type = 'post') { return isset($this->{$type}[$name]); } // Returns TRUE if IS set, FALSE if NOT set // Must provide a name with a | and single letter notation of p, g, c, s (i.e name|p) public static function exists($name) { return self::set_type($name, 'exists'); } // Returns TRUE if NOT set, FALSE if IS set // Must provide a name with a | and single letter notation of p, g, c, s (i.e name|p) public static function notExists($name) { return self::set_type($name, 'notExists'); } // Returns TRUE if var is NOT empty, and FALSE if IS empty // Must provide a name with a | and single letter notation of p, g, c, s (i.e name|p) public static function hasVal($name) { return self::set_type($name, 'hasVal'); } // Returns TRUE if var IS empty, and FALSE if NOT empty // Must provide a name with a | and single letter notation of p, g, c, s (i.e name|p) public static function noVal($name) { return self::set_type($name, 'noVal'); } // Use this to verify if an array has values. Uses array_filter_recursive to go through the entire multi-dimensional array // Returns TRUE if var is NOT empty, and FALSE if IS empty // Must provide a name with a | and single letter notation of p, g, c, s (i.e name|p) public static function arrayHasVal($name) { return self::set_type($name, 'arrayHasVal'); } // Use this to verify if an array has values. Uses array_filter_recursive to go through the entire multi-dimensional array // Returns TRUE if var IS empty, and FALSE if NOT empty // Must provide a name with a | and single letter notation of p, g, c, s (i.e name|p) public static function arrayNoVal($name) { return self::set_type($name, 'arrayNoVal'); } // Checks is the given $name has an empty value. Defaults to $_POST unless $type is given // Returns TRUE if var the IS empty, FALSE if NOT empty. // Type can be post or get public function is_empty($name, $type = 'post') { return empty($this->{$type}[$name]); } // Checks is the given $name has an empty value. Defaults to $_POST unless $type is given // Returns TRUE if var the is NOT empty, FALSE if IS empty. // Type can be post or get public function not_empty($name, $type = 'post') { return !empty($this->{$type}[$name]); } // Returns the value of the given name and type // Must provide a name with a | and single letter notation of p, g, c, s (i.e name|p) public static function val($name) { return self::set_type($name, 'val'); } // Splits the $name to grab the type of superglobal requested protected static function split_name($name) { return explode('|', $name); } // Grabs the superglobals array for the given type. protected static function set_type($type, $func = '') { $split = self::split_name($type); if(count($split) == 2 && !empty($split[1])) { switch($split[1]) { case 'p': $_items = $_POST; break; case 'g': $_items = $_GET; break; case 'c': $_items = $_COOKIE; break; case 's': $_items = $_SESSION; break; } if(!isset($_items)) { throw new Exception('Invalid input type specified for Input::'.$func.'()'); return FALSE; } switch($func) { case 'exists': $return = isset($_items[$split[0]]); break; case 'notExists': $return = !isset($_items[$split[0]]); break; // Only used if the item is an array case 'arrayHasVal': $item = (isset($_items[$split[0]]) && is_array($_items[$split[0]])) ? $_items[$split[0]] : FALSE; $return = !empty(array_filter_recursive($item)); break; // Only used if the item is an array case 'arrayNoVal': $item = (isset($_items[$split[0]]) && is_array($_items[$split[0]])) ? $_items[$split[0]] : FALSE; $return = empty(array_filter_recursive($item)); break; // Should not be used if the value of the item is an array /* Will always return FALSE if an array is given to prevent warnings being thrown Warnings could easily occur if a user tried to edit a POST or GET element into an array when it shouldn't be. This will prevent the warnings. */ case 'hasVal': $item = (isset($_items[$split[0]]) && !is_array($_items[$split[0]])) ? trim($_items[$split[0]]) : FALSE; $return = ($item == '') ? FALSE : !empty($_items[$split[0]]); break; // Should not be used if the value of the item is an array /* Will always return FALSE if an array is given to prevent warnings being thrown Warnings could easily occur if a user tried to edit a POST or GET element into an array when it shouldn't be. This will prevent the warnings. */ case 'noVal': $item = (isset($_items[$split[0]]) && !is_array($_items[$split[0]])) ? trim($_items[$split[0]]) : TRUE; $return = ($item == '' || (isset($_items[$split[0]]) && is_array($_items[$split[0]]))) ? TRUE : empty($_items[$split[0]]); break; case 'val': $return = (isset($_items[$split[0]])) ? ((is_array($_items[$split[0]])) ? $_items[$split[0]] : trim($_items[$split[0]])) : FALSE; break; default: $return = (isset($_items[$split[0]])) ? $_items[$split[0]] : FALSE; } return $return; } else { throw new Exception('No input type provided for Input::'.$func.'()'); return FALSE; } } /* Returns an input value. $name is the key name to return $type is the input type (get or post) at this time. $clean set to TRUE will use the sanitize function then return. $cast will cast the value to the given $cast type i.e. int, string */ protected function input_value($name, $type, $clean, $cast) { if($this->is_set($name, $type) === TRUE) { if($clean === TRUE) { $this->{$type}[$name] = sanitize($this->{$type}[$name]); } elseif(!empty($cast) && in_array($cast, $this->_casts)) { $this->cast($name, $type, $cast); } } return $this; } public function cast($name, $type = 'post', $cast) { (in_array($cast, $this->_casts)) ? settype($this->{$type}[$name], $cast) : ''; return $this; } public function setBool($name, $type = 'post') { return ($this->is_set($name, $type)) ? 1 : 0; } // Returns all input values for the given $type // Type can be post or get public function all($type) { return $this->$type; } // Returns the value for the given $name or FALSE if the name is not set in the $_POST array. // Set argument 2 to TRUE to automatically use the sanitize() on the returned value. // Set agument 3 to a valid $_casts type to automatically settype() the returned value. public function post($name, $clean = FALSE, $cast = FALSE) { $this->input_value($name, $this->_p, $clean, $cast); return ($this->is_set($name)) ? $this->post[$name] : FALSE; } // Returns the value for the given $name or FALSE if the name is not set in the $_GET array. // Set argument 2 to TRUE to automatically use the sanitize() on the returned value. // Set agument 3 to a valid $_casts type to automatically settype() the returned value. public function get($name, $clean = FALSE, $cast = FALSE) { $this->input_value($name, $this->_g, $clean, $cast); return ($this->is_set($name, $this->_g)) ? $this->get[$name] : FALSE; } // Used to check if a form has been submitted by checking for the given $button_name public function submitted($button_name = 'submit', $type = 'post') { return ($this->is_set($button_name, $type) == TRUE) ? TRUE : FALSE; } } It ended up being a mixture of a couple similar methods, static and regular. I wanted to be able to use a few static methods through out the cms constantly without having to instantiate a global var or on each page I needed it. Those statics are generally for basic quick checking if a var is empty or set and getting it's value to run a block of code. I am no expert in php but am no dummy either, but I did learn a lot about classes building this. I tested each method along the way with different scenarios to make sure it always returned the proper value it was designed for, lord knows there were a few that didn't initially and needed to be edited after the fact, but that's part of building and testing. I even threw in a couple custom exceptions for certain methods to help with debugging when using the class in the future. If anyone has more critique or suggestions on how to improve it, I am all ears.
  15. This doesn't work. You can't use variable variables on superglobals like POST and GET, I've tried and it states it in the php manual too. I understand why you see this as a solution but I still can't imagine an instance that you would ever need to update/change the posted array. That data is provided by the user, so why would you want/need to modify it, then it wouldn't be what they sent you. You could simply assign the added value to another variable in the script or have it posted as a hidden input in the first place.
  16. Well yeah, but that's how the entire php language works too, so I'm not seeing your point. I can't think of an reason or instance (at least for POST, GET anyway) that you would directly modify the original array. Typically any modification to an orignal array element, like POST and GET, would be assigned to a new var anyway, still leaving the original array intact. I am very interested in a real world scenario if you can provide one
  17. I'm not sure what you're getting at with your last post. The construct is setting internal vars from the globals already. At this moment I have only chosen to focus on get and post. I am researching other reasons why the other super globals might be useful within the class or an extended class.
  18. After some more review, there isn't a need for the switch() or in_array() in the is_set method. A simple one line isset works just as good. public function is_set($name, $type = 'post') { return (isset($this->{$type}[$name])) ? TRUE : FALSE; } Same goes for the is_empty method public function is_empty($name, $type = 'post') { return (empty($this->{$type}[$name])) ? TRUE : FALSE; } Any other suggestions are very welcomed.
  19. No, your case example would not work. I am dynamically setting the $this-> var, so it needs the full version I have. I do like the in_array method though, I didn't consider that when designing, might be easier to understand too.
  20. I am trying to build a Input class mainly for POST and GET. I am not real proficient with classes. I know I don't understand a number of the principles of a class but I am learning. This is just a fairly basic class that I will expand on over time. Could those of you that know a good amount about classes please review the code for me and hopefully give me some pointers and point out any real shortcomings, blah blah. class Input { protected $post = array(); protected $get = array(); protected $_p = 'post'; protected $_g = 'get'; function __construct() { $this->post = $_POST; $this->get = $_GET; } // Checks is the given $name isset(). Defaults to $_POST unless $type is given public function is_set($name, $type = 'post') { switch($type) { case $this->_p: return (isset($this->{$this->_p}[$name])) ? TRUE : FALSE; break; case $this->_g: return (isset($this->{$this->_g}[$name])) ? TRUE : FALSE; break; default: return FALSE; } } // Checks is the given $name has an empty value. Defaults to $_POST unless $type is given public function is_empty($name, $type = 'post') { switch($type) { case $this->_p: return (empty($this->{$this->_p}[$name])) ? TRUE : FALSE; break; case $this->_g: return (empty($this->{$this->_g}[$name])) ? TRUE : FALSE; break; default: return FALSE; } } protected function input_value($name, $type, $clean) { if($name !== FALSE) { if($this->is_set($name, $type) === TRUE) { return ($clean === TRUE) ? sanitize($this->{$type}[$name]) : $this->{$type}[$name]; } else { return FALSE; } } else { return $this->all($type); } } // Returns all input values for the given $type protected function all($type) { return $this->$type; } // Returns the value for the given $name or FALSE if the name is not set in the $_POST array. // Will return all $_POST vars if no $name is given. public function post($name = FALSE, $clean = FALSE) { return $this->input_value($name, $this->_p, $clean); } // Returns the value for the given $name or FALSE if the name is not set in the $_GET array. // Will return all $_GET vars if no $name is given. public function get($name = FALSE, $clean = FALSE) { return $this->input_value($name, $this->_g, $clean); } public function files() { } // Used to check if a form has been submitted by checking for the given $button_name public function submitted($button_name = 'submit', $type = 'post') { return ($this->is_set($button_name, $type) == TRUE) ? TRUE : FALSE; } }
  21. In your particular case with this code, it would be best to wrap the entire mysql connection (open to close) in an if() that checks if the form has been submitted yet. At this time the page is trying to run the insert query as soon as the page loads, but the post vars don't exist yet cause you haven't submitted the form. if(isset($_POST['Submit'])) { // Connect to the database $con = mysqli_connect("localhost","root","","Oefentoets1"); $naam = $_POST['Naam']; $score = $_POST['Score']; // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $sql = "INSERT INTO Scores (Naam, Score) VALUES ('$naam', '$score')"; if ($con->query($sql) === TRUE) { echo "Thanks for signing up!"; } else { echo "Error: " . $sql . "<br>" . $con->error; } mysqli_close($con); }
  22. This '%".$select."%' Should be this `".$select."` But you also need to use mysql_real_escape_string on the $_GET['select'] too. Plus you should really start converting this to PDO instead, mysql functions are highly outdated and will be removed in upcoming php versions.
  23. Besides the possible issues with your script, also understand that ANY of the Microsoft email domains (outlook, hotmail, live, msn) are very very hard to have an email arrive in the inbox. They have very strict rules in place to prevent spam, so make sure to check your spam box before deciding that the email has never arrived. Try sending it to a yahoo or gmail address too and see if it arrives there. Those email domains are far less strict.
  24. Show us the code that is setting $conn outside the function.
  25. If this is all the code for the query, then yo uforgot to actually run the query. You're trying to get the results with the fetch_array but yo unever ran the query beforehand. Also, there is no need for the while() since you are only getting a single row from the db.
×
×
  • 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.