Guest User

Untitled

a guest
Mar 5th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. I'm having some issues with understanding how to setup a registration section and a log in section on the same page,
  2.  
  3. I have created a main.php page and within that page I'm already connected and authenticated against the sql server and the database I created. in my main form.php this is what I have. everything below works fine, this where I'm getting confused.
  4.  
  5. on the main form I want to put 2 sections the current log in that works correctly, but I want to be able to add a register section.
  6. and with the registration section I want to add a few more sections, like name, username, password, email, and location when they register now my question is.
  7.  
  8. I think my biggest problem is understanding that the main page is connected to the database server and a table and I'm working if using that table is the best practice, because if so I would have to plan it out correctly. This is my main issue,
  9.  
  10.  
  11. 1. should the members table have those additional options?
  12.  
  13. 2. when I create the profile.php page after registration is complete is there any settings that I need to
  14. have on those sections in order to pull data from that table for the profile.php you know to display names, email, etc.
  15.  
  16.  
  17. Thanks so much for everyone's help.
  18.  
  19. "Please no rush and if you could please send your response to my email or another pastebin"
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30. This is my main form:
  31.  
  32. <table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
  33. <tr>
  34. <form name="form1" method="post" action="check.php">
  35. <td>
  36. <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
  37. <tr>
  38. <td colspan="3"><strong>Member Login </strong></td>
  39. </tr>
  40. <tr>
  41. <td width="78">Username</td>
  42. <td width="6">:</td>
  43. <td width="294"><input name="myusername" type="text" id="myusername"></td>
  44. </tr>
  45. <tr>
  46. <td>Password</td>
  47. <td>:</td>
  48. <td><input name="mypassword" type="text" id="mypassword"></td>
  49. </tr>
  50. <tr>
  51. <td>&nbsp;</td>
  52. <td>&nbsp;</td>
  53. <td><input type="submit" name="Submit" value="Login"></td>
  54. </tr>
  55. </table>
  56. </td>
  57. </form>
  58. </tr>
  59. </table>
  60.  
  61.  
  62. This is check.php
  63.  
  64. <?php
  65. $host="localhost";
  66. $username="juniorbisono";
  67. $password="mypassword";
  68. $db_name="juniorbisono";
  69. $tbl_name="members"; //
  70.  
  71. // Connect to server and select databse.
  72. mysql_connect("$host", "$username", "$password")or die("cannot connect");
  73. mysql_select_db("$db_name")or die("cannot select DB");
  74.  
  75. // username and password sent from form
  76. $myusername=$_POST['myusername'];
  77. $mypassword=$_POST['mypassword'];
  78.  
  79. // To protect MySQL injection (more detail about MySQL injection)
  80. $myusername = stripslashes($myusername);
  81. $mypassword = stripslashes($mypassword);
  82. $myusername = mysql_real_escape_string($myusername);
  83. $mypassword = mysql_real_escape_string($mypassword);
  84.  
  85. $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
  86. $result=mysql_query($sql);
  87.  
  88. // Mysql_num_row is counting table row
  89. $count=mysql_num_rows($result);
  90. // If result matched $myusername and $mypassword, table row must be 1 row
  91.  
  92. if($count==1){
  93. // Register $myusername, $mypassword and redirect to file "profile.php"
  94. session_register("myusername");
  95. session_register("mypassword");
  96. header("location:success.php");
  97. }
  98. else {
  99. echo "Wrong Username or Password";
  100. }
  101. ?>
Add Comment
Please, Sign In to add comment