+ Reply to Thread
Results 1 to 8 of 8

Thread: php and mysql help

  1. #1
    jac904 is offline x10Hosting Member jac904 is an unknown quantity at this point
    Join Date
    Nov 2009
    Posts
    25

    Question php and mysql help

    Hi,I have created a members page and mysql db for my site and was wondering how to get the code for page and where to acutally insert code in order for page to work.This is very new to me.

  2. #2
    khopcraft77 is offline x10Hosting Member khopcraft77 is an unknown quantity at this point
    Join Date
    May 2011
    Location
    Sooke, B.C.
    Posts
    80

    Re: php and mysql help

    Could you explain what you are trying to do? Here are the basics of mysql: http://www.w3schools.com/php/php_mysql_intro.asp
    Play games at my website: Games of Greatness

  3. #3
    jac904 is offline x10Hosting Member jac904 is an unknown quantity at this point
    Join Date
    Nov 2009
    Posts
    25

    Talking Re: php and mysql help

    I wanted to make a members page on my where people had to create a login to become part of site.I watched a video and made mysql members data base in phpadmin.This is where i'm stuck,i wanted to know how to put this onto my site but not sure how to go about it.I don't know where to get the code or where to put it on site builder ,unless there is another way to create a working member page.

  4. #4
    bvkhunt11 is offline x10Hosting Member bvkhunt11 is an unknown quantity at this point
    Join Date
    Feb 2011
    Posts
    6

    Re: php and mysql help

    So is the login working? Do you need to know how to create login page or how to create database in phpmyadmin? Or do you need to know how to upload the database to the web server??
    Please be clear...

  5. #5
    zerostrike is offline x10Hosting Member zerostrike is an unknown quantity at this point
    Join Date
    May 2010
    Location
    Philippines
    Posts
    6

    Re: php and mysql help

    Do you mean you want a Register page and a login page?

    Kindly be specific so we can help/assist you in any way we can.

  6. #6
    jac904 is offline x10Hosting Member jac904 is an unknown quantity at this point
    Join Date
    Nov 2009
    Posts
    25

    Wink Re: php and mysql help

    A login and register page is what i want.I made this in phpmyadmin, but don't know what to do with it.

    ID int(11) No
    usename varchar(255) No
    sign_up_date datetime No
    email varchar(255) No
    bio text Yes NULL
    account_permissions enum('a', 'b', 'c') No b
    email_activation enum('0', '1') No 0
    password varchar(255) No
    lastlogin datetime No

    This is my first time dealing with this while making a site.Very new to me.

    Thank you for the help.

  7. #7
    er.rohittank22 is offline x10Hosting Member er.rohittank22 is an unknown quantity at this point
    Join Date
    Jan 2011
    Posts
    4

    Thumbs up Re: php and mysql help

    First of all create a database and Run this sql query in Phpmyadmin then follow next steps...

    CREATE TABLE IF NOT EXISTS `members` (
    `ID` int(11) NOT NULL AUTO_INCREMENT,
    `username` varchar(255) NOT NULL,
    `sign_up_date` datetime NOT NULL,
    `email` varchar(255) NOT NULL,
    `bio` text,
    `account_permissions` enum('a','b','c') DEFAULT NULL,
    `email_activation` enum('0','1') DEFAULT NULL,
    `password` varchar(255) NOT NULL,
    `lastlogin` datetime DEFAULT NULL,
    PRIMARY KEY (`ID`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;



    Now Make your web pages as....
    .................................................. ..................................
    -------------------For SignUp---------------------

    save this as 'signup.php'

    <h3 align='center'>Signup for a New Account</h3>
    <h4 align='center'>Please fill given details below:</h4>
    <form id='regForm' name='regForm' method='post' action='registerit.php'>

    <table width='600' border='0' cellpadding='2' cellspacing='0' align='center'>

    <tr>
    <th>*Email </th>
    <td><input name='email' type='text' class='textfield' id='email' /></td>
    </tr>
    <tr>
    <th>*Username</th>
    <td><input name='username' type='text' class='textfield' id='username' /></td>
    </tr>
    <tr>
    <th>*Password</th>
    <td><input name='password' type='password' class='textfield' id='password' /></td>
    </tr>
    <tr>
    <th>*Confirm Password </th>
    <td><input name='cpassword' type='password' class='textfield' id='cpassword' /></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td><input type='submit' name='Register' value='Register' /></td>
    </tr>
    </table>
    </form>
    ------------------------------------------------------------------------
    Save this as registerit.php
    <?php
    define('DB_HOST', 'localhost');
    define('DB_USER', 'YOUR_DATABASE_USERNAME'); //Change Username with Your
    define('DB_PASSWORD', 'YOUR_DB_PASSWORD'); //Change Password with Your
    define('DB_DATABASE', 'YOUR_DB_NAME'); //Change Database name with Your
    mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
    mysql_select_db(DB_DATABASE);


    $email = $_POST['email'];
    $username = $_POST['username'];
    $password = $_POST['password'];
    $cpassword = $_POST['cpassword'];
    $date=date('Y-m-d h-i-s A');

    if($password==$cpassword)
    {
    $q = mysql_query("insert into members (email,username,password,sign_up_date) values('$email','$username','$password','$date')") ;
    if ($q)
    {
    echo "<h2>Registration Successfull</h2>
    <a href='index.php'> Click to Login</a>";
    }
    else
    {
    echo "Something wrong with Query";
    }
    }
    else
    {
    echo "<h3>Password Not Match</h3>
    }
    ?>

    ---------------------------------------------------------------------------------
    -------------------For Login---------------------
    Save this as 'index.php'

    <h3 align='center'>Login</h3>

    <form id='loginForm' name='loginForm' method='post' action='loginit.php'>

    <table width='600' border='0' cellpadding='2' cellspacing='0' align='center'>


    <tr>
    <th>*Username</th>
    <td><input name='username' type='text' class='textfield' id='username' /></td>
    </tr>
    <tr>
    <th>*Password</th>
    <td><input name='password' type='password' class='textfield' id='password' /></td>
    </tr>

    <tr>
    <td>&nbsp;</td>
    <td><input type='submit' name='Login' value='Login' /></td>
    </tr>
    </table>
    </form>

    --------------------------------------------------
    Save this as loginit.php
    <?php
    define('DB_HOST', 'localhost');
    define('DB_USER', 'YOUR_DATABASE_USERNAME'); //Change Username with Your
    define('DB_PASSWORD', 'YOUR_DB_PASSWORD'); //Change Password with Your
    define('DB_DATABASE', 'YOUR_DB_NAME'); //Change Database name with Your
    mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
    mysql_select_db(DB_DATABASE);

    session_start();

    $username = $_POST['username'];
    $password = $_POST['password'];
    $sql = mysql_query("SELECT * FROM members where username='$username' && password='$password'");
    if(mysql_num_rows($sql)==1)
    {
    session_regenerate_id();
    $member = mysql_fetch_assoc($sql);
    $_SESSION['SESS_MEMBER_ID'] = $member['id'];
    $_SESSION['SESS_EMAIL'] = $member['email'];
    $_SESSION['SESS_USERNAME'] = $member['username'];
    session_write_close();
    header("location: logged.php");

    }else {

    echo "Username Password Not Matched";

    }
    ?>

    -----------------------------------------------------------------------------------------
    Save this as 'logged.php'
    <?php
    //Start session
    session_start();

    if($_SESSION['SESS_USERNAME'] == '') {
    header("location: access-denied.php");
    exit();
    }
    else
    {
    echo "Welcome $_SESSION[SESS_USERNAME] You are Logged in";
    echo "<br /><a href='logout.php'>Logout</a>";

    }
    ?>

    ---------------------------------------------------------
    Save it as 'logout.php'
    <?php

    //Start session
    session_start();
    unset($_SESSION['SESS_MEMBER_ID']);
    unset($_SESSION['SESS_EMAIL']);
    unset($_SESSION['SESS_USERNAME']);
    //Unset the variables stored in session

    echo "<h1>Logout </h1>
    <p align='center'>&nbsp;</p>
    <h4 align='center' class='err'>You have been logged out.</h4>";

    ?>

    -----------------------------------------------------------
    Save it as 'access-denied.php'
    <?php
    echo "<h3>Access Denied</h3>";
    ?>

    -------------------------------------------------------------------------------------
    I think that this will solve your problem... enjoy...

  8. #8
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: php and mysql help

    Do NOT use er.rohittank22's code. It is incredibly insecure (vulnerable to SQL injection, vulnerable to session hijacking, stores passwords as plaintext). It also uses the outdated (and soon-to-be deprecated) mysql extension. It's a great example of why you shouldn't do this yourself for production sites. You should design and build a login system only to learn or if you've a strong understanding of security issues.

    The topic of logins and user systems has been covered many times before on this forum. Search for relevant threads to get better answers.
    Last edited by misson; 08-07-2011 at 01:26 AM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

+ Reply to Thread

Similar Threads

  1. Replies: 3
    Last Post: 02-02-2011, 02:09 AM
  2. Replies: 1
    Last Post: 10-15-2010, 01:46 PM
  3. Replies: 2
    Last Post: 10-14-2010, 10:49 AM
  4. Replies: 2
    Last Post: 12-17-2007, 03:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers