Jump to content

$Three3

Members
  • Posts

    78
  • Joined

  • Last visited

    Never

Everything posted by $Three3

  1. Hey give this code a shot. It will move all files in the variable $directory to the NewDirectory only if there are 30 or more files in the $directory variable. The $directory variable will hold the current date for each day in the format of 01162010. If there are only a couple hundred files in the $directory variable it will not over run your server. I just moved 147 files in about 2 seconds with this same script. <<?php $directory = date('djY') ; $directoryScan = scandir($directory) ; $numFiles = count($directoryScan) - 1 ; if ($numFiles >= 30) { foreach ($directoryScan as $value) { if ((is_file($value)) AND (substr($item, 0, 1) != '.')) { rename("$directory/$value" , "NewFolder/$value") ; } } echo "There are 30 or more files in the directory: $directory<br /><br /> The files have been moved successfully." ; } else { echo "There are no files to move today." ; } ?>
  2. To check whether the directory you are using for example the current date, you could use the scandir() function to test whether there are 30 or more files in the directory. So for example you could use this to test: <?php $directory = '012410' ; $directoryScan = scandir($directory) ; $numFiles = count($directoryScan) - 1 ; if ($numFiles >= 30) { echo "There are 30 or more files in the directory: $directory" ; } else { echo "There are no files to move today." ; } ?> This code will just check to see if there are more than 30 files on the particular folder you want to check.
  3. Hi everyone, I am new to SQL and I have been reading a book called "Learning SQL" and I am stuck on this one part of the book. It has to do with the CONSTRAINT command and I am not sure what this command does or means. The book never even explains its functionality. Here is the code from the book: CREATE TABLE person (person_id SMALLINT UNSIGNED,fname VARCHAR(20), lname VARCHAR(20), gender ENUM('M','F'), birth_date DATE, street VARCHAR(30), city VARCHAR(20), state VARCHAR(20), country VARCHAR(20), postal_code VARCHAR(20), CONSTRAINT pk_person PRIMARY KEY (person_id)); And the second table that goes along with the code above is: CREATE TABLE favorite_food (person_id SMALLINT UNSIGNED,food VARCHAR(20), CONSTRAINT pk_favorite_food PRIMARY KEY (person_id, food), CONSTRAINT fk_fav_food_person_id FOREIGN KEY (person_id)REFERENCES person (person_id));
  4. Ok on this script here: $total = total number of $row[]; $half = $total / .5; for (i = 0; i < $total; i ++){ if(i < $half){ ?> <li><?PHP echo $row[i]; ?> </li> <?PHP else { ?> <li><?PHP echo $row[i]; ?> </li> <?PHP Make it this: $total = total number of $row[]; $half = $total / .5; for ($i = 0; $i < $total; $i++){ if($i < $half){ ?> <li><?PHP echo $row[$i]; ?> </li> <?PHP else { ?> <li><?PHP echo $row[$i]; ?> </li> <?PHP Try adding the dollar $ symbol in front of the i's and it should work now man.
  5. Thanks a lot man for those links and explanations. It really cleared things up for me. Thanks again
  6. Hi, I have just begun to learn about connecting and adding entries to a MYSQL database but I am confused on one part of what I have read so far. When trying to Create a Table in the database, this is what the book says to write: CREATE TABLE entries (entry_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , title VARCHAR(100) NOT NULL, entry TEXT NOT NULL, date_entered DATETIME NOT NULL) What I really do not grasp 100% is what the CAPITAL words really mean. If someone does not mind explaining the what this actually means it would be great. Thanks a lot in advance for the help.
  7. Awesome. I understand now. Thanks a lot for that link and for your time and help. Appreciate it
  8. Hey thanks for the reply. Okay I understand that now but what I do not understand is why you would want to make sure that variable $contents is not equal to a dot/period? Thanks again man
  9. Hey everyone, I have been reading a php book and following all of the examples in the book but I am stuck on this one line. I actually understand the hardest part of this script but not the simple part. Here is the code: <?php date_default_timezone_set('US/Central') ; //Scan directories $searchDirectory = '.' ; $directoryScan = scandir($searchDirectory) ; //Create a list of directories first echo "<h2>Directories</h2>" ; echo "<ul>" ; //Access the contents of the directory foreach ($directoryScan as $contents) { if ((is_dir($contents)) AND (substr($contents , 0 , 1) != '.')) { echo "<li>$contents</li>" ; } } echo "</ul>" ; //Create Files header echo "<hr /><h1>Files</h1>" ; //Create Table echo '<table cellpadding="2" cellspacing="10" align="left">' ; //Create Files Row echo "<tr> <td><b><u>Name</u></b></td> <td><b><u>Size</u></b></td> <td><b><u>Last Modified</u></b></td> <td><b><u>File Permissions</u></b></td> <td><b><u>File Owner</u></b></td> <td><b><u>File Last Accessed</u></b></td> </tr>" ; //Access the files in the directory foreach ($directoryScan as $contents) { if ((is_file($contents)) AND (substr($contents, 0 , 1) != '.')) { //Create File Size & Last Mod date $fs = filesize($contents) ; $lm = date('F j, Y' , filemtime($contents)) ; $fp = fileperms($contents) ; $fo = fileowner($contents) ; $fla = date('F j, Y' , fileatime($contents)) ; //Print Out Data echo "<tr> <td>$contents</td> <td>$fs</td> <td>$lm</td> <td>$fp</td> <td>$fo</td> <td>$fla</td> </tr>" ; } } echo "</table>" ; ?> What is confusing me is this line: if ((is_dir($contents)) AND (substr($contents , 0 , 1) != '.')) { I understand that whole line but what I do not understand is the part with the '.' period. What does this mean? Thanks in advance for the help.
  10. Hey thanks for the reply. I'm not 100% sure what you mean by passing it to a form. If you don't mind explaining that that would be great. Thanks
  11. Hi I am new to php programing and I was trying to make up a simple script like a captcha but I cannot get the validation part of it working. I think it should work but it is not. Anyone know what is wrong. Any help is greatly appreciated. Here is the code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Captcha</title> </head> <body> <?php $alpha = 'abcdefghijklmnopqrstuvwxyz' ; $shuffle = str_shuffle($alpha) ; $partial = substr($shuffle , 0 , 4) ; echo "$partial <br /><br />" ; if (isset($_POST['submitted'])) { //Valdate the info if ($_POST['input'] != $partial) { echo "Your answer does not match the capthcha. Please try again.<br /><br />" ; } else { echo "You answered correctly!<br /><br />" ; } } ?> <form action="capthcha2.php" method="post"> <p>Enter Captcha: <input name="input" type="text" size="20" /></p> <input name="submit" type="submit" value="Submit" /> <input name="submitted" type="hidden" value="true" /> </form> </body> </html>
  12. Lol wow. A couple of days for a missing period. Thanks a lot man! Lol. If you do not mind also, is there anyway to get an error on something like this?
  13. Okay I just added that to the top but it still gives me a blank page. I even tried it on the little script below but it still does not display any errors. <?php ini_set ('display_errors', 1); error_reporting (E_ALL); for ($i = 1 ; $i <= 10 ; $i++) { echo $i ?>
  14. Hi, I have been stuck on this for a while now. I am really new to PHP and I cannot get the script below to display the html form. I have tried practically everything but it is just not working for me. It just displays a blank page. Any help is greatly appreciated. Also, ever since I have switched over to a new server, I have not been able to get any errors to display while testing my scripts. How can I go about getting the errors turned back on? Thanks <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>User Registration</title> </head> <body> <?php //Check to see if form has been submitted if (isset($_POST['submitted'])) { //Set Flag Varibale $problem = FALSE ; //There are currently no problems //Validate all forms if (empty($_POST['username'])) { $problem = TRUE ; die('You must enter a username') ; } if (strlen($_POST['usernmae'] <= 4)) { $problem = TRUE ; die('You must enter a username longer than 4 characters') ; } if (empty($_POST['email'])) { $problem = TRUE ; die('You must enter an email address.') ; } if (empty($_POST['password1'])) { $problem = TRUE ; die('You must enter a password') ; } if (strlen($_POST['password1'] <= 4)) { $problem = TRUE ; die('You must enter a password longer than 4 characters') ; } if ($_POST['password1'] != $_POST['password2']) { $problem = TRUE ; die('Your passwords do not match. Please go back and correct the issue.') ; } if (!$problem) { //If there were not any problems //Try to open the file to write to if ($fp = fopen('../userinfo/userinfo.txt' , 'ab')) { $data = $_POST['username'] . "<br />" . $_POST['email'] . "<br />" $_POST['password1'] . "\n" ; //Write to the file and Close the file fwrite($fp , $data) ; fclose($fp) ; echo "You have successfully registered! Your user information is below: (We have also emailed you this info) <br /><br /><br />" ; $to = $_POST['email'] ; $subject = 'User Registration Information' ; $body = $data ; //Mail the information to the user mail($to , $subject , $body , 'From: jon@gmail.com') ; } else { die('You could not register. There was a system error. Please try again.') ; } } else { die('You forgot a field. Please go back and fill out all forms.') ; } } else { echo '<form action="myregister.php" method="post"> <p>Username:* <input name="username" type="text" size="20" />Must be longer than 4 characters</p> <p>E-mail:* <input name="email" type="text" size="20" /></p> <p>Password:* <input name="password1" type="password" size="20" />Must be longer than 4 characters</p> <p>Confirm Pasword:* <input name="password2" type="password" size="20" /></p> <input name="submit" type="submit" value="Register" /> <input name="submitted" type="hidden" value="true" /> </form>' ; } echo "<p>The * denotes a required field</p>" ; //End PHP ?> </body> </html>
  15. ok cool thanks I will give that a try. One quick question though, when I am editing the file it say "Warning: You are editing a read only file." Is it suppose to say that? You will need to edit the php.ini as the root user. The warning it is giving you is basically saying 'you don't have permissions to write to this file'. Thanks a lot. It work now. That was the reason because of the permissions. Thank a lot for the help.
  16. ok cool thanks I will give that a try. One quick question though, when I am editing the file it say "Warning: You are editing a read only file." Is it suppose to say that?
  17. I have managed to change the file name using the vim command but I do not know how to save the changes? any ideas? I tried this but it is giving me an odd error.
  18. Hi, I have been trying to edit my php.ini file through the command line using putty. I need to edit this: max_upload_filesize = 2M I need it to be 10MB. Any instructions would be great. I am on a virtual dedicated server so I have ssh access. I can also use instructions for a Mac or PC so let me know. Thanks!
  19. yes So the code: if (!$problem) turns the $problem to TRUE? Or does it check to see that $problem is NOT true and if it is not true echo the statement? Thanks for the helpful reply. I'm close to understanding this lol. I'm not sure why this is giving such a hard rme to grasp because it seems like it would b simple to understand. Thanks for the patience.
  20. Hey man thanks for the reply. That clarified it up quite a bit. That helped me get through that chapter finally lol. 2 chapters later though there is another example with the not ! operator. It was used in a different way this time. Here is the code: <?php if (isset($_POST['submitted'])) { $probelm = FALSE ; // No problems so far //start checking to make sure forms were filled out correclty if (empty($_POST['fname'])) { $problem = TRUE ; die('Please enter your first name.') ; } if (empty($_POST['lname'])) { $problem = TRUE ; die('Please enter your last name.') ; } if ((empty($_POST['email'])) { $problem = TRUE ; die('Please enter your email address.') ; } if (empty($_POST['password1'])) { $problem = TRUE ; die('Please enter a password.') ; } if ($_POST['password1'] != $_POST['password2']) { $problem = TRUE ; die('Your passwords do not match, please go back and correct the issue.') ; } if (!$problem) { echo "You have successfully registered for an account in North Shore. Your user information <br /> has been emailed to you at " . $_POST['email'] ; This line here if (!$problem) is the one giving me a hard time. Does this mean if there are no problems? Thanks again for the help.
  21. Thanks a lot for the help. I understand the script now. I really appreciate it.
  22. not greater, it will stop when $i == $n Hey thanks for clarifying that. I was confused but thanks for clearing that up. Could you explain what this line means? if (($n%$i) == 0) I know the "%" operator divides the 2 numbers and then gives you the remainder but for example, if I was to put "57" in the text box to see if it is a prime number, what is 57 being divided by? Is it being divided by "2" which would would leave a remainder of "1" which would not equal "0" so it should be considered a prime correct? Thanks again for the help.
  23. Here is the html form you need: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>BMI Calculator</title> </head> <body> <form action="bmi.php" method="post"> Enter Your Height (Inches) <input name="height" type="text" size="7" /> <br /> <br /> Enter Your Weight (Pounds) <input name="weight" type="text" size="7" /> <br /> <br /> <input name="submit" type="submit" value="Submit" /> </form> </body> </html> and here is the php code you need: <?php $height = $_POST['height'] ; $weight = $_POST['weight'] ; ?> <?php $bmih = $height * $height ; $bmiw = $weight/$bmih ; $bmiw *= 703 ; echo "Your BMI (Body Mass Index) is " . number_format($bmiw , 2 , '.', ',') . "." ; echo "<br />" ; echo "<ul>" ; echo "<li>Normal weight = 18.5-24.9</li>" ; echo "<li>Overweight = 25-29.9</li>" ; echo "<li>Obesity = BMI of 30 or greater</li>" ; echo "</ul>" ; ?> You should name the html form "bmi.html" and the php form should be named "bmi.php". Just copy and paste these into a file and save them with the names above. The script will calculate your BMI (Body Mass Index). It uses really basic PHP operators and functions. Hope this helps you.
  24. Hey thanks for trying it out. I got it working now. It was just a minor error on my part. If you do not mind though, I am having little trouble understanding this line of code : // test each number for prime-ness: // check the number by dividing it // by all the numbers between 2 and itself // if not perfectly divisible by any, // number is prime for ($i=2; $i<$n; $i++) { $primeFlag = 0 ; if (($n%$i) == 0) { break; } $primeFlag = 1; } I understand the rest of the code but this is throwing me off. Thanks again for the help.
  25. Hey thanks for the great link. That helped me quite a bit. Here is the code for one of the example programs at the end of the chapter. <?php // if form not yet submitted // display form if (!isset($_POST['submit'])) { ?> <form method="post" action="primes.php"> Enter a list of numbers, separated by commas: <br /> <input type="text" name="num" /> <p> <input type="submit" name="submit" value="Submit" /> </form> <?php // if form submitted // process form input } else { // retrieve number from POST submission // convert to array by splitting on comma $numStr = $_POST['num'] ; $numArr = explode(',', $_POST['num']) ; $primes = array() ; $primeFlag = 0 ; // iterate over array // get absolute values of each number foreach ($numArr as $n) { $n = trim(abs($n)); // test each number for prime-ness: // check the number by dividing it // by all the numbers between 2 and itself // if not perfectly divisible by any, // number is prime for ($i=2; $i<$n; $i++) { $primeFlag = 0 ; if (($n%$i) == 0) { break; } $primeFlag = 1; } // if prime // add to output array if ($primeFlag == 1) { array_push($primes , $n) ; } } // check if any primes were found // if yes, sort and remove duplicates from array // print message if (count($primes) > 0) { $primes = array_unique($primes) ; sort($primes) ; echo 'The following numbers are prime: ' . implode($primes, ' ') ; } else { echo 'No prime numbers found' ; } } ?> The problem I am having with the code is that it will check for prime numbers, but will only display the last prime number entered into the text box. I attached a 2 screenshots to the post to help you understand what I am talking about. What is wrong with the code? I copied and pasted word for word out of the book but it still does not work. Thanks. [attachment deleted by admin]
×
×
  • 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.