1 / 16

MySQL PHP Example

MySQL PHP Example. Spring 2014. dbcontrol.php. <?php $dbName = "flashword"; //production database $Host = "flashword.db.5173116.hostedresource.com"; $User = "flashword"; $Password = "flashDB09"; mysql_connect ($Host, $User, $Password) or die("Unable to connect to host $dbName");

vaughn
Download Presentation

MySQL PHP Example

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. MySQL PHP Example Spring 2014

  2. dbcontrol.php <?php $dbName = "flashword"; //production database $Host = "flashword.db.5173116.hostedresource.com"; $User = "flashword"; $Password = "flashDB09"; mysql_connect ($Host, $User, $Password) or die("Unable to connect to host $dbName"); mysql_select_db($dbName) or die( "Unable to select database $dbName"); php?>

  3. header.php <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"> <title>header.php</title> </head> <body> <table style="text-align: left;" border="1" cellpadding="2“ cellspacing="2" width="700"> <tbody> <tr> <td style=""><img src="images/uncp-1by1.gif" alt="UNCP Logo“ height="125" width="125"> </td> <td style="font-size: 36px;">UNCP Flash Card – English Words</td> </tr> </tbody> </table> <br> <br> </body>

  4. home.php <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Untitled</title> </head> <body> <?php echo("<table summary='' width='50'><tr><td>"); echo("<form action='index.php' method='post'>"); echo("<tr><td align = 'left'><input type='submit' name='select' style='font-size: 36px;' value='Return Home' /></td>"); echo("</form></td></tr>"); echo("</td></tr></table>"); ?> </body> </html>

  5. index.php <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Flash Cards</title> </head> <body> <?php include("header.php"); include("dbControl.php"); $i = 0; //start from beginnng of results, 1 will be added to i before records accessed $wlquery = "SELECT * FROM wordLists ORDER BY Name"; $results = mysql_query($wlquery); $nosrows = mysql_numrows($results);

  6. index.php echo("<table summary='' style='font-size: 36px;'><tr><td>"); echo("<form action='fCard.php' name='selectWordList' method='post'>"); echo("<tr><td align = 'left'>Select Word List: <select style='font-size: 36px;' name = 'tableName' size='1'>"); //tableName contains name of table with words & answers echo("<Option style='font-size: 36px;' Value='words' SELECTED>words</option>"); for($u = 0; $u < $nosrows; $u++) { $sid=mysql_result($results,$u,'Name'); echo("<Option style='font-size: 36px;' Value='" . $sid . "'>" . $sid . "</option>"); } echo("</select>"); echo("<tr><td align = 'left'>Select Order: <select style='font-size: 36px;' name = 'order' size='1'>");

  7. index.php //order contains Alphabetical or Random echo("<Option style='font-size: 36px;' Value='Alphabetical' SELECTED>Alphabetical</option>"); echo("<Option style='font-size: 36px;' Value='Random'>Random</option>"); echo("</select>"); echo("<tr><td align = 'left'>Select Subset: <select style='font-size: 36px;' name = 'subset' size='1'>"); //subset containa All, A, B, .., the subset of the table to displah echo("<Option Value='All' SELECTED>All</option>"); echo("<Option Value='a'>A</option>"); echo("<Option Value='b'>B</option>"); echo("<Option Value='c'>C</option>"); echo("<option value='d'>D</option>"); echo("<option value='e'>E</option>"); echo("<option value='f'>F</option>"); echo("<option value='g'>G</option>"); echo("<option value='h'>H</option>"); echo("<option value='i'>I</option>"); echo("<option value='j'>J</option>"); echo("<option value='k'>K</option>"); echo("<option value='l'>L</option>");

  8. index.php echo("<option value='m'>M</option>"); echo("<option value='n'>N</option>"); echo("<option value='o'>O</option>"); echo("<option value='p'>P</option>"); echo("<option value='q'>Q</option>"); echo("<option value='r'>R</option>"); echo("<option value='s'>S</option>"); echo("<option value='t'>T</option>"); echo("<option value='u'>U</option>"); echo("<option value='v'>V</option>"); echo("<option value='w'>W</option>"); echo("<option value='x'>X</option>"); echo("<option value='y'>Y</option>"); echo("<option value='z'>Z</option>"); echo("</select>");

  9. index.php echo("<input type='hidden' name='i' value='" . $i . "'/>"); //i contains where to continue in results echo("<input type='hidden' name='select' value='Next Word'/>"); //select contains New Word, display a word without the Answer echo("<input type = 'submit' name = 'id' style='font-size: 36px;' value = 'Go to Flash Card'/>"); //id is the button to continue echo("</select>"); echo("</form></td></tr>"); echo("</td></tr></table>"); echo("<br><br><img src='images/color1.gif' width='300' height='3'/>"); echo("<table summary='Contribution' width='450'>"); echo("<tr><td><font size='2'>Web site developed by:<br>"); echo("&nbsp;&nbsp;Dr. Charles W. Lillie<br>"); echo("&nbsp;&nbsp;Department of Mathematics & Computer Science<br>"); echo("&nbsp;&nbsp;University of North Carolina at Pembroke<br>"); echo("&nbsp;&nbsp;Email: <a href='mailto:lilliec@uncp.edu'>lilliec@uncp.edu</a>"); echo("</font></td></tr></table>"); ?> </body> </html>

  10. fCard.php <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type"> <title>wCard.php</title> </head> <body> <?php echo("<table summary='Overall Table' width='750' border='0'>"); echo("<tr><td>"); include("header.php"); include("dbControl.php"); echo("</td></tr>"); $error=false; $i=$_POST['i']; //i contains where to continue in results

  11. fCard.php $select=$_POST['select']; //select contains New Word, display a word without the Answer $subset=$_POST['subset']; //subset containa All, A, B, .., the subset of the table to displah $order=$_POST['order']; //order contains Alphabetical or Random $tableName=$_POST['tableName']; //tableName contains name of table with words & answers $empty="_________________________"; if($subset == 'All') { $query = "SELECT * FROM " . $tableName . " ORDER BY Word"; } if($subset != 'All') { $query = "SELECT * FROM " . $tableName . " WHERE Word LIKE '$subset%' ORDER BY Word"; }

  12. fCard.php $results = mysql_query($query); $norow = mysql_numrows($results); if($norow==0) { echo("<tr><td>"); include("home.php"); echo("</td></tr>"); echo("<tr style='font-size: 36px;'><td colspan='2'><font color='#ff0033'>There are no words on this list</font></tr></td>"); $error=true; } if($i>=$norow) { $i = 0; } if($order == 'Random' && $select == "Next Word") { $i = rand(0, $norow - 1); }

  13. fCard.php if(!$error) { echo("Nunber of words in list is " . $norow); $word=mysql_result($results,$i,'Word'); $answer=mysql_result($results,$i,'Answer'); if($select == "Answer") { echo("<tr><td colspan='2'><table bgcolor='#ffffcc' style='text-align: left height: 200px width: 400px;' border='0' cellpadding='2' cellspacing='2'><tbody>"); echo("<tr style='font-size: 36px;'><td style='vertical-align: top;'>".$word."</td></tr>"); echo("<tr style='font-size: 36px;'><td style='vertical-align: top;'>".$answer."</td></tr>"); echo("</tbody></table></td></tr>"); } else { echo("<tr><td colspan='2'><table bgcolor='#ffffcc' style='text-align: left height: 300px width: 300px;' border='0' cellpadding='2' cellspacing='2'><tbody>"); echo("<tr style='font-size: 36px;'><td style='vertical-align: top;'>".$word."</td></tr>"); echo("<tr style='font-size: 36px;'><td style='vertical-align: top;'>".$empty."</td></tr>"); echo("</tbody></table></td></tr>"); }

  14. fCard.php echo("</table>"); echo("<table summary='Return and Next Buttons' border='0'>"); echo("<tr><td>"); // echo("<td>"); include("home.php"); echo("</td>"); if($select == "Next Word") { echo("<form action='fCard.php' method='post'>"); echo("<td width='100'align = 'left' valign = 'bottom'><input type='submit' name='select' style='font-size: 36px;' value='Answer' /></td>"); // echo("<td align = 'center'><input type='submit' name='select' value='Next Word' /></td>"); echo("<td><input type='hidden' name='i' value='".$i."' /></td>"); echo("<input type='hidden' name='subset' value='".$subset."' />"); echo("<input type='hidden' name='order' value='".$order."' />"); echo("<input type='hidden' name='tableName' value='".$tableName."' /></td>"); echo("</form></td></tr>"); }

  15. fCard.php else { if($order == 'Random') { $i = rand(0, $norow - 1); } else { $i = $i+1; } echo("<form action='fCard.php' method='post'>"); echo("<td width='50'align = 'left' valign = 'bottom'><input type='submit' name='select' style='font-size: 36px;' value='Next Word' />"); echo("<td><input type='hidden' name='i' value='".$i."' /></td>"); echo("<input type='hidden' name='subset' value='".$subset."' />"); echo("<input type='hidden' name='order' value='".$order."' />"); echo("<input type='hidden' name='tableName' value='".$tableName."' /></td>"); echo("</form></td></tr>"); } }

  16. fCard.php echo("</table>"); echo("<br><br>"); ?> </body> </html>

More Related