-
Posts
155 -
Joined
-
Last visited
-
Days Won
3
Everything posted by Frank_b
-
ouch.. Why iframes? these are outdated!
-
I hope i do understand your questions. First of all, includes in php are includes from the server's filesystem . That will say that you can include php files from any directory where you have enough rights to read them. And that means that you can include the files from a place outside your public html directories. (or web-root), For example if your webroot starts here: /var/www/public_html and your main index.php is here: /var/www/public_html/index.php then you could for example make a new directory in the /var/www directory and name him includes for example. in this new directory you can place your php include files like sessions.php for example. The result would be this: /var/www/includes/sessions.php /var/www/public_html/index.php inside the index.php you could include sessions.php: include '/var/www/includes/sessions.php'; But sessions.php is NOT available from outside the server.
-
did you forget session_start(); ?
-
Create records based on values from other tables
Frank_b replied to UltimateNova's topic in MySQL Help
Well if you want to be possible to enter more than one club you will get a many-to-many relation as well. That means that you will get a join-table player_club. I am not sure about the seasons. Season: [2014/15 Premier League] Drop Down Select from seasons table That will make no sense: adding fields to seasons from seasons.. I think i should make no seasons table. seasons are dynamic. you can use a extra field in the join table to retrieve the season. What kind of thing is a Premier league? That is a competition i think. so make a table competitions and a table player Then make a join table with one extra column: a season field with type integer. Enter 2014 for the season 2014/15. With a small function you can change 2014 to 2014/2015 when you retrieve information from the database competition: id name competition_player comp_id player_id season (type: int) player id name born height weight Now you will be able to use every competition like PREMIER LEAGUE multiple times with the same player where you can add a season for every entry like this: Player season competiton 1 2012 5 1 2013 5 1 2014 5 -
Create records based on values from other tables
Frank_b replied to UltimateNova's topic in MySQL Help
The id is the 'primary key' we often like to use the autoincrement option so that it counts up automaticly if we insert a new record. The club_id is a foreign key. To optimize your database add an index key to this column. besides one-to-many relations there are some other ones. the one-to-one relation is straightforwards and i will not discuss it here. Than there is a many-to-many as well. Lets take persons and teams. Imagine that we have a player in team A that besides of playing football in team A also coaches a younger team B. So one person can be connected to more than one team. And one team exists about multiple persons. That is a many-to-many relation. But how do we store many to many relations? persons: ---------------------------------- id | name | born | team_id ---------------------------------- 1 | Bloggs | 1996-05-29 | 12 teams: ---------------------- id | name | club_id | ----------------------- 11 | team A| 33 | 12 | team B| 33 | person_team ---------------------- person_id | team_id | ---------------------- 1 | 11 | 1 | 12 | The last table we call it a join table. As you can see in this table there are two records for person nr 1. Person nr 1 is active in two teams. to SELECT data from more than one table, google on mysql JOIN. -
Create records based on values from other tables
Frank_b replied to UltimateNova's topic in MySQL Help
Hello, This is a common question for new mysql users. So a player can be member of a club right? If we inverse that than we would say that a club has multiple players. We call this a one-to-many relation. (try to google it) The storage in the database is simple: Since a player can only be member of one club we just have to make a column 'club_id' that where we will store the unique id of the club where the player belongs to. players: ---------------------------------- id | name | born | club_id ---------------------------------- 1 | Bloggs | 1996-05-29 | 33 clubs: ----------------------- id | name | city | ----------------------- 33 | Ajax | Amsterdam | -
Writing GET content (from form.php file) to a separate text.txt
Frank_b replied to sataiuto's topic in PHP Coding Help
exactly file_put_contents is easier. And like jcbones showed you really have to show an error if the file was not written since there can be enough reasons that the function could fail. One of the reasons is permisions on a linux server. Give your directory where you want to write to enough permissions (755). -
Looks good Barand. I am still not sure if i should choose for more model records which sometimes only differ in periods or if i should use your model.
-
i am sorry but your code is a bit to long to edit it all in my available free time. But i give you a basic example <?php // Here comes your PHP programm logic! // There will be not a single output. That means nog echo or printf(), etc // assume this variables has been loaded from the database: $isLoggedIn = true; $username = 'Frank'; $prevLogin = '2014/10/06 14:07:00'; // what will we do with users that are nog logged in? if(!$isLoggedIn) { header('Location: login.php'); exit; // stop this script after the redirect! } ?> <!-- HERE STARTS YOUR OUTPUT, THAT IS ALWAYS THE LAST PART OF YOUR CODE. --> <!-- FROM THIS MOMENT WE ONLY USE PHP SNIPPETS TO ECHO PHP VARIABLES OR TO LOOP THROUGH AN ARRAY TO DISPLAY THE ELEMENTS. --> <!doctype html> <html> <head> <meta charset="utf-8"> <title>Admin Home</title> </head> <body> <div style="userinfo"> <p>Hello <?php echo $username; ?>, we are glad that you are back since <?php echo $prevLogin; ?> !</p> <h1>Admin Home</h1> <p>bla bla bla</p> </div> </body> </html>
-
Barand, Can you explain why you put from_year and to_year in the join-table model_part and not in the model table?
-
can you show the html of this part of your page? I mean the source of your HTML page, you can choose to see the source in your browser..
-
I think file_exists() is not designed for URL's but from PHP 5 it will work with some url wrappers. try this one too: $filename= 'https://www.google.pl/logos/2012/haring-12-hp.png'; $file_headers = @get_headers($filename); if($file_headers[0] == 'HTTP/1.0 404 Not Found'){ echo "The file $filename does not exist"; } else if ($file_headers[0] == 'HTTP/1.0 302 Found' && $file_headers[7] == 'HTTP/1.0 404 Not Found'){ echo "The file $filename does not exist, and I got redirected to a custom 404 page.."; } else { echo "The file $filename exists"; } source: http://stackoverflow.com/questions/10444059/file-exists-returns-false-even-if-file-exist-remote-url
-
How to select question from mysql tables randomly ?
Frank_b replied to JosephHanh's topic in PHP Coding Help
or this query: SELECT * FROM pictures ORDER BY RAND() LIMIT 1; -
what a mess. a user_id at the beginning of a filename... What if my filename starts with a number. Let's say 12hours.jpg. and my user id is 5. Then the filename would be 512hours.jpg. Lucky for user number 512, he just got a free picture. Then number two: is there a limit for one upload per user? what if the user wants to upload more then one? where are you going to store that in your database? I can make one suggestion i am affraid: stop coding and buy yourself a book!
-
class Horse { private fedtime; public function __construct() { $this->fedtime = new DateTime('yesterday'); } public function getLastFedTime() { return $this->fedtime; } public function setLastFedTime($time) $this->fedtime = $time; } public function isHungry() { $now = new DateTime(); $interval = date_diff($this->fedtime, $now); return $interval->format('%a') > 1; // gives true if the fedtime is more then one day ago, otherwise false. } } And now you do the rest!
-
Why do you check on id AND name in the where claus? If the id is unique than that would be enough.
-
SELECT * FROM orders WHERE DATEDIFF( duedate, CURRENT_DATE()) <= 10 That is enough to show only orders that are equal or less to 10 days before the column duedate. Like requinix said: Do not move them to another table. That is bad practise. ps. i assumed that you have a duedate column with the type DATE or DATETIME.
-
> I have a IBM DB2 table on one side, and PHP application on other. DB2 table is like a "temporary" table. Have them on the same machine or on different machines? Normaly you let your PHP application handle database requests (or commands) to your database server, which will reply to this requests. There is a IBM DB2 driver for PDO available: http://php.net/manual/en/ref.pdo-ibm.php One of the links on that page brings you to a first connection example: http://php.net/manual/en/ref.pdo-ibm.connection.php For the rest PDO will work much the same as PDO works for other databases. Most PDO tutorials will focus on MySql databases.
-
Yes, security is always the problem. In each case do not allow to store files with a .php extension or a .htaccess name! Thanks jcbones.
-
add a timestamp to each file is a bit strange to hear. Do you mean that you want to add a timestamp to the filename? the php time() function gives you the current timestamp which is the number of second passed since January 1 1970 00:00:00 GMT. The original filename can be found under the $_FILES['file']['name'][$key] <?php // be sure that dir/filename.ext will be a valid path and that you have write permissions $uploads_dir = 'uploads/'; // if we got something posted if($_SERVER['REQUEST_METHOD'] == 'POST') { // walk through the error codes for each separate file foreach ($_FILES['file']['error'] as $key => $error) { if ($error == UPLOAD_ERR_OK) { // now move the uploaded file to uploads/<filename> $tmp_name = $_FILES['file']['tmp_name'][$key]; $name = $_FILES['file']['name'][$key]; move_uploaded_file($tmp_name, $uploads_dir.$name); echo time() . '-' . $name . '<br>'; } } } ?> <html> <head> <title></title> </head> <body> <form enctype="multipart/form-data" action="" method="POST"> <input type="file" name="file[]" id="file" ><br> <input type="file" name="file[]" id="file" ><br> <input type="file" name="file[]" id="file" ><br> <input type="file" name="file[]" id="file" ><br> <input type="submit" value="upload"> </form> </body> </html>
-
take a look here: http://webdevelopingcat.com/php-mysql-tutorial-for-beginners-connecting-to-the-database-with-pdo/
-
nearly yes... did you have success now?
-
Hi Barand, I just changed the > to < to change the order direction Skill_Points from ascending to descending like you did and i have exactly the same results. tried it with more elements and still the results are equal. I looked on php.net and saw that they descriped it like you are telling but i think because of php's automatic type casting it does not make any sence if you give a boolean or a int back. a boolean will be converted to an integer when needed. There is also no need to return a negative, positive or zero back because zero will stay unhandled. Note: If two members compare as equal, their relative order in the sorted array is undefined. Long story short: two manners and same result.
-
Hi, That is a very global question. Can you explain what you system is? are you talking about a database, a textfile or what?
-
Mention that move_uploaded_file() will overwrite files without any warning. Lot of developers give uploaded files unique names with help of current timestamp. The generated name AND the original name will be stored into the database. This solution protects you from files being overwrited.