Internet and web technology ppt

ppt on internet technology and internet programming and web technology ppt
Dr.ShaneMatts Profile Pic
Dr.ShaneMatts,United States,Teacher
Published Date:23-07-2017
Your Website URL(Optional)
Comment
COM1004 Web and Internet Technology  When a user submits a web form, how do we save the information to a database?  How do we retrieve that data later? ID NAME EMAIL MESSAGE TIMESTAMP 1 Mike mikedcs Hi there 2012-03-03 10:31:04 2 Steve stevedcs Gotcha 2012-03-03 10:33:07 3 Mike mikedcs Great - it works 2012-03-04 08:17:35  Design the form  Identify the information you want the user to provide  Create input tags accordingly  Here we want the user to provide Name, Email and Message data  Design a MySQL table to hold the data  Draw a picture of the required database table(s)  There should be a column for each input tag in the form that contain the relevant data  You may want to store extra data that isn't in the form (e.g. a timestamp and message ID) ID NAME EMAIL MESSAGE TIMESTAMP 1 Mike mikedcs Hi there 2012-03-03 10:31:04 2 Steve stevedcs Gotcha 2012-03-03 10:33:07 3 Mike mikedcs Great - it works 2012-03-04 08:17:35  Does the table exist?  Don't assume it exists just because you created it earlier - it may have been deleted in the mean time…  If necessary, create the table CREATE TABLE IF NOT EXISTS mytable (col1, col2, …); Retrieve data Submit data • If the user provided  If the user provided data, check it makes data, check it makes sense sense • Create a SELECT  Create an INSERT query to get data query to add data to from the table the table • Submit the query to  Submit the query to MySQL MySQL • Check for success  Check for success The data you  Your request has requested is not been processed; you available. Please try will hear from us again later. within 7 days Here is the data you  Sorry, we couldn't requested. handle your request. Please try again later. We're told what the form should look like • Data • Name • Email • Message • Required activities • Submit data • Retrieve data Single-line text inputs  Data input name='name' …  Name input name='email' …  Email Multi-line text input  Message textarea name='msg' /textarea  Activities Two buttons  Submit data input type='submit'  Retrieve data name='submit' input type='submit' name='retrieve' Please enter your name, email address, and message. form action ="mysql-01.php" method="get" table cellpadding="4" border="1" trtd align="right"Name/td tdinput name="name" type="text" maxlength="31" //td/tr trtd align="right"Email/td tdinput name="email" type="text" maxlength="63" //td/tr trtd align="right"Message/td tdtextarea name="msg" cols="30" rows="10"/textarea/td/tr trtd align="center" colspan="2" input type="submit" value=" Submit " name="submit" / input type="submit" value=" Retrieve " name="retrieve" / /td/tr /table/form  We need to store  Name, Email, Message  We will add extra information:  Message ID (primary key), timestamp id name email msg tstamp 1 Mike mikedcs Hi there 2012-03-03 10:31:04 2 Steve stevedcs Gotcha 2012-03-03 10:33:07 3 Mike mikedcs Great - it works 2012-03-04 08:17:35 mytable (id, name, email, msg, tstamp) id name email msg tstamp 1 Mike mikedcs Hi there 2012-03-03 10:31:04 2 Steve stevedcs Gotcha 2012-03-03 10:33:07 3 Mike mikedcs Great - it works 2012-03-04 08:17:35 Specify the column types. I'll use the following: • id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY • name VARCHAR(16) • email VARCHAR(32) • msg VARCHAR(100) • tstamp DATETIME  CHAR(n)  Exactly n characters, requires n bytes storage  VARCHAR(n)  Up to n characters, (length+(1 or 2)) bytes  TEXT  Up to 65535 characters, storage varies  MEDIUMTEXT  Up to 16,777,215 characters  LONGTEXT  Up to 4,294,967,295 characters  ENUM('square', 'circle', 'triangle')  A fixed list of allowed strings  DATETIME (8 bytes)  1000-01-01 00:00:00 to 9999-12-31 23:59:59  DATE (3 bytes)  1000-01-01 to 9999-12-31  TIME (3 bytes)  -838:59:59 to 838:59:59  YEAR(2), YEAR(4) (1 byte)  4-digit: 1901 - 2155  2-digit: 1970 - 2069 (specified as 00-99)  TIMESTAMP (4 bytes)  1970-01-01 00:00:01 to 2038-01-19 03:14:07  Before we can create the table, we need to connect to the MySQL server on the DCS network  To do so, we need to provide sensitive information (our passwords)  How can we make sure no-one can download this information?  Technical solutions: htaccess, htpasswd  Another solution: input the data from another file ?php / "info.php" defines the values of myDbase - my database myPass - my password myName - my username myHost - my hostname / info = "/mysecretpath/info.php"; include info; ? info.php is NOT under public_html, so can't be accessed online. It is still visible to the script, since it's on the server. ?php myHost = "my.sql.host.name"; myDbase = "mydatabase"; myPass = "mypassword"; myUser = "myusername"; ? Some people use a ".inc" name for these files, but this isn't always safe for sensitive data. Using ".php" should ensure the server executes the code depends on server configuration. // Connect to the SQL server mysql_pconnect(myHost,myUser,myPass) or die("Unable to connect to SQL serverbr /\n"); • If the connect command works, it returns TRUE • The or part is executed if the first bit is FALSE • The die command tells PHP to abandon the script and print the error message • The message will be displayed on a web page, so we need to remember the br / tag