-
Posts
3,404 -
Joined
-
Last visited
-
Days Won
55
Everything posted by Ch0cu3r
-
Try using trim to clear the whitespace before and after the value? Alternatively typecast the value to int $value = (int) $value; // typecase value to int
-
Those errors are caused by your original issued you started this topic with. See cyberRobot's post. Before you can use any mysql_ functions you need to make sure you are connected to MySQL. Otherwise you will get the errors you are receiving
-
What is with the use of return on the lines 13 & 15? return is not used for outputting something to the browser. It is usually used for returning data from a custom defined/callback function. To output something you need to use echo or print
-
Most likely due to starting your include file paths with a forward slash / In PHP / means the root of the file system, not root of your website. Either remove the forward slash from the start of the include path or prepend $_SERVER['DOCUMENT_ROOT'] to the file paths, example <?php include($_SERVER['DOCUMENT_ROOT'] .'/includes/header.html');?> <?php include($_SERVER['DOCUMENT_ROOT'] . '/includes/aside.html');?> Also when posting code please wrap it within tags. For now I have edited your post for you.
-
Sorry misspelt the function, it should be error_reporting (left out the r between o and t ) on line 3.
-
See strip_tags
-
The mysql_ functions will continue to work yes, But they will be removed completely at some point from future versions of PHP. The PHP developers have not released when this will take place though. However it is strongly advised to upgrade to your code to mysqli functions. The mysqli functions provided extra functionally lacking from the mysql_* functions. Such as prepared statements. Which is a more secure way of handling user input within a query, rather than sanitizing using mysql_real_escape_string A quick guide for updating your could would be as follows. But you should read the note bellow my post To convert your code you are going to need to first convert the mysql_ functions over to their mysqli_ function counter part. Consult the mysqli documentation (HINT look out for the procedural examples) to see what the necessary changes maybe for each function. The hard part will be converting mysql_result(). As there is no mysqli function with similar functionally. Instead you are going to need to come with your own functionality. What you'd do instead is use mysqli_fetch_row to get the result from the query and then return the first array item. Example code to convert may look like this return mysql_result(mysql_query(/* query */), 0) OR return mysql_result(mysql_query(/* query */), 0, 'user_id'); . Will need to be converted to something like this $result = mysqli_query(/* MySQLi Object*/, /* MySQL Query */); // execute query $field = mysqli_fetch_row($result); // get the result from the query return $field[0]; // return the first array item (value of the first field retuned by the query) . However in other instances of your code where it looks like return (mysql_result(mysql_query(/* query */), 0) == 1) ? true : false; It needs to be written as the conversion example I gave above, but the return $field[0] line will need to be changed to return $field[0] == 1 ? true : false; NOTE: This is a quick and dirty fix to get your code to work with mysqli. But I would strongly advise you to convert your queries that use user input (variables used inside the query) to be converted to prepared statements. These are far more secure than using mysqli_real_escape_string to sanitize the user input. Also you should add sufficient error checking to your queries, such as making sure the query has returned a result and take necessary action when the query issues an error.
-
Your code looks fine and should be generating the <option></option> tags for each city in your locations table. If no options are being generate you need to start debugging your PHP code to see where it failing. I'd start by checking mysql has not returned an error. Use mysqli_error to check.
-
You will need to rewrite your code so you are fetching the images and also generate their thumbnail. Then you can sort them in the order your require. Once you have sorted the images you can then begin to show them You'd being first by fetching the images (I prefer to use glob for specifically returning certain files by their file extension by using the GLOB_BRACE flag). I'd Then add the filename and the filemtime (returns the timestamp the image was created/last modified) into separate arrays. The array containing the filemtime values will be used to sort the files oldest to newest later using array_multisort. At this point the thumbnails can be generated $images = array(); $times = array(); // read the images folder for jpg, jpeg, png and gif images using glob() - see http://php.net/glob for info foreach(glob('images/*.{jpg,jpeg,png,gif}', GLOB_BRACE) as $image) { // add the file to the images array $images[] = $image; // get the files creation/last modification timestamp add it to the times array. // This array will be used later to sort the images array $times[] = filemtime($image); // generate the image thumbnail if needed if(!file_exists('thumbs/' . $image)) { // calling your makeThumb function, pass it the file extension for the image makeThumb(basename($image), pathinfo($image, PATHINFO_EXTENSION)); } } After the images have been gathered, use array_multisort to sort the $times array in descending order. This will cause the $images array to also be sorted newest to oldest too. // using the times array, to sort the images newest to oldest array_multisort($times , SORT_DESC, $images); Now the images can be listed showing the newest images first echo '<ul>'; foreach($images as $image) { echo '<li><a href="' . $image. '">'; echo '<img src="thumbs/'.$image.'" alt="" /></a></li>'; } echo '</ul>'; NOTE: I have cut a lot of your original code out. You will need to modify your getPicutres function in order for the above code to work
-
Retrieving single xml node value in PHP GCal Script
Ch0cu3r replied to m1kcal's topic in PHP Coding Help
Does the title for each event in the calendar resemble the the two football teams playing each other eg the title is like Manchester United v Arsenal If that is the case you could do away with your if/elseif statement completely as long as the filename for the football team logos are named the same as the football team name, are in lower-case and without spaces in the filename. You could simpify your code to // get the team name before the versus symbol list($teamNameLeft, ) = explode(' v ', $entry->title); // generate the file path to the team logo. // - converts the team name to lowercase // - removes spaces in the team name $team_image_path = 'logos/' . str_replace(' ', '', strtolower($teamNameLeft)) . '.png'; // if the logo image does NOT exist, use the unavailable logo if(!file_exists($team_image)) $team_image_path = 'logos/unavailable.png'; // set the HTML for the team logo $team_image = "<div id='left'><img src='$team_image_path' /></div>"; -
To be clear mod_rewrite has no effect on PHP. It only effects url requests to the server. Sounds to me you'd be better of running your 2 sites under two separate virtual hosts. Virtual hosts allows you to server to host multiple sites from the same server. Each site can have its own domain and document root. You could then add your framework to a central location on the server and then add it to the include_path
-
Most likely due to the file permissions set for the www/ directory. PHP has not created the file any where else. It will only attempt to create the file in the path you have specified You need to do as Jacques1 mentioned earlier and turn error reporting on. So PHP will tell you what is wrong in the event an error occurs. Add the following two lines at the top of your code before ( after the <?php ) ini_set('display_errors', true); error_repoting(E_ALL); When you run your code now you should see a bunch of errors displayed mentioning PHP does not have permission to create the file in /var/www To resolve the error you need to set the necessary file permissions to allow PHP to write to the /var/www directory. You can do as we did earlier with your home directory. By setting the www-data group as the group owner to /var/www and allowing the group owner to write to the directory, eg sudo chown root:www-data /var/www/ sudo chmod g+w /var/www/ Running code now will allow PHP to create the file. You need to read the link I gave you to understand how file permissions work.
-
Missed the Miscellaneous forum?
-
The best place would be php.net/mysqli. That is the documentation for mysqli. Each function has an explanation of what arguments it requires, what it does, what it returns and a code example for how it is used. From there you should be able to convert your the mysql_* functions to the mysqli_* equivalent functions. Alternatively you may find http://codular.com/php-mysqli helpful.
-
This is the expected behaviour if you have not set the necessary file permissions to allow PHP to create the file. You need to read up on file permissions to understand how permissions work under Debian (the rules are the same for any *nix os). By default only you are able to create/modify files and folders in you home directory as they are owned by you. Any other user (other than the root user) will be prohibited from creating/modifying any files/folders within your home directory. On Debian PHP is ran as the www-data user (under the www-data group) when your code is being ran. This is why PHP cannot create the text file in your home folder. Because PHP is being ran as different user and group it is being denied access to your home directory so the file is not being created. To allow PHP to create a files in your home directory you need to do two things. Set the www-data group as the group owner for your home directory and apply write permissions for the group owner. You can do this by running these two commands: (NOTE: Replace <your_username_here> with your Debian username) sudo chown <your_username_here>:www-data /home/<your_username_here>/ sudo chmod w+g /home/<your_username_here>/ Now when you run your code, PHP should now be able to create the text file within your home directory. But this should not be needed at all. Why are you requiring PHP to able to create files in your home folder and not your document root?
-
How would we know that? We are not sat in front of you.
-
Retrieving single xml node value in PHP GCal Script
Ch0cu3r replied to m1kcal's topic in PHP Coding Help
Your are completely wrong. What is the purpose of the teamImages function? -
Retrieving single xml node value in PHP GCal Script
Ch0cu3r replied to m1kcal's topic in PHP Coding Help
The purpose of this line is to replace the placeholder with the value of $team_image $temp_event=str_replace("###TEAM_IMAGE###", $team_image,$temp_event); have a read up on str_replace to see how it works. -
There shouldnt be any issued pasting code. Although please do wrap your code in tags, either type those tags manually or click the <> (code) button in the editor to paste your code. If you continue to have issues, then either attach your php files to your post or post a link to your code at pastebin,com
-
@claudiogc the ~ char will refer to the active users home directory. This will return your home directory when used in a terminal, as you are the user executing the command. But when the php code is process by PHP it'll be ran as a different user. So the ~ will refer to the user PHP is being running as. Which I believe with Debian it'll be the httpd user. So in order for the text file be created in your home directory you'll need to specify the full path to your home directory.
-
If you are seeing the PHP code then you appear to of not configured your server correctly. Or you're using short tags in your code (<? ?>) and not the full PHP tags (<?php ?>). I advise you to always use the full php tag syntax. Short tags are only supported if the short_open_tag directive is enabled in the configuration.
-
Retrieving single xml node value in PHP GCal Script
Ch0cu3r replied to m1kcal's topic in PHP Coding Help
That should work. It should output an image if $entry->title starts with the word Sundaland. If it didnt where did you place it? Anywhere between lines 122 and 169 should be ok. However do note that how the event is displayed depends on the $event_display variable. This variable contains a string which contains placeholders which will be replaced by their associated values returned from google calander. For example ###DATE### will be replaced by the date for the event. It probably would be a good idea to add a placeholder in that string for where you want the image to appear when the event is outputted. Eg, add a ###TEAM_IMAGE### placeholder $event_display="<P><B>###TITLE###</b> - from ###FROM### ###DATESTART### until ###UNTIL### ###DATEEND### (<a href='###LINK###'>add this</a>)<BR>###WHERE### (<a href='###MAPLINK###'>map</a>)<br>###TEAM_IMAGE### ###DESCRIPTION###</p>"; Now any where between lines 142 and 169 add the following // default replacement ###TEAM_IMAGE### placeholder valuem an empty string $team_image = ''; // if the entry title contains the word Sundardland at the start of the string if (0 === strpos($entry->title, 'Sunderland')) { // replace the ###TEAM_IMAGE### placeholder with a html image $team_image = "<div id='left'><img src='sun.png' /></div>"; } // replace the ###TEAM_IMAGE### placeholder $temp_event=str_replace("###TEAM_IMAGE###", $team_image,$temp_event); -
Retrieving single xml node value in PHP GCal Script
Ch0cu3r replied to m1kcal's topic in PHP Coding Help
Sounds like you are concatenating $entry->title to a variable. This variable on its own will only return the title for the current event being listed. Can you tell us what you trying to do with the title. Also are you wanting to get the title for all the events or just a specific event? -
preg_match() - wrong match to the regular expression given in pattern
Ch0cu3r replied to terungwa's topic in Regex Help
Then change your regex to v=([\w-]*) -
preg_match() - wrong match to the regular expression given in pattern
Ch0cu3r replied to terungwa's topic in Regex Help
The problem is with the regex for matching the the v= part of the youtube url v=(\w*\W?\w*) \w* will match any word character (typically letters, numbers, underscores, etc).This will match GXHijTS9_2g \W? will match a non word character (eg space, comma, period, etc) if it exists.This will match the space after the youtube url \w* will match any word character (letters, numbers, etc).This will match the first word after the url To solve the problem remove \W?\w* from the regex