Guest User

Untitled

a guest
May 29th, 2018
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. <?php
  2. //Check whether the form has been submitted
  3. if (array_key_exists('check_submit', $_POST)) {
  4.  
  5. //Converts the new line characters (\n) in the text area into HTML line breaks (the <br /> tag)
  6. //$_POST['Comments'] = nl2br($_POST['Comments']);
  7.  
  8. //Check whether a $_GET['Languages'] is set
  9. if ( isset($_POST['Colors']) ) {
  10. $_POST['Colors'] = implode(', ', $_POST['Colors']); //Converts an array into a single string
  11. }
  12.  
  13. //Let's now print out the received values in the browser
  14. echo "Your name: {$_POST['Name']}<br />";
  15. echo "Your password: {$_POST['Password']}<br />";
  16. echo "Your favourite season: {$_POST['Seasons']}<br /><br />";
  17. echo "Your comments:<br />{$_POST['Comments']}<br /><br />";
  18. echo "You are from: {$_POST['Country']}<br />";
  19. echo "Colors you chose: {$_POST['Colors']}<br />";
  20. } else {
  21. echo "You can't see this page without submitting the form.";
  22. }
  23.  
  24. $Name = $_POST['Name'];
  25. $Password = $_POST['Password'];
  26. $Seasons = $_POST['Seasons'];
  27. $Comments = $_POST['Comments'];
  28. $Country = $_POST['Country'];
  29. $Colors = $_POST['Colors'];
  30.  
  31. # Database information-------------------------------------------
  32. # Trying to fetch data from database-----------------------------
  33.  
  34. $myServer = "localhost";
  35. $myUser = "root";
  36. $myPass = "";
  37. $myDB = "group";
  38.  
  39. //connection to the database
  40. $dbhandle = mysql_connect($myServer, $myUser, $myPass) //echo " connection to DB is OK ";
  41. or die("Couldn't connect to SQL Server on $myServer");
  42.  
  43. //select a database to work with
  44. $selected = mysql_select_db($myDB, $dbhandle) //echo " DB Access is OK ";
  45. or die("Couldn't open database $myDB");
  46.  
  47. echo "Your Name is : $Name </br>Password is : $Password </br>Chosen Season is : $Seasons </br>Put Comment is : $Comments </br>you are form : $Country </br> Chosen Colour is : $Colors </br>";
  48.  
  49. $query = "INSERT INTO info (Id, Name, Password, Seasons, Comments, Country, Colors) VALUES ('NULL', $Name, $Password, $Seasons, $Comments, $Country, $Colors)";
  50.  
  51. //execute the SQL query and return records
  52. $result = mysql_query($query) or die('Failed to write to Database');
  53.  
  54. /* $numRows = mysql_num_rows($result);
  55. echo "<h1>" . $numRows . " Row" . ($numRows == 1 ? "" : "s") . " Returned </h1>";
  56.  
  57. //display the results
  58. while($row = mysql_fetch_array($result))
  59. {
  60. echo "<li>" . $row["id"] . $row["name"] . $row["salary"] . $row["experience"] . "</li>";
  61. }
  62. */
  63. mysql_close($dbhandle);
  64.  
  65. ?>
Add Comment
Please, Sign In to add comment