Jump to content

Truman

Members
  • Posts

    109
  • Joined

  • Last visited

Everything posted by Truman

  1. <!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" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>View Your Settings</title> <style type="text/css"> body { font-size: x-large; color: #999; } <?php // Script 9.2 - view_settings.php if (isset($_COOKIES['font_size'])) { print "\t\tfont-size: " . htmlentites($_COOKIES['font_size']) . "; \n } else { print "font-size: medium;"; } if (isset($_COOKIES['font_color'])) { print "color: #" . htmlentities($_COOKIES['font_color']) . ";\n"; } else { print "\t\tcolor: #ooo;"; } ?> </style> </head> <body> <p><a href="customize.php">Customize your settings.</a></p> <p><a href="reset.php">Reset your settings.</a></p> <p>yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda</p> </body> </html> Can you please tell me why I receive this message> Parse error: syntax error, unexpected 'size' (T_STRING) in C:\xampp\htdocs\my-site\view_settings.php on line 15 line 15 is: print "font-size: medium;";
  2. Can you please take a look at this code, from some reason it doesn't work. <?php // Script 8.9 - register.php define ('DEFINE', 'register'); include('templates/header.html'); print '<h2>Registration Form</h2> <p>Register so that you can take advantage of certain features like this, that, and the other things</p>'; print '<style type="text/css" media="screen"> .error { color: red; } </style>'; if ($_SERVER['REQUESTED_METHOD'] == 'POST') { $problem = FALSE; if (empty($_POST['first_name'])) { $problem = TRUE; print '<p class="error">Please enter your first name!</p>'; } if (empty($_POST['last_name'])) { $problem = TRUE; print '<p class="error">Please enter your last name!</p>'; } if (empty($_POST['email'])) { $problem = TRUE; print '<p class="error">Please enter your email address.</p>'; } if (empty($_POST['password1'])) { $problem = TRUE; print '<p class="error">Please enter a password.</p>'; } if ($_POST['password1'] != $_POST['password2']) { $problem = TRUE; print '<p class="error">Your password did not match your confirm password.</p>'; } if (!$problem) { print '<p>You are now registered.</p>'; } $_POST = array(); } else { print '<p class="error">Please try again!</p>'; } ?> <form action="register.php" method="post"> <p>First Name: <input type="text" name="first_name" size="20" value="<?php if (isset($_POST['first_name'])) { print htmlspecialchars($_POST['first_name']); } ?>" /></p> <p>Last Name: <input type="text" name="last_name" size="20" value="<?php if (isset($_POST['last_name'])) { print htmlspecialchars($_POST['last_name']); } ?>" /></p> <p>Email: <input type="text" name="email" size="20" value="<?php if (isset($_POST['email']) { print htmlspecialchars($_POST['email']);} ?> /></p> <p>Password: <input type="password" name="password1" size="20" value="<?php if (isset($_POST['password1']) { print htmlspecialchars($_POST['password']); } ?> /></p> <p>Confirm Password: <input type="password" name="password2" size="20" value="<?php if (isset($_POST['password2'])) { print htmlspecialchars ($_POST[password2']); } ?>" /></p> <p><input type="submit" name="submit" value="Register!"> /></p> </form> <?php include('templates/footer.html'); ?> I receive a note: Parse error: syntax error, unexpected '{' in C:\xampp\htdocs\my-site\register.php on line 46 line 46 is: <p>Email: <input type="text" name="email" size="20" value="<?php if (isset($_POST['email']) { print
  3. OK, I forgot one quotation but the topic is not about that. I am saying that I don't understand the distinguished code.
  4. I'm working of registration form and I have a problem with understanding one of the codes. <?php // Script 8.9 - register.php define ('DEFINE', 'register'); include('templates/header.html'); print '<h2>Registration Form</h2> <p>Register so that you can take advantage of certain features like this, that, and the other things</p>'; print '<style type="text/css" media="screen"> .error { color: red; } </style>'; if ($_SERVER['REQUESTED_METHOD'] == 'POST') { $problem = FALSE; if (empty($_POST['first_name'])) { $problem = TRUE; print '<p class="error">Please enter your first name!</p>'; } if (empty($_POST['last_name'])) { $problem = TRUE; print '<p class="error">Please enter your last name!</p>'; } if (empty($_POST[email'])) { $problem = TRUE; print '<p class="error">Please enter your email address.</p>'; } if (empty($_POST['password1'])) { $problem = TRUE; print '<p class="error">Please enter a password.</p>'; } if ($_POST['password1'] != $_POST['password2']) { $problem = TRUE; print '<p class="error">Your password did not match your confirm password.</p>'; } if (!$problem) { print '<p>You are now registered.</p>' } $_POST = array(); } else { print '<p class="error">Please try again!</p> } } ?> this part: if (!$problem) { print '<p>You are now registered.</p>' } Why are we using exclamation mark here? I already defined $problem = FALSE at the beginning of the whole code. That means that there is no problem. If we reverse it to TRUE it will mean that there is a problem with registration but in that case the user shouldn't see "You are now registered". The if condition is fulfilled in any case because with don't have any '<', '>' or '=='.
  5. Thank you, I didn't know this...In the book it's not mentioned. Now it works fine.
  6. I don't think so, this html executes and I see content. here is the page:
  7. I'm making now a template and within header.html I placed two date functions but when I run the code I don't see them on the browser. Don't know why, everything is by the book. <!DOCTYPE html> <head> <title> </title> <?php // Print the page title if (defined('TITLE')) { print TITLE; } else { print 'Raise High the Roof Beam! A J.D. Salinger Fan Club'; } ?> </head> <body> <div id="wrapper"> <div id="header"> <p class="description">A J.D. Salinger Fan Club</p> <h1><a href="index.php">Raise High the Roof Beam!</a></h1> <ul id="nav"> <li><a href="books.php">Books</a></li> <li><a href="#">Stories</a></li> <li><a href="#">Quotes</a></li> <li><a href="login.php">Login</a></li> <li><a href="register.php">Register</a></li> </ul> </div><!-- header --> <div id="sidebar"> <h2>Favorite Quotes</h2> <p class="news">I don't exactly know what I mean by that, but I mean it.< /br> <em>Catcher in the Rye</em></p> <p class="news">I privately say to you, old friend...please accept from me this unpretentious bouqet of early-blooming parentheses: (((()))). <em>Raise high the Roof Beam, Carpenters and Seymour: An Introduction</em></p> <p><?php date_default_timezone_set('America/New_York'); print date('g:i a l F j'); ?></p> </div><!-- sidebar --> <div id="content"> <!-- BEGIN CHANGEALBE CONTENT. --> <!-- Script 8.6 - header.html -->
  8. Truman

    array_diff_key()

    I don't understand this array function although I read php manual. This is an example: <?php $array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); $array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); var_dump(array_diff_key($array1, $array2)); ?> and this is output: array(2) { ["red"]=> int(2) ["purple"]=> int(4)} I don't see any connection here, why is for example key red different from the key blue in the second array but the key blue from the first arrays differs from the key green in the second array? Or I got this completely wrong?
  9. Thanks, and I learn't a new function.
  10. So the author of this book is wrong? That's strange... p.s. I understand that you are right. It doesn't work.
  11. I'm working on multidimensiona arrays, I ran this code thru php checker and everything looks fine. <!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" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Larry Ullman's books and chapters.</title> </head> <body> <h1>Some of Larry Ullman's books</h1> <?php // Script 7.4 - books.php $phpvqs = array (1 => 'Getting Started with PHP', 'Variables', 'HTML Forms and PHP', 'Using Numbers'); $phpadv = array (1 => 'Advanced PHP Techniques', 'Developing Web Applications', 'Advanced Databe Concepts', 'Security Techniques'); $phpmysql = array (1 => 'Introduction to PHP', 'Programming with PHP', 'Creating Dynamic Web Sites', 'Introduction to MySQL'); $books = array ( 'PHP VQS' => $phpvqs, 'PHP Advanced VQP' => $phpadv, 'PHP and MySQL VQP' => $phpmysql ); print "<p>The third chapter of my first book is <i>{$books['PHP VQS'][3]}</i>.</p>"; print "<p>The first chapter of my second books is <i>{$books['PHP Advanced VQP'][1]}</i>.</p>"; print "<p>The fourth chapter of my fourt books is <i>{$books['PHP and MySQL VQP'][4]}</i>.</p>"; foreach ($books as $key => $value) { print "<p>$key: $value</p>\n"; } ?> </body> </html> But it sends message: Notice: Array to string conversion in C:\xampp\htdocs\my-site\books.php on line 24 PHP VQS: Array Notice: Array to string conversion in C:\xampp\htdocs\my-site\books.php on line 24 PHP Advanced VQP: Array Notice: Array to string conversion in C:\xampp\htdocs\my-site\books.php on line 24 PHP and MySQL VQP: Array ------------------------------------------------------------------------------------------------------------------- line 24 is: print "<p>$key: $value</p>\n";
  12. No BOM. By the way, what is bom?
  13. Windows, UTF-8 apply to opened ANSI files.
  14. Still the same thing...I give up and moving forward.
  15. I added '?wellthisis=bull' and receive the same message.
  16. And again: Parse error: syntax error, unexpected '{' in C:\xampp\htdocs\my-site\handle_reg.php on line 33
  17. if ( is_numeric($_POST['year']) && (strlen($_POST['year'] ) == 4)) { if ($_POST['year'] < 2015) { $age = 2015 - $_POST['year']; } else { print '<p class="error">Either you entered your birth year wrong or you come from the future!</p>'; $okay = FALSE; } } else { print '<p class="error">Please enter the year you were born as four digits.</p>'; $okay = FALSE; }
  18. After copypaste of your code I receive the same message. If you want I can attach html and php code that you can see it yourself.
  19. And now again I receive that '{' is unexpected. I don't understand what is wrong with this curly brace...It's not about parenthesis now...
  20. I fixed the previos problem but now the message is: - Please enter the year you were born as four digits. ...and I entered 4 digits. Any idea why this conditional doesn't work?
  21. I receive the same message after eding the parenthesis, that '{' is unexpected...
  22. Again a thing I don't understand, I'm working on nesting conditionals: <?php // Script 6.2 handle_reg.php $okay = TRUE; if (empty($_POST['email'])) { print '<p class="error">Please enter your email address.</p>'; $okay = FALSE; } if (empty($_POST['password'])) { print '<p class="error">Please enter your password.</p>'; $okay = FALSE; } if (empty($_POST['confirm'])) { print '<p class="error">Please enter your password.</p>'; $okay = FALSE; } if ($_POST['password'] != $_POST['confirm']) { print '<p class="error">Your confirmed password does not match the original password.</p>'; $okay = FALSE; } if ( is_numeric($_POST['year']) AND (strlen($_POST['year'] == 4) ) { if ($_POST['year'] < 2015) { $age = 2015 - $_POST['year']; } else { print '<p class="error">Either you entered your birth year wrong or you come from the future!</p>'; $okay = FALSE; } } else { print '<p class="error">Please enter the year you were born as four digits.</p>'; $okay = FALSE; } if (!isset($_POST['terms']) AND ($_POST['terms'] == 'YES') ) { print '<p class="error">You must accept the terms.</p>'; $okay = FALSE; } if ($okay) { print '<p>You have been successfully registered.</p>'; print "<p>You will turn $age this year</p>"; } ?> it says: Parse error: syntax error, unexpected '{' in C:\xampp\htdocs\my-site\handle_reg.php on line 32 line 32 is: if ( is_numeric($_POST['year']) AND (strlen($_POST['year'] == 4) ) { Why is opening curly brace unexpected?
  23. I used double quotes, it works great. Thank you.
  24. An another problem, php code checker see no mistake: <!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" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Registration</title> <style type="text/css" media="screen"> .error { color: red;} </style> </head> <body> <h1>Registration Results</h1> <?php // Script 6.2 handle_reg.php $okay = TRUE; if (empty($_POST['email'])) { print '<p class="error">Please enter your email address.</p>'; $okay = FALSE; } if (empty($_POST['password'])) { print '<p class="error">Please enter your password.</p>'; $okay = FALSE; } if (empty($_POST['confirm'])) { print '<p class="error">Please enter your password.</p>'; $okay = FALSE; } if ($_POST['password'] != $_POST['confirm']) { print '<p class="error">Your confirmed password does not match the original password.</p>'; $okay = FALSE; } if (is_numeric($_POST['year'])) { $age = 2016 - $_POST['year']; } else { print '<p>Please enter the year you were born as four digits.</p>'; $okay = FALSE; } if ($_POST['year'] >= 2016) { print '<p class="error">Either you enter your birth year wrong or you come from the future!</p>'; $okay = FALSE; } if ($okay) { print '<p>You have been successfully registered.</p>'; print '<p>You will turn $age this year</p>'; } ?> </body> </html> and I receive: Registration ResultsYou have been successfully registered. You will turn $age this year I don't understand why it doesn't show $age variable, the formula should be OK.
×
×
  • Create New...