Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.55 KB | None | 0 0
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Precious Metals | Quotes</title>
  6. <link href="styles.css" rel="stylesheet" type="text/css">
  7. </head>
  8.  
  9. <body>
  10. <?php
  11.  
  12. //Set the readCSV as a function so you avoid the need to type it out.
  13.  
  14. function readCSV($csvFile) {
  15. $handle = fopen($csvFile, 'r');
  16. while (!feof($handle) ) {
  17. $file[] = fgetcsv($handle, 1024);
  18. }
  19. return $file;
  20. }
  21.  
  22. //Open the CSV files (Rates and metals)
  23.  
  24. $file1 = 'Rates.csv';
  25. $file2 = 'metals.csv';
  26.  
  27. $file_rate = readCSV($file1);
  28. $file_metal = readCSV($file2);
  29.  
  30. //handle any errors first
  31.  
  32. ini_set('display_errors',0);
  33.  
  34. $amount = $_REQUEST['amountvalue'];
  35. $option = $_REQUEST['sweetvalue'];
  36.  
  37. ?>
  38. <div id='main'>
  39. <div id='titleImage'><img src='logo.png' width='750' height='200' alt='Precious Metals Title' /></div>
  40. <div id='menu-wrapper'>
  41. <div id='menu'>
  42. <ul>
  43. <li><a href='index.php'>Home</a></li>
  44. <li class='current_page_item'><a href='#'>Quotes</a></li>
  45. <li><a href='register.php'>Register</a></li>
  46. </ul>
  47. </div>
  48. </div>
  49.  
  50. <div class='forms'>
  51. <h1>Get a Quote</h1>
  52. <?php
  53. $space = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
  54. //Assign a variable to the values entered by the user in the form below
  55. $option = $_POST['metal'];
  56. $weight = $_POST['amountvalue'];
  57.  
  58. //Use an If statement to check if any data has been entered.
  59. if($_REQUEST['amountvalue']==NULL){
  60. $errormessage .= " $space $space $space Please enter a weight for $option";
  61. }
  62. else if($_REQUEST['amountvalue']<=0){
  63. echo" $space $space $space Please enter a value above 0g";
  64. }
  65. else if( isset( $_REQUEST['calculate'])){
  66. $operator=$_REQUEST['metal'];
  67. if($operator==$file_metal[0][0])
  68. {
  69. $add = $_REQUEST['amountvalue'];
  70. $res = $add * $file_metal[0][1];
  71. $res2 = $file_metal[0][1]* $add * $file_rate[0][1];
  72. $res3 = $file_metal[0][1]* $add * $file_rate[1][1];
  73. }
  74. if($operator==$file_metal[1][0])
  75. {
  76. $add = $_REQUEST['amountvalue'];
  77. $res = $add * $file_metal[1][1];
  78. $res2 = $file_metal[1][1]* $add * $file_rate[0][1];
  79. $res3 = $file_metal[1][1]* $add * $file_rate[1][1];
  80. }
  81. if($operator==$file_metal[2][0])
  82. {
  83. $add = $_REQUEST['amountvalue'];
  84. $res = $add * $file_metal[2][1];
  85. $res2 = $file_metal[2][1]* $add * $file_rate[0][1];
  86. $res3 = $file_metal[2][1]* $add * $file_rate[1][1];
  87. }
  88. if($operator==$file_metal[3][0])
  89. {
  90. $add = $_REQUEST['amountvalue'];
  91. $res = $add * $file_metal[3][1];
  92. $res2 = $file_metal[3][1]* $add * $file_rate[0][1];
  93. $res3 = $file_metal[3][1]* $add * $file_rate[1][1];
  94. }
  95. $errorMessage = "Thank you, below is your quote for " . "$amount" . " grams of " . "$option" . "";
  96. }
  97. ?>
  98. <form action='quotes.php' method='post' name='quote'>
  99. <table style="border:groove #000000" width="750px">
  100. <tr>
  101. <td>Type of metal:&nbsp;&nbsp;&nbsp;</td>
  102. <td>
  103. <select name="metal" style="width: 120px">
  104. <option><?php echo $file_metal[0][0]?></option>
  105. <option><?php echo $file_metal[1][0]?></option>
  106. <option><?php echo $file_metal[2][0]?></option>
  107. <option><?php echo $file_metal[3][0]?></option>
  108. </select></form></td>
  109. </tr>
  110. <tr>
  111. <td>Metal Amount</td>
  112. <td class="auto-style5">
  113. <input name="amountvalue" type="number" style="color:red"/>
  114. g</td>
  115.  
  116. </tr>
  117. <tr>
  118. <td></td>
  119. <td><input type="submit" name="calculate" value="Calculate" /></td>
  120.  
  121. </tr>
  122. <tr>
  123. <td colspan="2"><?php
  124. if(!empty($errorMessage)){
  125. echo("<ul>" . $errorMessage . "</ul>\n");
  126. }
  127. else
  128.  
  129.  
  130.  
  131. ?></td>
  132. </tr>
  133. <!--- Rounding the final values to 2 decimal places so it is easier on the eye -->
  134. <tr>
  135. <td>Amount in GBP: </td>
  136. <td>&pound;<?php echo round($res ,2) ?> </td>
  137. </tr>
  138. <tr>
  139. <td>Amount in USD: </td>
  140. <td>&#36;<?php echo round($res2 ,2) ?> </td>
  141. </tr>
  142. <tr>
  143. <td>Amount in EUR: </td>
  144. <td>&euro;<?php echo round($res3 ,2) ?> </td>
  145. </tr>
  146. </table>
  147.  
  148. </div>
  149. <p><?php echo"$space";?>If you have more than 500g of scrap metal to sell please telephone us for a quote</p>
  150. </div>
  151.  
  152. </body>
  153. </html>
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  182. <html xmlns="http://www.w3.org/1999/xhtml">
  183. <head>
  184. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  185. <title>Precious Metals | Register</title>
  186. <link href="styles.css" rel="stylesheet" type="text/css">
  187. </head>
  188.  
  189. <body>
  190. <div id='main'>
  191. <div id='titleImage'><img src='logo.png' width='750' height='200' alt='Precious Metals Title' /></div>
  192. <div id='menu-wrapper'>
  193. <div id='menu'>
  194. <ul>
  195. <li><a href='index.php'>Home</a></li>
  196. <li><a href='quotes.php'>Quotes</a></li>
  197. <li class='current_page_item'><a href='#'>Register</a></li>
  198. </ul>
  199. </div>
  200. </div>
  201.  
  202. <div class='forms'>
  203. <h1>Register</h1>
  204. <form action='register.php' method='post' name='register'>
  205. <table>
  206. <tr>
  207. <td>Username:</td><td><input type="text" name="user" /></td>
  208. </tr>
  209. <tr>
  210. <td>Email:</td><td><input type="text" name="pass" /></td>
  211. </tr>
  212. <tr>
  213. <td>Password:</td><td><input type="text" name="email" /></td>
  214. </tr>
  215. <tr>
  216. <td>Company:</td><td><input type="text" name="company" /></td>
  217. </tr>
  218. <tr>
  219. <td><input type="submit" value="Submit"></td>
  220. </tr>
  221. </table>
  222. </form>
  223. </div>
  224. </div>
  225. <?php
  226. $username = "oavcs67";
  227. $password = "";
  228. $hostname = "";
  229.  
  230. $dbhandle = mysql_connect($hostname, $username, $password) or die("Could not connect to database");
  231.  
  232. $selected = mysql_select_db("1", $dbhandle);
  233.  
  234. if(isset($_POST['user']) && isset($_POST['pass']) && isset($_POST['email']) && isset($_POST['company'])){
  235.  
  236. $user = $_POST['user'];
  237. $pass = $_POST['pass'];
  238. $email = $_POST['email'];
  239. $company = $_POST['company'];
  240.  
  241. $query = mysql_query("SELECT * FROM info WHERE Username='$user' && Password='$pass'");
  242. if(mysql_num_rows($query) > 0) {
  243. echo "Username has already been taken, sorry about that";
  244. }
  245. else{
  246. mysql_query("INSERT INTO info (name, email, password, company, active) VALUES ('$user', '$pass', '$email', '$company', '0')");
  247. header("location:index.php");
  248. }
  249. }
  250.  
  251.  
  252. mysql_close();
  253. ?>
  254. </body>
  255. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement