Jump to content

yrstruly

Members
  • Posts

    172
  • Joined

  • Last visited

Posts posted by yrstruly

  1. Im getting these erros with the register and login codes:<!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>Register</title> <style type="text/css" media="screen"> .error { color: red; } </style></head><body><h1>Register</h1><?php // Script 11.6 - register.php/* This script registers a user by storing their information in a text file and creating a directory for them. */ // Identify the directory and file to use:$dir = '../users/';$file = $dir . 'users.txt'; if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Handle the form. $problem = FALSE; // No problems so far. // Check for each value... if (empty($_POST['username'])) { $problem = TRUE; print '<p class="error">Please enter a username!</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 confirmed password!</p>'; } if (!$problem) { // If there weren't any problems... if (is_writable($file)) { // Open the file. // Create the data to be written: $subdir = time() . rand(0, 4596); $data = $_POST['username'] . "\t" . md5(trim($_POST['password1'])) . "\t" . $subdir . PHP_EOL; // Write the data: file_put_contents($file, $data, FILE_APPEND | LOCK_EX); // Create the directory: mkdir ($dir . $subdir); // Print a message: print '<p>You are now registered!</p>'; } else { // Couldn't write to the file. print '<p class="error">You could not be registered due to a system error.</p>'; } } else { // Forgot a field. print '<p class="error">Please go back and try again!</p>'; } } else { // Display the form. // Leave PHP and display the form:?> <form action="register.php" method="post"> <p>Username: <input type="text" name="username" size="20" /></p> <p>Password: <input type="password" name="password1" size="20" /></p> <p>Confirm Password: <input type="password" name="password2" size="20" /></p> <input type="submit" name="submit" value="Register" /></form> <?php } // End of submission IF. ?></body></html> Register Please enter a username!'; } if (empty($_POST['password1'])) { $problem = TRUE; print 'Please enter a password!'; } if ($_POST['password1'] != $_POST['password2']) { $problem = TRUE; print 'Your password did not match your confirmed password!'; } if (!$problem) { // If there weren't any problems... if (is_writable($file)) { // Open the file. // Create the data to be written: $subdir = time() . rand(0, 4596); $data = $_POST['username'] . "\t" . md5(trim($_POST['password1'])) . "\t" . $subdir . PHP_EOL; // Write the data: file_put_contents($file, $data, FILE_APPEND | LOCK_EX); // Create the directory: mkdir ($dir . $subdir); // Print a message: print 'You are now registered!'; } else { // Couldn't write to the file. print 'You could not be registered due to a system error.'; } } else { // Forgot a field. print 'Please go back and try again!'; } } else { // Display the form. // Leave PHP and display the form: ?> Username: Password: Confirm Password: <!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>Login</title></head><body><h1>Login</h1><?php // Script 11.8 - login.php/* This script logs a user in by check the stored values in text file. */ // Identify the file to use:$file = 'users/users.txt'; if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Handle the form. $loggedin = FALSE; // Not currently logged in. // Enable auto_detect_line_settings: ini_set('auto_detect_line_endings', 1); // Open the file: $fp = fopen($file, 'rb'); // Loop through the file: while ( $line = fgetcsv($fp, 200, "\t") ) { // Check the file data against the submitted data: if ( ($line[0] == $_POST['username']) AND ($line[1] == md5(trim($_POST['password']))) ) { $loggedin = TRUE; // Correct username/password combination. // Stop looping through the file: break; } // End of IF. } // End of WHILE. fclose($fp); // Close the file. // Print a message: if ($loggedin) { print '<p>You are now logged in.</p>'; } else { print '<p style="color: red;">The username and password you entered do not match those on file.</p>'; } } else { // Display the form. // Leave PHP and display the form:?> <form action="login.php" method="post"> <p>Username: <input type="text" name="username" size="20" /></p> <p>Password: <input type="password" name="password" size="20" /></p> <input type="submit" name="submit" value="Login" /></form> <?php } // End of submission IF. ?> </body></html> Login You are now logged in.'; } else { print 'The username and password you entered do not match those on file. '; } } else { // Display the form. // Leave PHP and display the form: ?> Username: Password: This is the live one:http://project2013.net78.net/login.php

  2. When i run the code, it gives the following output: Hello, $name!"; ?> <!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>Greetings!</title></head><body><?php // Script 3.7 - hello.phpini_set ('display_errors', 1); // Let me learn from my mistakes!error_reporting (E_ALL | E_STRICT); // Show all possible problems!// This page should receive a name value in the URL.// Say "Hello":$name = $_GET['Celia'];print "<p>Hello, <span style=\"font-weight: bold;\">$name</span>!</p>";?></body></html><!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>Greetings!</title></head><body><!-- Script 3.6 - hello.html --><div><p>Click a link to say hello:</p><ul> <li><a href="hello.php?name=Michael">Michael</a></li> <li><a href="hello.php?name=Celia">Celia</a></li> <li><a href="hello.php?name=Jude">Jude</a></li> <li><a href="hello.php?name=Sophie">Sophie</a></li></ul></div></body></html> Im including the html code:

  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...ransitional.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>Add a Blog Entry</title></head><body><h1>Add a Blog Entry</h1><?php // Script 12.5 - add_entry.php/* This script adds a blog entry to the database. */if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Handle the form. // Connect and select: $dbc = mysql_connect('localhost', 'root', 'musica'); mysql_select_db('myblog', $dbc); // Validate the form data: $problem = FALSE; if (!empty($_POST['title']) && !empty($_POST['entry'])) { $title = trim(strip_tags($_POST['title'])); $entry = trim(strip_tags($_POST['entry'])); } else { print '<p style="color: red;">Please submit both a title and an entry.</p>'; $problem = TRUE; } if (!$problem) { // Define the query: $query = "INSERT INTO entries (entry_id, title, entry, date_entered) VALUES (0, '$title', '$entry', NOW())"; // Execute the query: if (@mysql_query($query, $dbc)) { print '<p>The blog entry has been added!</p>'; } else { print '<p style="color: red;">Could not add the entry because:<br />' . mysql_error($dbc) . '.</p><p>The query being run was: ' . $query . '</p>'; } } // No problem! mysql_close($dbc); // Close the connection. } // End of form submission IF.// Display the form:?><form action="add_entry.php" method="post"> <p>Entry Title: <input type="text" name="title" size="40" maxsize="100" /></p> <p>Entry Text: <textarea name="entry" cols="40" rows="5"></textarea></p> <input type="submit" name="submit" value="Post This Entry!" /></form></body></html> iI'm getting the folowing output, what am i doing wrong? Add a Blog EntryPlease submit both a title and an entry.'; $problem = TRUE; } if (!$problem) { // Define the query: $query = "INSERT INTO entries (entry_id, title, entry, date_entered) VALUES (0, '$title', '$entry', NOW())"; // Execute the query: if (@mysql_query($query, $dbc)) { print 'The blog entry has been added!'; } else { print 'Could not add the entry because:' . mysql_error($dbc) . '.The query being run was: ' . $query . ''; } } // No problem! mysql_close($dbc); // Close the connection. } // End of form submission IF. // Display the form: ?>Entry Title:Entry Text:

  4. At that point there is no data base connection.Only the codes given and then a page thats suppose to show after i have login.I have followed the steps in the book, so i dont know what i have been missing or doing wrong.Could it be that there need to be a text file to store the username n password when you register , which stores the data or what is missing?The sending of the email im also unlcear about as it dot not explain that you need a specific server ect?

  5. Im trying to connect to mysql database and get the folllowing error: Could not connect to MySQL:No connection could be made because the target machine actively refused it. . Im running this code: <!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>Connect to MySQL</title></head><body><?php // Script 12.2 - mysql_connect.php #2/* This script connects to the MySQL server. */ // Attempt to connect to MySQL and print out messages:if ($dbc = @mysql_connect('localhost', '', '')) { print '<p>Successfully connected to MySQL!</p>'; mysql_close($dbc); // Close the connection. } else { print '<p style="color: red;">Could not connect to MySQL:<br />' . mysql_error() . '.</p>'; } ?></body></html>Also dont work when i run it like:if ($dbc = mysql_connect('localhost','username', 'password')) { Im using Xammp

  6. Im working throught tutorials from a book by Larry Ullman. I dont know if the page is going to log in only after i have developed and connected the database? From what i understand the page is suppose to register the user at this point and then send a link to your email adress and then you login that takes you to a welcome page. The welcome is already created, but dont display when i try to login. I dont think the registration is working, will it only worked after the datase base is connected?

  7. HiI have the following codes for registration and login. The registration doesnt seem to work, can anybody oint out where the problem is ?<?php // Script 8.10 - register.php #2/* This page lets people register for the site (in theory). */// Set the page title and include the header file:define('TITLE', 'Register');include('header.html');// Print some introductory text:print '<h2>Registration Form</h2> <p>Register so that you can take advantage of certain features like this, that, and the other thing.</p>'; // Add the CSS:print '<style type="text/css" media="screen"> .error { color: red; }</style>';// Check if the form has been submitted:if ($_SERVER['REQUEST_METHOD'] == 'POST') { $problem = FALSE; // No problems so far. // Check for each value... 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']) || (substr_count($_POST['email'], '@') != 1) ) { $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 confirmed password!</p>'; } if (!$problem) { // If there weren't any problems... // Print a message: print '<p>You are now registered!<br />Okay, you are not really registered but...</p>'; // Send the email: $body = "Thank you for registering with the J.D. Salinger fan club! Your password is '{$_POST['password1']}'."; mail($_POST['email'], 'Registration Confirmation', $body, 'From: admin@example.com'); // Clear the posted values: $_POST = array(); } else { // Forgot a field. print '<p class="error">Please try again!</p>'; }} // End of handle form IF.// Create the form:?><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 Address: <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['password1']); } ?>" /></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('footer.html'); // Need the footer. ?> <?php // Script 8.13 - login.php #2/* This page lets people log into the site (in theory). */// Set the page title and include the header file:define('TITLE', 'Login');include('header.html');// Print some introductory text:print '<h2>Login Form</h2> <p>Users who are logged in can take advantage of certain features like this, that, and the other thing.</p>';// Check if the form has been submitted:if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Handle the form: if ( (!empty($_POST['email'])) && (!empty($_POST['password'])) ) { if ( (strtolower($_POST['email']) == 'me@example.com') && ($_POST['password'] == 'testpass') ) { // Correct! // Redirect the user to the welcome page! ob_end_clean(); // Destroy the buffer! header ('Location: welcome.php'); exit(); } else { // Incorrect! print '<p>The submitted email address and password do not match those on file!<br />Go back and try again.</p>'; } } else { // Forgot a field. print '<p>Please make sure you enter both an email address and a password!<br />Go back and try again.</p>'; }} else { // Display the form. print '<form action="login.php" method="post"> <p>Email Address: <input type="text" name="email" size="20" /></p> <p>Password: <input type="password" name="password" size="20" /></p> <p><input type="submit" name="submit" value="Log In!" /></p> </form>';}include('footer.html'); // Need the footer.?>

  8. Thank you guys. I think it is the laptop thats the problem. I have run the same codes via an online server and it works! Another problem, when i run thiscode<!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>Greetings!</title></head><body><?php // Script 3.7 - hello.php ini_set ('display_errors', 1); // Let me learn from my mistakes!error_reporting (E_ALL | E_STRICT); // Show all possible problems! // This page should receive a name value in the URL. // Say "Hello":$name = $_GET[''];print "<p>Hello, <span style=\"font-weight: bold;\">$name</span>!</p>"; ?></body></html> I get this output: PHP Error Message Notice: Undefined index: Tony in /home/a9677473/public_html/hello.php on line 17

    Hello, ! The html code is working fine and all seems to be in place, what am i doing wrong here?

  9. The answer is not here cause i've been doing it like you guys said and its not working!It keeps on giving me this "; ?> on every page/code i do. Seems to only print the html or partially php...I saw post on the phpini file that needs to be set to on and not off, can this be it. In the xampp php file is php.ini-development and php.ini-production

  10. The answer is i dont know, maybe its just the html code thats working, obviuosly. So how do i fix this problem, i am running it through my localhost?

  11. When i run this code:<!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>Hello, World!</title></head><body><p>The following was created by PHP:<?phpprint "<span style=\"font-weight:bold;\">Hello, world!</span>";?></p></body></html> It executes on the server, but its not making the "Hello, World" bold and reads like this: The following was created by PHP: Hello, world!" ?> Is there a quotation to many or any brackets that should not be there?

  12. My root is file:///C:/xampp/htdocs/mylife.php, thats what it shows. I have used xammp before and it worked, i could execute my files from any folder just as long as its routed correctly. Why is the the previous code working and not the last one, thats the problem or what im asking? The code is executing just not the <?phpprint "Hello, world!";?> When i put it http http://localhost it automatically direct it to file:///C:/xampp/htdocs/mylife.php. Whats wrong?

  13. I am running it on localhost so it shows:file:///C:/xampp/hello1.php. When im running the following code it displays correctly, so i dont understand why the others wont execute and its url is: file:///C:/xampp/www/welcome.html<!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>Welcome to this Page!? </title></head><body><h1>This is a basic XHTML page!? </h1><br /><p>Even with <span style=?"font-size: 150%;">some</span>? decoration, it's still not very? exciting.</p></body>

  14. Hello I am doing this book by Larry Ullman. PHP for the Web Visual Quick start Guide. Im having trouble with a basic code like this: 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML1.0 Transitional//EN"2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">3 <html xmlns="http://www.w3.org/1999/xhtml"xml:lang="en" lang="en">4 <head>5 <meta http-equiv="content-type"content="text/html; charset=utf-8" />6 <title>Hello, World!</title>7 </head>8 <body>9 <p>The following was created by PHP:10 <?php11 print "Hello, world!";12 ?>13 </p>14 </body>15 </html> Its not printing "Hello, World", all it prints is The following was created by php. What am i doing wrong? I find that most of the codes executes like this from this book. Pls HELP

  15. Hello I have installed Xammp on my laptop running windows vistaI also have been using skype and did stop the use of port 80 as it blocked appache running. It all seems to be working now, accept for when im running my php code, it shows the page with the source code, what is missing/wrong? Thank you

  16. HelloI have installed xampp on my pc and it looks fine cause system is running. Im having trouble running my php file on my pc/local host. It keeps on asking if i wanna save the file and the file is already saved and also dont wanna download the file when i press save.Please help?

×
×
  • Create New...