Jump to content

dhmyers82

Members
  • Posts

    22
  • Joined

  • Last visited

Everything posted by dhmyers82

  1. When it is a .php file with a form and the action calls itself. The validations are running before the user even has a chance to enter in any data. I just reread the question and I think they should be separate files with all the data being appended to a "single" .txt file
  2. Sorry, where would you like me to post questions like this?
  3. Please tell me if I am thinking correctly I have a .html doc with a form. The form has an action calling a php file. The action is called when I hit submit. How does it work with an all-in-one form? Why is the php running as the page loads and not when I hit submit?
  4. When checking validity do I want to stripslashes before or after I check?
  5. I have no idea what it was doing. I came back to it and re-uploaded it and it is working fine. Thank you all for looking it over.
  6. I keep getting this error "Parse error: syntax error, unexpected '=' in /home/143/dmyers/public_html/sdev253/php/FileDownloader.php on line 4" How is the '=' not needed. Its straight from the stupid book... I hate php today <?php $dir = "files"; if (isset($_GET['filename'])) { $fileToGet = $dir. "/" .stripcslashes($_GET['filename']); if (is_readable($fileToGet)) { header("Content-Description: File Transfer"); header("Content-Type: application/force-download"); header("Content-Disposition: attachment; filename=\"" .$_GET['filename']. "\""); header("Content-Transfer-Encoding: base64"); header("Content-Length: " .filesize($fileToGet)); readfile($fileToGet); $showErrorPage = FALSE; } else { $errorMsg = "Cannot read \"$fileToGet\""; $showErrorPage = TRUE; } } else { $errorMsg = "No filename specified"; $showErrorPage = TRUE; } if ($showErrorPage) { ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "html://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>File Downloader</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> </head> <body> <p>There was an error downloading "<?php echo htmlentities($_GET['filename']); ?></p> <p><?php echo htmlentities($errorMsg); ?></p> </body> </html> <?php } ?>
  7. Thanks it was not saved as a .php and I know the HTML format has no bearing on it working. I have just had people tell me I need to be using HTML5 instead of XHTML, I was just trying to avoid more comments of that nature.
  8. There has to be an error in the php that I am not seeing as I am getting php script echoed in the top of the document. Also It is not finding the server. I dont know if this is becaus of the error I can't find or something else. Yes I know it is in XHTML. I am using an outdated book. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "html://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>[TEMPLATE]</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> </head> <body> <?php error_reporting(E_ALL); ini_set('display_errors', 'on'); $dir = "files"; if (isset($_POST['upload'])) { if (isset($_FILES['new_file'])) { if (move_uploaded_file($_FILES['new_file']['tmp_name'], $dir. "/" .$_FILES['new_file']['name']) == True) { chmod($dir. "/" .$_FILES['new_file']['name'], 0644); echo "File \"" .htmlentities($_FILES['new_file']['name']). "\"successfully uploaded.<br />\n"; } else echo "There was an error uploading \"" .htmlentities($_FILES['new_file']['name']). "\".<br />\n"; } } ?> <form action="FileUploader.php" method="POST" enctype="multipart/form-data"> <input type="hidden" name="MAX_FILE_SIZE" value="25000" /><br /> File to upload:<br /> <input type="file" name="new_file" /><br /> (25000 byte limit) <br /> <input type="submit" name="upload" value="Upload the File" /> <br /> </form> </body> </html> Thank you for the help.
  9. <h2>Scholarship Form</h2> <form name="scholarship" action="process_Scholarship.php" method="post"> <p>First Name: <input type="text" name="fname" /></p> <p>Last Name: <input type="text" name="lname" /></p> <p><input type="reset" value="Clear Form" /> <input type="submit" value="Send Form" /></p> </form> <?php error_reporting(E_ALL); ini_set('display_errors', 'on'); $firstName = validateInput($_POST['fname'], "First Name"); $lastName = validateInput($_POST['lname'], "Last Name"); if ($errorCount<0) echo "Please use the \"Back\" button to re-enter data.<br />\n"; else echo "<p>Thank you for filling out the scholarship form, ".$firstName." ".$lastName."."; function displayRequired($fieldName) { echo "The field \"$fieldName\" is required.<br />\n"; } function validateInput($data, $fieldName) { global $errorCount; if (empty($date)) { displayRequired($fieldName); ++$errorCount; $retval = ""; } else {//Only clean up the input if it isn't empty $retval = trim($data); $retval = stripslashes($retval); } return($retval); } $errorCount = 0; ?> it always reads the form as empty, and spits out the error message. why will it not read the names I enter?
  10. Thank you, PHP is making me want to throw my computer out the window... Its for homework so it has to be a "for". When Im done with this I get to change it to a "while". Im so excited
  11. I keep getting the following error: Fatal error: Function name must be a string in /home/dmyers53/public_html/Projects/Chisese_Zodiac_for_loop.php on line 34 I dont have a function named, where am I going wrong? <body> <img src="images/rat.jpg"></img><!--test the source. WORKS--> <?php error_reporting(E_ALL); ini_set('display_errors', 'on'); echo "<p>This line works</p>\n";//yes it does $zodiacPictures = array( "images/rat.jpg", "images/ox.jpg", "images/tiger.jpg", "images/rabbit.jpg", "images/dragon.jpg", "images/snake.jpg", "images/horse.jpg", "images/sheep.jpg", "images/monkey.jpg", "images/rooster.jpg", "images/dog.jpg", "images/pig.jpg"); for ($imgCounter = 0; $imgCounter <= 12; ++$imgCounter){ echo '<img src="' . $zodiacPictures($imgCounter) . '"></img>';// line 34 } ?> </body> </html>
  12. Thank you. I find it stupid that the book has us using xhtml, and <div>! i was taught html 5 as you can see by my tags. I just haven't converted the head over yet.
  13. Nevermind, Thank you. Sorry I combined two lines from my book and saw it as soon as I went back to look again. $extraFields = 0; $currField = strtok($record, ":");
  14. Having issues with an in book problem. I keep getting and "Undefined variable" Notice on the line that starts with "while ($currField != NULL) {" I am assuming it has something to do with the not NULL but I have no clue on this one folks. <?php error_reporting(E_ALL); ini_set('display_errors', 'on'); $record = "jdoe:8W4dS03a39Yk2:1463:24:John Doe:/home/jdoe:/bin/bash"; $passwordFields = array( "login name", "optional encrypted password", "numerical user ID", "numerical group ID", "user name or comment field", "user home directory", "optional user command interpreter"); $fieldIndex = 0; $extraFields = strtok($record, ":"); while ($currField != NULL) { if ($fieldIndex < count($passwordFields)) echo "<p>The {$passwordFields[$fieldIndex]} is <em>$currField</em></p>\n"; else { ++$extraFields; echo "<p>Extra Field # $extraFields is <em>$currField</em></p>\n"; } $currField = strtok(":"); ++$fieldIndex; } ?>
  15. for the HTML would I put all of it in the include file or would put part of it index file. <nav> <?php required foo.php ?> </nav> or how I had it to begin with.
  16. The text book I am using has 1 page on include files and no examples. I understand how to call the include file and that when I name it I should use the inc_ prefix... Where I am lost is what needs to be inside the include file? What can I omit from the file? Do I just write it like it is part of the .php file I am working on Example...I want to use a include file for a list of links. Starting File <html> <head> </head> <body> <?php> include 'links.php'; ?> </body> </html> Include File <nav> <ul> <li><a href="link1.htlm">Link 1</li> <li><a href="link2.htlm">Link 2</li> <li><a href="link3.htlm">Link 3</li> </ul> </nav> Do I need anything else in the include or would this work?
  17. Thats where I want to get to. Its much simpler and more streamlined. Thank you for posting.
  18. $$$$$$$$$$ yeah, I found that one also. Does eveything else look ok? Naming is what I struggle with alot. I never know what to name things to keep everything straight and to the point.
  19. Chapter 2 homework is coded. It works and that is the main thing, but I dont just want the grade, I want want to learn php and be proficent at it. Is there anything that looks wrong, Variable names, lack off comments, things out of place. All advice is welcome. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "html://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Temperature Conversion</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> </head> <body> <h1>Fahrenheit to Celsius Conversions</h1> <article> <?php $degFahrenheit = 0; function degreeConverter ($degFahrenheit) { //Function converts F* to C* $degCelsius = (($degFahrenheit - 32) * 5/9); $returnCelsius = round ($degCelsius, 1); return $returnCelsius; } do {//begining of loop $convertCelsius = degreeConverter($degFahrenheit); echo "<p>$degFahrenheit degrees Fahrenheit = $convertCelsius degrees Celsius.</p>"; ++degFahrenheit; } while ($degFahrenheit <= 100);//end of loop ?> </article> </body> </html>
  20. Thank you, I knew it was going to be something stupid like that.
  21. I need help debugging some homework.I have narrowed the problem down to the switch. when it gets to the switch it is spitting out the default everytime, also in the default the $score in both echo statment is not showing. Its probably something small killing me I just can't see it and dont have enough experience with php yet. <body> <?php $faceNamesSingular = array("one", "two", "three", "four", "five", "six"); $faceNamesPlural = array("ones", "twos", "threes", "fours", "fives", "sixes"); function checkForDoubles($die1, $die2) { global $faceNamesSingular; global $faceNamesPlural; $returnValue = false; if ($die1 == $die2) { //Doubles echo "The roll was double ", $faceNamesPlural[$die1-1], ".<br />"; $returnValue = true; } else { // Not Doubles echo "The roll was a ", $faceNamesSingular[$die1-1], " and a ", $faceNamesSingular[$die2-1], ".<br />"; $returnValue = false; } return $returnValue; } function displayScoreText($scores, $doubles) { switch ($score) { case 2: echo "You rolled snake eyes!<br />"; break; case 3: echo "You rolled a loose deuce!<br />"; break; case 5: echo "You rolled a fever five!<br />"; break; case 7: echo "You rolled a natural!<br />"; break; case 9: echo "You rolled a nina!<br />"; break; case 11: echo "You rolled a yo!<br />"; break; case 12: echo "You rolled boxcars!<br />"; break; default: if ($score % 2 == 0) {//any even number if ($doubles) { echo "You rolled a hard $score!<br />"; } else { //Not Doubles echo "You rolled an easy $score!<br />"; } } break; } } $dice = array(); $dice[0] = rand(1,6); $dice[1] = rand(1,6); $score = $dice[0] + $dice[1]; echo "<p>"; echo "The total score for the roll was $score.<br />"; $doubles = checkForDoubles($dice[0], $dice[1]); displayScoreText($score, $doubles); echo "</p>"; ?> </body> </html> DiceRoll.php
  22. Hello, I'm Dustin I going back to school for software development. this semester I am taking PHP and Javescript.
×
×
  • 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.