I am working through the beginning php 4 book by wrox and I can not get
the example to work.
It is reading and passing the form data but the cookies is not being
written or read here is my code.

Also why can I not place these variables in line with the echo
statement. If I do it doesn't work.
I thought I could just echo "face=$_POST['type_sel'] " <- but it does
not work.

if ( $_POST['type_sel'] ) echo "face=" . $_POST['type_sel'] . " ";
if ( $_POST['size_sel'] ) echo "size=" . $_POST['size_sel'] . " ";

Paul Kraus

Code
----
<?php
//cookies.php
if ($_POST['type_sel']) setcookie ("font['type']", $_POST['type_sel'],
time()+3600);
if ($_POST['size_sel']) setcookie ("font['size']", $_POST['size_sel'],
time()+3600);
$type = array ("arial", "helvetica", "sans-serif", "courier");
$size = array ("1","2","3","4","5","6","7");
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>Testing Cookies</title>
  </head>
  <body>
    <h1>Testing Cookies PHP</h1>
    <hr>
    <div align='center'>
      <form method = post>

        What font type would you like to use?
        <select name="type_sel">
          <option selected value=''>default</option>
            <?php foreach ($type as $var) echo (
"<option>$var</option>"); ?>
          </select>
          <br><br><br>

        What font size would you like to use?
        <select name="size_sel">
          <option selected value=''>default</option>
            <?php  foreach ($size as $var) echo (
"<option>$var</option>" ); ?>
          </select>
          <br><br><br>
          <input type=submit>

        </form>

      <b>Your cookies say:</b><br>
      <?php
        echo ( "<font ");
        echo ( "type=$font[type]" );
        if ( $font['type'] ) echo "face=$font['type'] ";
        if ( $font['size'] ) echo "size=$font['size'] ";
        echo ( ">" );
        echo ( "\$font['type']  = $font['type']<br>" );
        echo ( "\$font['size']  = $font['size']<br>" );
        echo ( "</font><br>" );
      ?>

      <b>Your form variables say:</b><br>
      <?php
        echo ( "<font " );
        if ( $_POST['type_sel'] ) echo "face=" . $_POST['type_sel'] . "
";
        if ( $_POST['size_sel'] ) echo "size=" . $_POST['size_sel'] . "
";
       
        echo ( ">" );
        echo "type_sel = " . $_POST['type_sel'] . "<br>";
        echo "size_sel = " . $_POST['size_sel'] . "<br>";
        echo ( "</font>" );
      ?>
    </div>

    <address><a href="mailto:[EMAIL PROTECTED]"></a></address>
    <!-- Created: Thu Apr 03 21:10:49 Eastern Standard Time 2003 -->
    <!-- hhmts start -->
    Last modified: Thu Apr 03 21:58:00 Eastern Standard Time 2003
    <!-- hhmts end -->
    </body>
</html>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to