120 likes | 218 Views
Back to html / php / sql. HTML Hello World. <html> <head> <title>Page Title</title> </head> <body> <h1>Hello World!!</h1> </body> </html>. A little more. <html> <head> < title> Page Title </title>
E N D
HTML Hello World <html> <head> <title>Page Title</title> </head> <body> <h1>Hello World!!</h1> </body> </html>
A little more <html> <head> <title> Page Title </title> <link rel="stylesheet" href="mystyle.css" type="text/css" /> </head> <body> <p>My name is: <strong>Elizabeth Thiry</strong></p> <p>My user ID is: exn152</p> <p>I am a student at <a href="http://www.personal.psu.edu/exn152"> PSU </a></p> </body> </html>
CSS p { color:#666; font-size:.8em; padding-left:9em; } a { color: green; text-decoration:overline; } strong { color: purple; font-size:larger; }
Hello World With HTML and PHP <html> <head> <title>PHP Test</title> </head> <body> <?php echo '<p>Hello World</p>'; ?> </body> </html>
Forms <html> <head> <title>PHP Test</title> </head> <body> <h1>Form Page</h1> <form action=“action.php" method="post"> <p>Select a day: <select name="weekday"> <option>Sunday</option> <option>Monday</option> <option>Tuesday</option> <option>Wednesday</option> </select><br /> First Name: <input name="fname" type="text" /> <br /> Last Name: <input name="lname" type="text" /> <br /> <input type="submit" /> </form> </body> </html>
Action.php <html> <head> <title>PHP Test</title> </head> <body> <h1>My PHP Action Page</h1> <p> <?php $weekday = $_POST['weekday']; $fname = $_POST['fname']; $lname = $_POST['lname']; echo "You selected ". $weekday . "<br />"; echo "Thank you ". $fname ." ". $lname ."<br />"; ?> </p> </body> </html>
Connecting to SQL <html> <head> <title>Lab 5</title> </head> <body> <h1>Form Page</h1> <form action="lab5_action.php" method="post"> <p>Select a day: <select name="weekday"> <?php
Connecting to SQL.. Cont…. <?php $myServer = "updb1.up.ist.psu.edu"; $myUser = "sqlnna102"; $myPass = "snsmR8Wf"; $myDB = "nna102"; //connection to the database $dbhandle = mssql_connect($myServer, $myUser, $myPass) or die("Couldn't connect to SQL Server on $myServer"); //select a database to work with $selected = mssql_select_db($myDB, $dbhandle) or die("Couldn't open database $myDB");
Connecting to SQL.. Cont…. //declare the SQL statement that will query the database $query = "SELECT id, day "; $query .= "FROM Weekdays "; //execute the SQL query and return records $result = mssql_query($query); $numRows = mssql_num_rows($result); echo "<h1>" . $numRows . " Row" . ($numRows == 1 ? "" : "s") . " Returned </h1>"; //display the results while($row = mssql_fetch_array($result)) { echo "<option>" . $row["day"] . "</option>"; } //close the connection mssql_close($dbhandle); ?>
Connecting to SQL.. Cont…. </select><br /> First Name: <inputname="fname" type="text" /> <br /> Last Name: <inputname="lname" type="text" /> <br /> <input type="submit" /> </form> </body> </html>
Displaying in a table echo "<table border='1'> <tr> <th>FirstName</th> <th>LastName</th> </tr>"; //display the results while($row = mssql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['PlayerFirstName'] . "</td>"; echo "<td>" . $row['PlayerLastName'] . "</td>"; echo "</tr>"; } echo "</table>"; //close the connection mssql_close($dbhandle); ?>