EssayGhost Assignment代写,Essay代写,网课代修,Quiz代考

EssayGhost-Essay代写,作业代写,网课代修代上,cs代写代考

一站式网课代修,论文代写

高质量的Assignment代写、Paper代写、Report代写服务

EG1hao
网课代修代上,cs代写代考
数据库代写
您的位置: 主页 > 编程案例 > 数据库代写 >
数据库代写:PHP网页MySQL代做题目:COMP284 Practical 5 PHP (2) - 代写数据库
发布时间:2021-07-24 15:17:13浏览次数:
•Devise a SELECT-statement that just returns the values stored for the slot attribute in the meetings table and execute it.Hint: Refer to http://dev.mysql.com/doc/refman/5.5/en/select.htmlfor infor-mation on SELECT-statements.•Devise a DELETE-statement that removes the database entry for slot 11 and execute it.Hint: DELETE-statements are described at http://dev.mysql.com/doc/refman/5.5/en/delete.html.•Check that the deletion in the previous step has been successful.f.Disconnect from the MySQL server by using the command quit;2.Let us try to connect to our MySQL database using PHP.a.Open a text editor and enter the following HTML markup and PHP code: !DOCTYPEhtml html head title Practical5:PHPandDatabases /title /head body h1 Practical5:PHPandDatabases /h1 ?php$db_hostname= mysql $db_database= user $db_username= user $db_password= password $db_charset= utf8mb4 $dsn= mysql:host=$db_hostname;dbname=$db_database;charset=$db_charset $opt=array(PDO::ATTR_ERRMODE= PDO::ERRMODE_EXCEPTION,PDO::ATTR_DEFAULT_FETCH_MODE= PDO::FETCH_ASSOC,PDO::ATTR_EMULATE_PREPARES= falsetry{$pdo=newPDO($dsn,$db_username,$db_password,$opt);/Codefor4chere/Codefor4dhere/Codefor5ahereecho h2 Datainmeetingtable(Whileloop) /h2 $stmt=$pdo- query( select*frommeetings echo Rowsretrieved: .$stmt- rowcount(). br br while($row=$stmt- fetch()){echo Slot: ,$row[ slot ], br echo Name: ,$row[ name ], br echo Email: ,$row[ email ], br br echo h2 Datainmeetingtable(Foreachloop) /h2 $stmt=$pdo- query( select*frommeetings foreach($stmtas$row){echo Slot: ,$row[ slot ], br echo Name: ,$row[ name ], br echo Email: ,$row[ email ], br br $pdo=NULL;}catch(PDOException$e){exit( PDOError: .$e- getMessage(). br /body /html Replace both occurrences of user with your departmental user name and replace password with the password you have chosen for your database.b. Use the documentation at http://php.net/manual/en/pdo.connections.phpto un-derstand what the various PDO-functions in the code do.c. Save the code to a file name php05A.php in $HOME/public_html/. Make sure that nobody but you has read access for the file by usingchmod og-rwx /public_html/php05A.phpYou should only have to do so once. File permissions should not change while you continue to edit the file.d. Execute the PHP script in the terminal using the commandphp /public_html/php05A.phpCheck that there are no syntax error and that the script produces the output !DOCTYPEhtml html head title Practical19 /title /head body h1 Practical19A /h1 h2 Datainmeetingtable(Whileloop) /h2 Rowsretrieved:3 br br Slot:1 br Name:MichaelNorth br Email:[email protected] br br Slot:5 br Name:JodyLand br Email:[email protected] br br Slot:7 br Name:TrishShelby br Email:[email protected] br br h2 Datainmeetingtable(Foreachloop) /h2 Rowsretrieved:3 br br Slot:1 br Name:MichaelNorth br Email:[email protected] br br Slot:5 br Name:JodyLand br Email:[email protected] br br Slot:7 br Name:TrishShelby br Email:[email protected] br br /body /html e. Open a web browser and access the URLhttp://cgi.csc.liv.ac.uk/ user /php05A.phpwhere user should be replaced by your departmental user name.Make sure that the web page you are shown corresponds to the HTML code you have seen in Exercise 2d.f.It would be nice if the database data would be presented in the form of a HTML table with three columns called ‘Slot’, ‘Name’ and ‘Email’. Change the code of your PHP script so that two such tables are produced. Also, modify the query so that entries in the tables will be ordered by slot number.3.We now want to add some interactivity to our web application.a.Add the following code to php05A.php just before the statement $pdo = NULL.echo FORMSTART formname= form1 method= post selectname= select onChange= document.form1.submit() optionvalue= None Selectaname /option FORMSTART;//Addfurtheroptionshereecho FORMEND /select /form FORMEND;foreach($_REQUESTas$key= $value)echo $key= $value br b.Save the modified file, check that your code is syntactically correct by executing the script in a terminal, then refresh the URLhttp://cgi.csc.liv.ac.uk/ user /php05A.phpin your web browser. You should now see a rudimentary drop-down menu at the bottom of the page.c. At the point indicated by the comment “Add further options here” in Exercise 3a, add PHP code that generates additional options for the drop-down menu, one for each entry in the meetings database table. The value attribute for each option should be the email address stored in the database while the label should be the name, for example: optionvalue= [email protected] TrishShelby /option As in Exercise 2f, the required data should be retrieved from the database.d.Once you have successfully completed Exercise 3c, observe what happens if you select one of the options in the pop-up menu. You should see additional text at the bottom of the web page, for exampleselect= [email protected]if you have selected the name Michael North among the options.Make sure that you understand where this text comes from and how it comes about.e.Modify your script so that the output you see in Exercise 3cis no longer produced by the script, but instead the script addsYoucancontactMichaelNorthviathee-mailaddress[email protected]at the bottom of the page. Make sure that on the first visit of the URL no text is shown. Hint: The PDO function fetch described at http://php.net/manual/en/pdostatement.fetch.php willbe useful, as you only retrieve one row from the database.4.The next task is to add a facility that allows us to insert new data into the database via our web page.a.Add the following code to phpDB1.php just before the statement $pdo = NULL.echo FORM2 formname= form2 method= post Slot: inputtype= number name= slot min= 1 max= 100 br Name: inputtype= text name= name size= 100 brEmail: inputtype= text name= email size= 100 br inputtype= submit name= insert value= InsertintoDB inputtype= submit name= delete value= DeletefromDB inputtype= submit name= query value= QueryDB /form FORM2;b.Save the modified file, check that your code is syntactically correct by executing the script in a terminal, then refresh the URL for the script. You should now see a form that allows you to enter a slot number, name and e-mail address.c.Add code to your PHP script after the comment “Code for 4c here” and before the comment “Code for 4d here” that does the following: If a user supplies a non-empty slot number, name and e-mail address using the form introduced in Exercise 4aand clicks on the ‘Insert into DB’ button, then your code should insert those values into the database. If the insertion is successful, a success message should be shown. If the insertion fails (which will be the case if the slot number already exists in the database), then a failure message should be shown that includes the error message you get from MySQL.Hints:•First check whether the user has clicked the ‘Insert into DB’ button. If so, check whether the user has provided a slot number, name and e-mail address. If one of the pieces of information is missing, generate an error message and do not proceed to insert the incomplete information that was provided by the user.•A naive solution will retrieve the three values entered by the user, construct an SQL query as a string containing those values and execute that query, using code like$query= insertintomeetings(slot,name,email)values({$_REQUEST[ slot ]}, {$_REQUEST[ name ]} , {$_REQUEST[ email ]} ) $success=pdo- query($query);This solution is vulnerable to SQL injection and should therefore by avoided. See http://php.net/manual/en/security.database.sql-injection.php foradditionalinformation.•A better solution involves the use of a prepared statementand parameter binding. Prepared statements are a kind of compiled template for SQL statements that includes parameters/placeholders that will later be filled by values. Prepared statements offer two major benefits: (i) the SQL statements only need to be parsed (or prepared) once, but can be executed multiple times with the same or different values for the parameters, (ii) neither the parameters nor the values that are bound to them need to be quoted; this is handled automatically and in such a way that no SQL injection will occur.Using a prepared statement, the insertion of slot number, name and email address into our database may look as follows:$stmt=$pdo- prepare( insertintomeetings(slot,name,email)values(?,?,?) $success=$stmt- execute(array($_REQUEST[ slot ],$_REQUEST[ name ],$_REQUEST[ email ]));Here, using $pdo- prepare(), we first create a prepared statement with three place-holders, indicated by ?, that we will later bind to values. The binding of placeholders is done using $pdo- execute() that then also executes the query. The function takesas arguments an array with the values that should be bound to the placeholders. The function will return a boolean value indicating whether the execution has been successful.Instead of ? it is possible to use named placeholders. The names of the placehold-ers must then all appear as keys in the array that is used to provide values for the placeholders:$stmt=$pdo- prepare( insertintomeetings(slot,name,email)values(:slot,:name,:email) $success=$stmt- execute(array( name = $_REQUEST[ name ], slot = $_REQUEST[ slot ], email = $_REQUEST[ email ]));The advantage of name placeholders is obviously that fewer errors with the order of values are made.The manual pages for the relevant functions are– http://php.net/manual/en/pdo.prepare.php,– http://php.net/manual/en/pdostatement.bindparam.php, and– http://php.net/manual/en/pdostatement.execute.phpd.Add code to your PHP script after the comment “Code for 4d here” and before the comment “Code for 5a here” that does the following: If a user supplies a non-empty slot number using the form introduced in Exercise 4aand clicks on the ‘Delete from DB’ button, then your code should attempt to delete any entry with a matching slot number from the database. If the deletion successful removes an entry from the database, then a success message should be shown. If the deletion fails to remove anything from the database, then a failure message should be shown. If the database operation fails for any other reason, then a failure message should be shown that includes the error message you get from MySQL.Hint: For database operations like ‘update’ and ‘delete’ $pdo- execute() will return TRUE even if no database entry was update or deleted. To determine whether the op-eration was truely successful, one has to check whether the number of affected rows is greater than zero (or equal to the expected number of affected rows). $stmt- rowcount() returns the number of affected rows.5.Finally, we add a facility that allows us to query the database using regular expressions.a.Add code to your PHP script after the comment “Code for 5a here” that does the fol-lowing: If a user supplies a regular expression in the name field of the form introduced in Exercise 4aand clicks the ‘Query DB’ button, then your code should retrieve and display all entries in the meetings table where the value in the name field matches that regular expression.Hints:•First check whether the user has clicked the Query DB button. If so, check whether the user has entered something into the name field. If not, generate an error message and do not proceed to query the database.•For information on regular expression matching in MySQL see http://dev.mysql.com/doc/refman/5.5/en/pattern-matching.html•Just as in Exercise 4c, a prepared statement is the safest way to query the database. To prepare a statement for the query, to bind variables to the placeholder in the statement and to execute the statement, proceed as in Exercise 4c.•Once the prepared statement has been executed, we can use a foreach-loop to access and print out each row that was retrieved as in Exercise 2a.•It would be nice if the information retrieved from the database would be presented as HTML table, just as in Exercise 2f.代写CS Finance|建模|代码|系统|报告|考试编程类:C++,JAVA ,数据库,WEB,Linux,Nodejs,JSP,Html,Prolog,Python,Haskell,hadoop算法,系统 机器学习金融类:统计,计量,风险投资,金融工程,R语言,Python语言,Matlab,建立模型,数据分析,数据处理服务类:Lab/Assignment/Project/Course/Qzui/Midterm/Final/Exam/Test帮助代写代考辅导E-mail:[email protected]微信:BadGeniuscs 工作时间:无休息工作日-早上8点到凌晨3点如果您用的手机请先保存二维码到手机里面,识别图中二维码。如果用电脑,直接掏出手机果断扫描。

所有的编程代写范围:essayghost为美国、加拿大、英国、澳洲的留学生提供C语言代写、代写C语言、C语言代做、代做C语言、数据库代写、代写数据库、数据库代做、代做数据库、Web作业代写、代写Web作业、Web作业代做、代做Web作业、Java代写、代写Java、Java代做、代做Java、Python代写、代写Python、Python代做、代做Python、C/C++代写、代写C/C++、C/C++代做、代做C/C++、数据结构代写、代写数据结构、数据结构代做、代做数据结构等留学生编程作业代写服务。