Jump to content
Larry Ullman's Book Forums

yrstruly

Members
  • Posts

    4
  • Joined

  • Last visited

Everything posted by yrstruly

  1. Does Anybody know how do do this from end of 1st Q to the rest, Especially Creating the APis and Idexes and Bash code etc? 1. DB Schema Design - Design a basic database to store the following information + A fleet of Vehicles - Include details such as mileage, vin numbers etc + A pool of drivers - Include relevant documentation, e.g. Drivesr license, ID Book + A group of routes - Marking out GPS coords for directions etc. is not necessary, just include a start & end address as well as any other info you believe to be pertinent + A drivers schedule, tying the above 3 tables together 2. SQL skill test CREATE TABLE ¿tUSER¿ ( ¿id¿ bigint(20) NOT NULL AUTO§INCREMENT, ¿id§number¿ varchar(20) NOT NULL, ¿first§names¿ varchar(100) NOT NULL, ¿last§name¿ varchar(100) NOT NULL PRIMARY KEY (¿id¿), <<INDEXES>> ) CREATE TABLE ¿tPROFILE¿ ( ¿id¿ bigint(20) NOT NULL AUTO§INCREMENT, ¿tUSER§id¿ bigint(20) DEFAULT NULL, ¿tTYPES§id¿ bigint(20) DEFAULT NULL, ¿value¿ varchar(100) NOT NULL, PRIMARY KEY (¿id¿), <<INDEXES>> ) CREATE TABLE ¿tTYPES¿ ( ¿id¿ bigint(20) NOT NULL AUTO§INCREMENT, ¿type¿ varchar(100) NOT NULL DEFAULT '', ¿description¿ varchar(255) NOT NULL, ¿deleted¿ tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (¿id¿), <<INDEXES>> ) Apply indexes to the above tables, and design a SINGLE query to retrieve a full list of user information based on: 2.A) an ID number 2. a cellphone number (¿Cellphone¿ is a record in the ¿tTYPES¿ table) 3. Write a re-usable script for importing information into the above 3 tables, from the example dsv file below: - NB - All data of the same type MUST be stored in the same format - NB2- You may assume that if a column doesn't seem to exist for a piece of data, that data type is listed in the tTYPES table <<BOF>> record§numberöid§numberöfirst nameölast nameömsisdnönetworköpointsöcard numberögender 312ö9101011234011öTest JunioröSmithö071 123 4321öMTNö73ö1241551413214444öM 313ö9012023213011öBoböSmithö27743334321öVodacomö3ö1231233232323244öM 314ö8706055678011öFranköFrankinsonö2771 156 1567ö8taö0ö1231123453214444öM 315ö9102078765011öMaryöVan Niekerkö+27(0)711236677öCellCö2ö1278933213214444öF 316ö9005074545011öSusanöWilsonö0821121124öCellCö705ö1231233216544444öF 317ö9101013232011öKatherineöJeevesö+271233214ö8taö112ö1231233678214444öF 318ö9101011234011öMatthewöMatthiasö0711111111öMTNöö1231555213214444öM 319ö9103126666011öMichaelöBayö085-6122-161ö8taö63ö1231244413214444öM 320ö7506023232300öTyroneöOlivierö711234322öCellCö89ö1234563213214444öM 321ö8901020304055öBurtöJacksonö071 4566544öVodacomö1ö4567233213214444öM <<EOF>> 4. After the data has been imported, Write a basic API to wrap the Database. Include the following function points: - Add a new User - Update a User's details - Delete a User - Search users 5. Describe what the following bash statement does: grep ¿date +%Y-%m-%d --date='1 day ago'¿ /path/to/file/FILE§PREFIX§Ö¿date +%Y%m%d --date='1 day ago'¿.dsv ö grep -v 'ERROR' ö cut -d "ö" -f 2 ö sed 's/Ü0/27/' 1. If a resturaunt serves: - 3 types of starters - 5 types of main - N types of drinks - 3 types of desserts + How many different meals are available, if you can order 1 item of each type? + How many different meals are available, if you can order 1 item of each type, BUT you can order 2 drinks as long as you do not order the same drink twice? + How many different meals are available, if you can only order a dessert OR a starter? 2. If you need to profile 1000 users, each with 3 different attributes, and each attribute has 4 possible values - before parsing any of the date: + What can we guarantee about the resultset? 3. A wild director appears. He uses "I want to profile my user database using an additional attribute!" - Describe a ¿super-effective¿ method which we can implement, which will allow us to handle an indeterminate number of this type of request. 4. If we have two seperate tables, the first detailing a list of registered club members, and the second detailing a list of competition entrants (assuming we have a key we can join on), what do/could the following resultsets represent: - The INTERSECT of the tables - The MINUS of the tables - The UNION of the tables
  2. Im using the latest Xammp package. Can you be more spesific bout the sql functions, what and where should i edit it?
  3. 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>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. Hi I have the following codes for registration and login. The registration doesnt seem to work, can anybody point out where the problem is or what am i not doing, should there be a text file included? ?<?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. ?> 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
×
×
  • Create New...