Jump to content

jimjimalabim

New Members
  • Posts

    8
  • Joined

  • Last visited

    Never

Everything posted by jimjimalabim

  1. ok people sorry but its late, and I'm tired and I can't figure this out maybe I just need a break? I'm getting some warnings here, first here is my code: <?php echo"<?xml version=\1.0\"encoding=\UFT-8\"\x3f>"; echo"\n"; ?> <!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtmll/DTD/xhtmll-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"lang="en"> <head> <title>Assignment 7: Making Space, Part 3</title> <meta name="author" content="Jim Cozzy"/> </head> <body> <h1> Assignment 7: Making Space, Part 3 </h1> <?php echo "<h2>Today is ".date('l, F d, Y')."</h2>"; ?> <?php //calculate the area of an equilateral triangle function calcTriangle($cVal) { $halfSide = $cVal/2; $otherSide = sqrt(($cVal*$cVal) - ($halfSide*$halfSide)); $areaValue = $otherSide * $halfSide; echo "<p>The area of an equilateral triangle whose sides are {$cVal} is {$areaValue}.</p>\n"; } $yeah = (isset($_POST['vfld']))?$_POST['vfld']:''; if (isset($_POST['submit'])) { if ($_POST['submit'] == "Clear") { $yeah = ""; } elseif ($_POST['submit'] == "Calculate") { if (!eregi(square|circle|triangle, $yeah)) { echo "<p>Sorry I forgot to mention the the shape needs to be a Square, Circle, or a Triangle.</p>". "<p>Please return and try again.</p>"; exit; } }} ?> <form method="post" action="makingspace3.php" id="form1" name=form1"> <p> Write down a shape and a number and I will compute the area for: <input type="text" id="vfld" name="vfld" value="<?php echo $yeah; ?>"/> </p> <p> After you have done this click calcualte to see results </p> <p> <input type="submit" name="submit" value="Calculate" /> <input type="submit" name="submit" value="Clear" /> </p> </form> <div id="footer"> <pre>This page written by: <cite>James Cozzy</cite> ©2011 and beyond</pre> </div> </body> </html> so when I enter something wrong into my form like ggggg I want it to print an error which it does, but it also says what am I missing???? Notice: Use of undefined constant square - assumed 'square' in /studfs1/homepage/CISS-225/makingspace3.php on line 49 Notice: Use of undefined constant circle - assumed 'circle' in /studfs1/homepage/CISS-225/makingspace3.php on line 49 Notice: Use of undefined constant triangle - assumed 'triangle' in /studfs1/homepage/CISS-225/makingspace3.php on line 49
  2. I know I could not set them, but I'm trying to write a function that will not set, or set them to blank.
  3. Ok people I'm trying to write a simple function that will pass a blank string back to my form when the clear button is clicked, but for some reason it will not clear my form. I can't figure this out I have written other functions that have worked, but for some reason this has me stumped. Here is my function //function to clear variables function clearVars(&$j, &$k) { $workValue = ""; $workType = ""; } $workValue = (isset($_POST['vfld']))?$_POST['vfld']:''; $workType = (isset($_POST['tfld']))?$_POST['tfld']:''; if (isset($_POST['submit'])) { if ($_POST['submit'] == "Clear") { clearVars($vfld,$tfld); } elseif ($_POST['submit'] == "Calculate") { getVars($vfld,$tfld,$calc); $continue = testVars(); if ($continue == "yes") { switch ($workType) { case "circle": calcCircle($workValue); break; case "square": calcSquare($workValue); break; case "triangle": calcTriangle($workValue); break; } } } } ?> <form method="post" action="hw06.php" id="form1" name="form1"> <p> Enter a number here : <input type="text" id="vfld" name="vfld" value="<?php echo $workValue; ?>"/> </p> <p> This number is: <br /> <input type="radio" name="tfld" value="circle" <?php if ($workType == "circle") { echo 'checked="checked"'; } ?> /> : the radius of a circle <br /> <input type="radio" name="tfld" value="square" <?php if ($workType == "square") { echo 'checked="checked"'; } ?> /> : the length of one side of a square <br /> <input type="radio" name="tfld" value="triangle" <?php if ($workType == "triangle") { echo 'checked="checked"'; } ?> /> : the length of one side of an equilateral triangle </p> <p> <input type="submit" name="submit" value="Calculate" /> <input type="submit" name="submit" value="Clear" /> </p> </form> <div id="footer"> <pre>This page written by: <cite>The President</cite> ©2011 and beyond</pre> </div> </body> </html>
  4. Thank you that did help, and I liked the explanation!
  5. Can't figure out what is wrong with my function getVars here is my code <?php echo"<?xml version=\1.0\"encoding=\UFT-8\"\x3f>"; echo"\n"; ?> <!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtmll/DTD/xhtmll-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"lang="en"> <head> <title>My third PHP Generated Document</title> </head> <body> <h2> My Third PHP Document </h2> <?php echo "<h3>Today is ".date('l, F d, Y')."</h3>"; ?> <?php //calculate the area of an equilateral triangle function calcTriangle($cVal) { $halfSide = $cVal/2; $otherSide = sqrt(($cVal*$cVal) - ($halfSide*$halfSide)); $area = $otherSide * $halfSide; echo "<p>The area of an equilateral triangle whose sides are {$calcValue} is {$areaValue}.</p>\n"; } //calculate the area of a circle function calcCircle($cVal) { $areaValue = $calcValue * $calcValue * pi(); echo "<p>The area of a circle whose radius is {$calcValue} is {$areaValue}.</p>\n"; } //calculate the area of s square function calcSquare($cVal) { $areaValue = $calcValue * $calcValue; echo "<p>The area of a square whose sides are {$calcValue} is {$areaValue}.</p>\n"; } //function to test variables function testVars() { global $_POST; if (empty($_POST['vfld'])) { echo "<h3>Error</h3>"; echo "<p>You must enter a value!</p>\n"; return "no"; } else { return "yes"; } } //function to get variables function getVars(&$a, &$b, &$c) { global $_POST; $a->$workValue = $_POST['vfld']; $b->$workType = $_POST['tfld']; $c->$calcValue = (float) $workValue; return; } $workValue = (isset($_POST['vfld']))?$_POST['vfld']:''; $workType = (isset($_POST['tfld']))?$_POST['tfld']:''; if (isset($_POST['submit'])) { if ($_POST['submit'] == "Clear") { clearVars(); } elseif ($_POST['submit'] == "Calculate") { getVars(); $continue = testVars(); if ($continue == "yes") { switch ($workType) { case "circle": calcCircle($workVal); break; case "square": calcSquare($workVal); break; case "triangle": calcTriangle($workVal); break; } } } } <form method="post" action="hw06.php" id="form1" name="form1"> <p> Enter a number here : <input type="text" id="vfld" name="vfld" value="<?php echo $workValue; ?>"/> </p> <p> This number is: <br /> <input type="radio" name="tfld" value="circle" <?php if ($workType == "circle") { echo 'checked="checked"'; } ?> /> : the radius of a circle <br /> <input type="radio" name="tfld" value="square" <?php if ($workType == "square") { echo 'checked="checked"'; } ?> /> : the length of one side of a square <br /> <input type="radio" name="tfld" value="triangle" <?php if ($workType == "triangle") { echo 'checked="checked"'; } ?> /> : the length of one side of an equilateral triangle </p> <p> <input type="submit" name="submit" value="Calculate" /> <input type="submit" name="submit" value="Clear" /> </p> </form> <div id="footer"> </div> </body> </html> and here are my errors Warning: Missing argument 1 for getVars(), called in /studfs1/homepage/CISS-225/hw06.php on line 69 and defined in /studfs1/homepage/CISS-225/hw06.php on line 55 Warning: Missing argument 2 for getVars(), called in /studfs1/homepage/CISS-225/hw06.php on line 69 and defined in /studfs1/homepage/CISS-225/hw06.php on line 55 Warning: Missing argument 3 for getVars(), called in /studfs1/homepage/CISS-225/hw06.php on line 69 and defined in /studfs1/homepage/CISS-225/hw06.php on line 55 Notice: Undefined variable: workValue in /studfs1/homepage/CISS-225/hw06.php on line 57 Fatal error: Cannot access empty property in /studfs1/homepage/CISS-225/hw06.php on line 57 Any help would be greatly appreciated please explain too
  6. Thank you, that helped. I'm still having some issues, but I will work through them, i'm sure if it gets too confusing I will be back. What do you mean post code within [ code] ? Again thank you, it looks like you turned them into global variables? Or maybe you can explain a little more what you did?
  7. Hello people I'm having some trouble, and I kind think I know what it is, but for some reason I just can't figure it out. I think I need an isset function, but I'm not sure where to put it? Here is my code followed by my errors. <?php echo"<?xml version=\1.0\"encoding=\UFT-8\"\x3f>"; echo"\n"; ?> <!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtmll/DTD/xhtmll-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"lang="en"> <head> <title>My Second PHP Generated Document</title> </head> <body> <?php if (isset($_POST['submit'])) { if ($_POST['submit'] == "Clear") { $workValue = ""; $workType = ""; } elseif ($_POST['submit'] == "Calculate") { $workValue = $_POST['vfld']; $workType = $_POST['tfld']; $calcValue = (float) $workValue; if (empty($_POST['vfld'])) { echo "<h3>Error</h3>"; echo "<p>You must enter a value!</p>\n"; } elseif ($calcValue == 0) { echo "<h3>Error</h3>"; echo "<p>You must enter a number!</p>\n"; } elseif ($calcValue < 0) { echo "<h3>Error</h3>"; echo "<p>You must enter a positive number!</p>\n"; } elseif (empty($_POST['tfld'])) { echo "<h3>Error</h3>"; echo "<p>You must select a calculation type!</p>\n"; }} else { switch ($workType) { case "circle": $areaValue = $calcValue * $calcValue * pi(); break; case "square": $areaValue = $calcValue * $calcValue; // echo "The area of a square whose sides are" break; case "triangle": $halfSide = $calcValue/2; $otherSide = sqrt(($calcValue * calcValue) - ($halfSide * halfSide)); $areaValue = $otherSide * $halfSide; echo "The area of an equilateral triangle whose sides are $calcValue} is {areaValue}."; break; }} } ?> <form method="post" action="hw04.php" id="form1" name="form1"> <p> Enter a number here : <input type="text" id="vfld" name="vfld" value="<?php echo $workValue; ?>"/> </p> <p> This number is a: <br /> <input type="radio" name="tfld" value="circle" <?php if ($workType == "circle") { echo 'checked="checked"'; } ?> /> : the radius of a circle <br /> <input type="radio" name="tfld" value="square" <?php if ($workType == "square") { echo 'checked="checked"'; } ?> /> : the length of one side of a square <br /> <input type="radio" name="tfld" value="triangle" <?php if ($workType == "triangle") { echo 'checked="checked"'; } ?> /> : the length of one side of an equilateral triangle </p> <p> <input type="submit" name="submit" value="Calculate" /> <input type="submit" name="submit" value="Clear" /> </p> </form> <div id="footer"> <pre>This page written by: <cite>James Cozzy</cite> ©2011 and beyond</pre> </div> </body> </html> And my errors Enter a number here : This number is a: Notice: Undefined variable: workType in /studfs1/j-cozzy/homepage/CISS-225/hw04.php on line 69 /> : the radius of a circle Notice: Undefined variable: workType in /studfs1/j-cozzy/homepage/CISS-225/hw04.php on line 74 /> : the length of one side of a square Notice: Undefined variable: workType in /studfs1/j-cozzy/homepage/CISS-225/hw04.php on line 79 /> : the length of one side of an equilateral triangle any help would be much appreciated?
×
×
  • 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.