Guest User

Untitled

a guest
Oct 28th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.96 KB | None | 0 0
  1. register.php
  2. <?php
  3. session_start();
  4.  
  5. $id = $_POST["accept"];
  6. $paintingname = $_POST["accept1"];
  7.  
  8. $host = "xx";
  9. $user = "xx";
  10. $pass= "xx";
  11. $dbname = "xx";
  12. $conn = new mysqli($host,$user,$pass, $dbname );
  13.  
  14. $_SESSION['id'] = $id;
  15. $_SESSION['paintingname'] = $paintingname;
  16.  
  17. if ($conn->connect_error) {
  18. die("Connection failed : ".$conn->connect_error); //fixme
  19. }
  20.  
  21. if (isset($_POST['reg_user'])) {
  22.  
  23. $username = isset($_POST["username"]) ? $conn->real_escape_string($_POST["username"]) : "";
  24. $email = isset($_POST["email"]) ? $conn->real_escape_string($_POST["email"]) : "";
  25. $password = isset($_POST["password"]) ? $conn->real_escape_string($_POST["password"]) : "";
  26. $password2 = isset($_POST["password2"]) ? $conn->real_escape_string($_POST["password2"]) : "";
  27.  
  28.  
  29. if ($password_1 != $password_2) {
  30. array_push($errors, "The two passwords do not match");
  31. }
  32.  
  33. // first check the database to make sure
  34. // a user does not already exist with the same username and/or email
  35. $user_check_query = "SELECT * FROM users WHERE username='$username' OR email='$email' LIMIT 1";
  36. $result = mysqli_query($conn, $user_check_query);
  37. $user1 = mysqli_fetch_assoc($result);
  38.  
  39. if ($user1) { // if user exists
  40. if ($user1['username'] === $username) {
  41. array_push($errors, "Username already exists");
  42. }
  43.  
  44. if ($user1['email'] === $email) {
  45. array_push($errors, "email already exists");
  46. }
  47. }
  48.  
  49. // Finally, register user if there are no errors in the form
  50. if (count($errors) == 0) {
  51. $password = md5($password_1);//encrypt the password before saving in the database
  52.  
  53. $query = "INSERT INTO users(username, email, password)
  54. VALUES('$username', '$email', '$password')";
  55. mysqli_query($db, $query);
  56.  
  57. }
  58. }
  59.  
  60. ?>
  61.  
  62. <html>
  63. <head>
  64. <title>Registration system PHP and MySQL</title>
  65. <link rel="stylesheet" type="text/css" href="style.css">
  66. </head>
  67. <body>
  68. <div class="header">
  69. <h2>Register</h2>
  70. </div>
  71.  
  72. <form method="post" action="confirm.php">
  73.  
  74. <div class="input-group">
  75. <label>Username</label>
  76. <input type="text" name="username" required />
  77. </div>
  78. <div class="input-group">
  79. <label>Email</label>
  80. <input type="email" name="email" required />
  81. </div>
  82. <div class="input-group">
  83. <label>Password</label>
  84. <input type="password" name="password_1" required />
  85. </div>
  86. <div class="input-group">
  87. <label>Confirm password</label>
  88. <input type="password" name="password_2" required />
  89. </div>
  90. <div class="input-group">
  91. <button type="submit" class="btn" name="reg_user" >Register</button>
  92. </div>
  93. <p>
  94. Already a member? <a href="login.php">Sign in</a>
  95. </p>
  96. </form>
  97. </body>
  98. </html>
  99.  
  100. details.php
  101. <html>
  102. <head>
  103. <title>Table with database</title>
  104. <style type ="text/css">
  105. table {
  106. border: 2px solid red;
  107. background-colour: #FFC;
  108. }
  109. th {
  110. border-bottom: 5px solid #000;
  111. }
  112. td {
  113. border-bottom: 2px solid #666;
  114. }
  115. </style>
  116.  
  117.  
  118. </head>
  119. <body>
  120.  
  121. <?php
  122. session_start();
  123. $servername = "xx";
  124. $username = "xx";
  125. $password= "xx";
  126. $dbname = "xx";
  127. $conn = new mysqli($servername,$username,$password, $dbname );
  128.  
  129.  
  130. $id = $_POST["accept"];
  131.  
  132. if ($conn->connect_error) {
  133. die("Connection failed : ".$conn->connect_error); //fixme
  134. }
  135. $sql= "SELECT * FROM `listart` where id =".$id;
  136. $result=$conn->query($sql);
  137.  
  138.  
  139. if ($result->num_rows > 0) {
  140. echo "<table>n";
  141. echo "<tr>";
  142. echo "<th>ID</th>";
  143. echo "<th>Image</th>";
  144. echo "<th>Description</th>";
  145. echo "<th>Date of completion</th>";
  146. echo "<th>Painting Name</th>";
  147. echo "<th>Height</th>";
  148. echo "<th>Width</th>";
  149. echo "<th>Price</th>";
  150.  
  151. echo "</tr>";
  152. while ($row = mysqli_fetch_array($result)) {
  153.  
  154. echo "<tr>n";
  155. echo "<td>".$row["id"]."</td>n";
  156. echo "<td>"; echo ' <img src= "data:image/jpeg;base64,'.base64_encode($row['image']).'" height = "200 width = "200"/>'; echo "</td>";
  157. echo "<td>".$row["description"]."</td>n";
  158. echo "<td>".$row["Dateofcompletion"]."</td>n";
  159. echo "<td>".$row["pname"]."</td>n";
  160. echo "<td>".$row["height"]." mm "."</td>n";
  161. echo "<td>".$row["width"]." mm "."</td>n";
  162. echo "<td>"."£ ".$row["price"]."</td>n";
  163. echo "<td><form action='register.php' method='POST'><input type='hidden' name='accept' value='".$row["id"]."'/><input type='hidden' name='accept1' value='".$row["pname"]."'/> <input type='submit' name='submit-btn' value='Order'><button type='button' onclick="history.back();">Back</button></form></td>";
  164. echo "</tr>n";
  165.  
  166. }
  167. echo "</table>n";
  168. }
  169.  
  170. $conn->close();
  171. ?>
  172.  
  173.  
  174. </body>
  175. </html>
  176.  
  177. vieworders.php
  178.  
  179. <html>
  180. <head>
  181. <title>Table with database</title>
  182. <style type ="text/css">
  183. table {
  184. border: 2px solid red;
  185. background-colour: #FFC;
  186. }
  187. th {
  188. border-bottom: 5px solid #000;
  189. }
  190. td {
  191. border-bottom: 2px solid #666;
  192. }
  193. </style>
  194.  
  195.  
  196. </head>
  197. <body>
  198. <h2>Here is a table with your orders!</h2>
  199. <div>
  200.  
  201. <?php
  202. session_start();
  203. $servername = "xx";
  204. $username = "xx";
  205. $password= "xx";
  206. $dbname = "xx";
  207. $conn = new mysqli($servername,$username,$password, $dbname );
  208.  
  209.  
  210. $id = $_SESSION['id'];
  211. $paintingname = $_SESSION['paintingname'];
  212.  
  213.  
  214. if (isset($_POST['submit'])) {
  215. $uname = isset($_POST["uname"]) ? $conn -> real_escape_string($_POST["uname"]):"";
  216. $email = isset($_POST["email"]) ? $conn -> real_escape_string($_POST["email"]):"";
  217. $paddress = isset($_POST["padd"]) ? $conn -> real_escape_string($_POST["padd"]):"";
  218. $phonenumber = isset($_POST["phonenumber"]) ? $conn -> real_escape_string($_POST["phonenumber"]):"";
  219. }
  220.  
  221.  
  222. if ($conn->connect_error) {
  223. die("Connection failed : ".$conn->connect_error); //fixme
  224. }
  225.  
  226.  
  227. $sql = "INSERT INTO vieworders(id,paintingname,username,email,postalcode,phonenumber) VALUES
  228. ('$id','$paintingname','$uname','$email','$paddress','$phonenumber');";
  229.  
  230. //echo "<p><b>$sql</b></p>";
  231.  
  232. if ($conn->query($sql) == TRUE) {
  233. echo "<p> Insert successful </p>";
  234. }
  235. else {
  236. die("error on insert".$conn->error);
  237. }
  238.  
  239.  
  240. $sql = "SELECT * FROM `vieworders`";
  241. $result1=$conn->query($sql);
  242.  
  243.  
  244. if ($result1->num_rows > 0) {
  245. echo "<table>n";
  246. echo "<tr>";
  247. echo "<th>ID</th>";
  248. echo "<th>Painting Name</th>";
  249. echo "<th>Username</th>";
  250. echo "<th>Email</th>";
  251. echo "<th>Postal code</th>";
  252. echo "<th>Phone number</th>";
  253. echo "<th>Order status</th>";
  254. echo "</tr>";
  255. while ($row = mysqli_fetch_array($result1)) {
  256.  
  257. echo "<tr>n";
  258. echo "<td>".$row["id"]."</td>n";
  259. echo "<td>".$row["paintingname"]."</td>n";
  260. echo "<td>".$row["username"]."</td>n";
  261. echo "<td>".$row["email"]."</td>n";
  262. echo "<td>".$row["postalcode"]."</td>n";
  263. echo "<td>".$row["phonenumber"]."</td>n";
  264. echo "<td>".$row["status"]."</td>n";
  265. echo "</tr>n";
  266. }
  267. echo "</table>n";
  268. }
  269.  
  270. $conn->close();
  271.  
  272. ?>
  273.  
  274. </div>
  275. </body>
  276. </html>
Add Comment
Please, Sign In to add comment