Created
June 6, 2014 01:44
-
-
Save camh96/8ca459cc191756296182 to your computer and use it in GitHub Desktop.
News Database
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!doctype HTML> | |
| <head> | |
| <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
| <title>Add to TC News</title> | |
| <link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.4.2/pure-min.css"> | |
| <script src="http://code.jquery.com/jquery-2.0.3.min.js"></script> | |
| <style> | |
| body { | |
| width: 1600px; | |
| margin-right: auto; | |
| margin-left: auto; | |
| background: #FFF; | |
| padding: 20px 30px 20px 30px; | |
| font: 12px "Helvetica Neue", Helvetica, Arial, sans-serif; | |
| color: #888; | |
| text-shadow: 1px 1px 1px #FFF; | |
| padding-left: 260px | |
| } | |
| h1 { | |
| padding-left: 260px;} | |
| </style> | |
| </head> | |
| <body> | |
| <form method="post" action="newscon.php" class="pure-form"> | |
| <h1>Add some info here</h1> | |
| <a href="newsdb.php" class="button"><h2>Click here to go home</h2></a> | |
| <fieldset class="pure-group"> | |
| <br><h3>Staff Cipher</h3><input type="text" name="StaffCipher" value="" size="30" class="pure-input-1-2" placeholder="StaffCipher" /> | |
| <br><h3>Date Published</h3><input type="date" name="DatePublished" value="" size="30" class="pure-input-1-2" placeholder="DatePublished" /> | |
| <br><h3>Important</h3></br><select name="Important"> | |
| <option>Yes</option> | |
| <option>No</option> </select> | |
| <br><h3>Title</h3><input type="text" name="Title" value="" size="50" class="pure-input-1-2" placeholder="Title" /> | |
| <br><h3>Message</h3><input type="textarea" name="Message" value="" size="2500" class="pure-input-1-2" placeholder="Message in here" /> | |
| <br><h3>Department</h3></br><select name = "Department"> | |
| <option>DIT</option> | |
| <option>Science</option> | |
| <option>Art</option> | |
| <option>Food</option> | |
| <option>Maths</option> | |
| <option>English</option> | |
| <option>Languages</option></select> | |
| <br><h3>Status</h3><input type="text" name="Status" value="0" size="30" class="pure-input-1-2" placeholder="Status" readonly/> | |
| </fieldset> | |
| <input type="submit" value="Submit" class="pure-button pure-input-1-2 pure-button-primary" /> | |
| </form> | |
| </body> | |
| </html> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $con=mysqli_connect("localhost","Staff","aC5Z6VC8hVM5qDPu","news"); | |
| if (mysqli_connect_errno()) | |
| { | |
| echo "Failed to connect to MySQL: " . mysqli_connect_error(); | |
| } | |
| $sql="INSERT INTO newsdb (StaffCipher, DatePublished, Important, Title, Message, Department, Status) | |
| VALUES | |
| ('$_POST[StaffCipher]','$_POST[DatePublished]','$_POST[Important]','$_POST[Title]','$_POST[Message]','$_POST[Department]','$_POST[Status]')"; | |
| if (!mysqli_query($con,$sql)) | |
| { | |
| die('ERROR: ' . mysqli_error($con)); | |
| } | |
| echo "<h2>News item pending approval!</h2>"; | |
| mysqli_close($con); | |
| ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // login as student, only select privilege | |
| $username = "student"; | |
| $password = ""; | |
| $hostname = "127.0.0.1"; | |
| //connect | |
| $con = mysqli_connect($hostname, $username, $password, 'news'); | |
| // check connection | |
| if (mysqli_connect_errno()) { | |
| printf("Connect failed: %s\n", mysqli_connect_error()); | |
| exit(); | |
| } | |
| //mysql_select_db("news", $con); | |
| $sql = <<<EOS | |
| SELECT StaffCipher, DatePublished, Title, Message | |
| FROM newsdb | |
| LIMIT 3 | |
| EOS; | |
| $result = mysqli_query($con, $sql); | |
| ?> | |
| <!doctype html> | |
| <head> | |
| <meta charset="utf-8" /> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
| <title>TC News homepage</title> | |
| <link rel="stylesheet" href="css/foundation.css" /> | |
| <script src="js/vendor/modernizr.js"></script> | |
| </head> | |
| <div class="row"> | |
| <div class="large-12 columns"> | |
| <div class="nav-bar right"> | |
| <ul class="button-group"> | |
| <li><a href="#" class="button">Home</a></li> | |
| <li><a href="insertnews.php" class="button">Submit a post</a></li> | |
| <li><a href="#" class="button">Admin area</a></li> | |
| </ul> | |
| </div> | |
| <h1><small>This is the TC News database.</small></h1> | |
| <hr /> | |
| </div> | |
| </div> | |
| </header> | |
| <!-- End Nav --> | |
| <?php | |
| while($row = mysqli_fetch_array($result)) { | |
| echo '<div class="row">'; | |
| echo '<div class="large-6 columns">'; | |
| print "<article><h3>" . $row['Title'] . " </h3>"; | |
| print "<h6> Written by " . $row['StaffCipher'] . " </h6>"; | |
| print "<p>" . $row['Message'] . " </p>"; | |
| print "<p>" . $row['DatePublished'] . "</p></article> "; | |
| echo '</div>'; | |
| echo '</div>'; | |
| } | |
| ?>: | |
| <div class="large-3 columns"> | |
| <h5>Departments</h5> | |
| <ul class="side-nav"> | |
| <li><a href="#">DIT</a></li> | |
| <li><a href="#">Science</a></li> | |
| <li><a href="#">Art</a></li> | |
| <li><a href="#">Food</a></li> | |
| <li><a href="#">Maths</a></li> | |
| <li><a href="#">English</a></li> | |
| <li><a href="#">Languages</a></li> | |
| </ul> | |
| </div> | |
| </body> | |
| </html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment