Advertisement
Guest User

Untitled

a guest
Sep 27th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.88 KB | None | 0 0
  1. in dreamweaver i get syntar error on line 103 that the second to last line line in the code...And on wamp server i get this:  Parse error: syntax error, unexpected $end in C:\wamp\www\register\register.php on line 105
  2. please help me...
  3.  
  4. <head>
  5. <?php
  6. // Don't put your includes in the middle of the code!
  7. require_once ('connect_to_mysql.php');
  8.  
  9. function show_form()
  10. {
  11. $txt = "<h1>Register To Govana Designs</h1>";
  12. $txt .= "<form action='register.php' method='POST'>
  13. $txt .= <table>;
  14. $txt .= <tr> <td> First name: </td> <td> <input type='text' name='firstname' value='".$firstname."' /> </td> </tr>";
  15. $txt .= "<tr> <td> Last name: </td> <td> <input type='text' name='lastname' value='".$lastname."' /> </td> </tr>";
  16. $txt .= "<tr> <td> Enter a username: </td> <td> <input type='text' name='username' value='".$username."' /> </td> </tr>";
  17. $txt .= "<tr> <td> Email: </td> <td> <input type='email' name='email' value='".$email."' /> </td> </tr>";
  18. $txt .= "<tr> <td> Enter a password: </td> <td> <input type='password' name='password' /> </td> </tr>";
  19. $txt .= "<tr> <td> Comfim password: </td> <td> <input type='password' name='confirmpassword' /> </td> </tr>";
  20. $txt .= "</table>";
  21. $txt .= "<p> <input type='submit' name='submit' value='Register' /> </p>";
  22. $txt .= "</form>";
  23. return($txt);
  24. }
  25. function deal_with_form()
  26. {
  27. // Cleanup variables
  28. // no need to use "isset": ALL variables WILL be set, since the form has been sent.
  29. // howver, the variables VALUES may be blank!
  30. $firstname = strip_tags ($POST['firstname']);
  31. $lastname = strip_tags ($POST['lastname']);
  32. $username = strtolower (strip_tags($POST['username']));
  33. $email = strip_tags ($POST['email']);
  34. $password = strip_tags ($POST['password']);
  35. $comfirmpassword = strip_tags($POST['confirmpassword']);
  36. $datum = date("Y-m-d");
  37. // don't use "date": it is confusing with the function!
  38. // Although you should the validity of the field in javascript BEFORE sending the form,
  39. // you can check them here...
  40. if (($firstname == "firstname") || ($lastname == "lastname"))
  41. return ("missfields");
  42. if ( 'any other checks here' ) // if fail, return
  43. return ("incorrect");
  44. // Check if exists in DB
  45. $con = mysql_connect("localhost","root","");
  46. mysql_select_db("phplogin");
  47. $sql = "select `username` from `users` where `username`='" . $username . "' ";
  48. // recommended: all lower cases
  49. // note the syntax!
  50. // build your query separately, so you can use it in case of problems.
  51. $res = mysql_query($sql) or die ("Error: sql=" .$sql. "<br>" . mysql_error());
  52. // your previous query was incorrect (your mysql_num_rows would not work: you must use the return POINTER to results from the query )
  53. $cnt = mysql_num_rows($res);
  54. if ($cnt == 0) // register!
  55. {
  56. // Encrypt password
  57. $pwd = md5($password);
  58.  
  59. // build sql:
  60. $datum = date("Y-m-d");
  61. $sql = "insert into `users` (`id`, `firstname`, 'lastname', `username`, 'email', `password`, `datum` )
  62. values = ( NULL , '".$firstname."', '".$lastname."', '".$username."', '".$email."', '".$pwd."', '".$datum."' )";
  63. // change the field "date" in table to "datum: "date" is a keyword!!!
  64. mysql_query($sql); // do the insert.
  65. mysql_close($con);
  66. return("pass");
  67. }
  68. else
  69. {
  70. mysql_close($con);
  71. return ("taken");
  72. }
  73. {
  74. ?>
  75. </head>
  76. <html>
  77. <body>
  78. <?php
  79. if (!isset($_POST['submit'])) // $_POST is not set yet: first pass
  80. echo (show_form());
  81. else // $_POST is set: this code just received the form!
  82. {
  83. $res = deal_with_form();
  84. switch ($res)
  85. {
  86. case "pass":
  87. echo "You have just registered to Govana Designs! <a href='index.php'>Return to login page</a>";
  88. break;
  89. case "taken":
  90. echo "<p>Sorry, this name is already taken<p>";
  91. unset ($_POST['submit']);
  92. echo (show_form());
  93. break;
  94. case "incorrect":
  95. echo "<p>Sorry, some fields are incorrect</p>";
  96. unset ($_POST['submit']);
  97. echo (show_form());
  98. break;
  99. case "missfields":
  100. echo "<p>You must complete all fields</p>";
  101. unset ($_POST['submit']);
  102. }
  103. }
  104. ?>
  105. </body>
  106. </html>
  107.  
  108. line 105
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement