Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I'm having some issues with understanding how to setup a registration section and a log in section on the same page,
- 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.
- 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.
- 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.
- 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,
- 1. should the members table have those additional options?
- 2. when I create the profile.php page after registration is complete is there any settings that I need to
- have on those sections in order to pull data from that table for the profile.php you know to display names, email, etc.
- Thanks so much for everyone's help.
- "Please no rush and if you could please send your response to my email or another pastebin"
- This is my main form:
- <table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
- <tr>
- <form name="form1" method="post" action="check.php">
- <td>
- <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
- <tr>
- <td colspan="3"><strong>Member Login </strong></td>
- </tr>
- <tr>
- <td width="78">Username</td>
- <td width="6">:</td>
- <td width="294"><input name="myusername" type="text" id="myusername"></td>
- </tr>
- <tr>
- <td>Password</td>
- <td>:</td>
- <td><input name="mypassword" type="text" id="mypassword"></td>
- </tr>
- <tr>
- <td> </td>
- <td> </td>
- <td><input type="submit" name="Submit" value="Login"></td>
- </tr>
- </table>
- </td>
- </form>
- </tr>
- </table>
- This is check.php
- <?php
- $host="localhost";
- $username="juniorbisono";
- $password="mypassword";
- $db_name="juniorbisono";
- $tbl_name="members"; //
- // Connect to server and select databse.
- mysql_connect("$host", "$username", "$password")or die("cannot connect");
- mysql_select_db("$db_name")or die("cannot select DB");
- // username and password sent from form
- $myusername=$_POST['myusername'];
- $mypassword=$_POST['mypassword'];
- // To protect MySQL injection (more detail about MySQL injection)
- $myusername = stripslashes($myusername);
- $mypassword = stripslashes($mypassword);
- $myusername = mysql_real_escape_string($myusername);
- $mypassword = mysql_real_escape_string($mypassword);
- $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
- $result=mysql_query($sql);
- // Mysql_num_row is counting table row
- $count=mysql_num_rows($result);
- // If result matched $myusername and $mypassword, table row must be 1 row
- if($count==1){
- // Register $myusername, $mypassword and redirect to file "profile.php"
- session_register("myusername");
- session_register("mypassword");
- header("location:success.php");
- }
- else {
- echo "Wrong Username or Password";
- }
- ?>
Add Comment
Please, Sign In to add comment