Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.46 KB | None | 0 0
  1. <html>
  2. <head><title>Building A Form</title></head>
  3. <body>
  4. <p>
  5. <?php
  6. error_reporting(0);
  7. $search = $_GET["search"];
  8. $self=$_SERVER["PHP_SELF"];
  9. //default
  10. if ($search != NULL){
  11. include ('db_login.php');
  12. $connection = mysql_connect($db_host, $db_username, $db_password);
  13. if (!$connection) {
  14. die ("Could not connect to the database: <br />".mysql_error());
  15. }
  16. else{
  17. echo ("Connection established!<p>");
  18. }
  19. echo ('<p>Your search was: '.$search.'.<p>
  20. ');
  21. $db_select=mysql_select_db($db_database);
  22. if (!$db_select){
  23. die ("Could not select the database: <br />".mysql_error());
  24. }
  25. $select=' SELECT ';
  26. $column=' * ';
  27. $from =' from ';
  28. $first_table =' first_table ';
  29. //$query=$select.$column.$from.$first_table;
  30. $query="SELECT * from first_table WHERE column_1 = $search ";//this work?
  31. $result=mysql_query($query);
  32. if (!$result){
  33. die ("Could not query the database: <br />".mysql_error());
  34. }
  35. echo ('<table border="1">');
  36. echo ('<tr><th>Numbers</th><th>Letters</th></tr>');
  37. while ($result_row = mysql_fetch_row($result)) {
  38.     echo ('<tr><td>');
  39.     echo ($result_row[0]. '</td><td>');
  40.     echo ($result_row[1]. '</td></tr>');
  41. }
  42. mysql_close($connection);
  43. echo ('<p><a href ="simple.php">Try again?</a>');
  44. }
  45. else {
  46.     echo('
  47. <form action="'.$_SERVER["PHP_SELF"].'" method="GET">
  48. <label>Search: <input type=text name="search" /></label>
  49. <input type="submit" value="Go!" />
  50. </form>
  51. <p>Enter "123", "234", or "345"
  52. ');
  53. }
  54. ?>
  55. <p><a href ="index.html">Back</a>
  56. </body>
  57. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement