Sunday, April 29, 2012

ITC280 Update 4

1. We can use print_r to view the contents of an array.

$aFruit = array("bananas","apples","oranges");
print_r($aFruit);


2. We can use the HTML pre tag to view print_r() the way it was meant to be seen.

$aFruit = array("bananas","apples","oranges");
echo "<pre>";
print_r($aFruit);
echo "</pre>";


3. We should used var_dump() instead of print_r() because var_dump() works with almost everything.

var_dump($aFruit);

4. We can use var_dump() for more than one item:

$aFruit = array("bananas","apples","oranges");
$myName = "Leopaul";
echo "<pre>";
var_dump($aFruit,$myName);
echo "</pre>";


5. We can use a for loop to examine the contents of an array:

$aFruit = array("bananas","apples","oranges");
for($x=0;$x<count($aFruit);$x++)
{
echo $aFruit[$x] . "<br />";
}


6. We can add to an array by using empty []
$aCheese = array();
$aCheese[0] = "cheddar";
$aCheese[1] = "swiss";
$aCheese[2] = "limburger";
$aCheese[] = "gouda";
$aCheese[] = "feta";
for($x=0;$x<count($aCheese);$x++)
{
echo $x . ") " . $aCheese[$x] . "<br />";
}


7. We can use a foreach loop to go one direction only.

$aCheese = array();
$aCheese[0] = "cheddar";
$aCheese[1] = "swiss";
$aCheese[2] = "limburger";
$aCheese[] = "gouda";
$aCheese[] = "feta";


foreach($aCheese as $fromage)
{
    echo $fromage . "<br />;
}


8. We can use an associative array to store string data as keys.

$nav1 = array();
$nav1["index.php"] = "Home Page";
$nav1["contact.php"] = "Contact Page";
$nav1["about_us.php"] = "About Us";
$nav1["links.php"] = "Links";


foreach($nav1 as $url => $text)
{
    echo '<a href="' . $url . '">' . $text . '</a><br />';
}


9. Email1.php starting point for Wednesday

<?php
//email1.php
include 'header.php';
define("THIS_PAGE",basename($_SERVER['PHP_SELF']));
if(isset($_POST['FirstName']))
{//email data, then thank user!
echo $_POST['FirstName'] . "<br />";
echo '<a href="' . THIS_PAGE . '">RESET</a>';
}else{
?>
<form action="<?=THIS_PAGE?>" method="post">
First Name: <input type="text" name="FirstName" /><br />
Last Name: <input type="text" name="LastName" /><br />
<input type="submit" value="Email Us!" />
</form>
<?php
}//end of formhandler
include 'footer.php';
?>


10. PHP’s mail function

mail("ldelro02@seattlecentral.edu","My Subject!","My Text","noreply@seattlecentral.edu");

11. We can replace the strings with variables declared at the top of the page.
mail($ToEmail,$Subject,"My Text",$FromEmail);

12. Using var_dump() to view the entire POST array.
echo "<pre>";
Var_dump($_POST);
echo "</pre>";


13. Use PHP_EOL to create operating system specific carriage returns.

*SCORES

- Pop Quiz 5: 10/10 (100%)
- Pop Quiz 6: 10/10 (100%)

*NOTES

I'm very glad that Mr. Newman didn't give us test for this week but Assignment 4 seems to be a bit more difficult. Surely we did half of that in class but how can I finish the other half of Assingment 4 by any means of putting something like a checkbox, radio, or something that is more of a multiple choice?

It said that the form handler must:

1) Email you the information on the form
2) Include at least 2 radio buttons, 3 checkboxes, 2 textboxes and 1 textarea for comments
3) Protect itself from invalid data entry (hacking)
4) Require a valid email from the user and require first and last name textbox entry

...How can we finish this? Clearly we have to finish this by Monday midnight...

...that is all.

1 comment:

Bill said...

Leopaul,

Thank you for your nice post!

Not to worry about A4! We'll cover all of that in class!

See you tomorrow!

Bill