Results 1 to 9 of 9

Thread: points :)

  1. #1
    Join Date
    Feb 2007
    Location
    Earth
    Posts
    127
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default points :)

    ok its more of a php question, but mysql is involved as well

    account.php (this page will show all user info, just a line with the points for now)

    PHP Code:
    <?php 
    // Connects to your Database 
    mysql_connect("localhost""root","") or die(mysql_error()); 
    mysql_select_db("kalrith") or die(mysql_error()); 

    //checks for login and points
    if(isset($_COOKIE['ID_my_site'])) 

    // Collects data from "friends" table  
    $username $_COOKIE['ID_my_site']; 
    $pass $_COOKIE['Key_my_site'];
    $check mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); 
    while(
    $info mysql_fetch_array$check )) 


    //if the cookie has the wrong password, they are taken to the login page 
    if ($pass != $info['password']) 
    header("Location: login.php"); 


    //member area is here 
    else 

    ?>
    Points: <?php echo"$info['points']" ?>
    <?php



    else 

    //if not a member is shown this

    ?>
    <?php 
    include("head.php"); ?>
    You need to be signed in to have points!
    <?php include("foot.php"); ?>
    <?php

    ?>
    add.php (registration page)
    PHP Code:
    <?php 
    // Mysql data removed for security reasons 

    //This code runs if the form has been submitted
    if (isset($_POST['submit'])) { 

    //This makes sure they did not leave any fields blank
    if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] ) {
    die(
    'You must fill in all the information to be registered. <a href="add.php">Go Back</a>');
    exit;
    }

    // checks if the username is in use
    if (!get_magic_quotes_gpc()) {
    $_POST['username'] = addslashes($_POST['username']);
    }
    $usercheck $_POST['username'];
    $check mysql_query("SELECT username FROM users WHERE username = '$usercheck'"
    or die(
    mysql_error());
    $check2 mysql_num_rows($check);

    //if the name exists it gives an error
    if ($check2 != 0) {
    die(
    'Sorry, the username '.$_POST['username'].' is already in use. <a href="add.php">Try it again.</a>');
    }

    // this makes sure both passwords entered match
    if ($_POST['pass'] != $_POST['pass2']) {
    die(
    'Your passwords did not match. <a href="add.php">Try again.</a> ');
    }

    // here we encrypt the password and add slashes if needed
    $_POST['pass'] = md5($_POST['pass']);
    if (!
    get_magic_quotes_gpc()) {
    $_POST['pass'] = addslashes($_POST['pass']);
    $_POST['username'] = addslashes($_POST['username']);
    $_POST['points'] = ($_POST['points']);
    }

    // now we insert it into the database 
    $insert "INSERT INTO users (username, password, points)
    VALUES ('"
    .$_POST['username']."', '".$_POST['pass']."', '".$_POST['points']."')";
    $add_member mysql_query($insert);
    ?>

    <!-- Now we let them know if their registration was successful -->
    <h1>Registered</h1>
    <p>Thank you, you have registered - you may now <a href="login.php">login</a>.</p>
    <?php 

    else 
    {    
    ?>
    <?php 
    include("head.php"); ?>
    <center>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <table border=3 cellpadding=4 bgcolor="black">
    <tr><td bgcolor="black"><h2><center><font color="#00ff00">Please register before using the content on Kalrith</font></center></h2></td></tr>
    <tr><td bgcolor="black"><font color="#00ff00">Username:</font> 
    <input type="text" name="username" maxlength="60">
    </td></tr>
    <tr><td bgcolor="black"><font color="#00ff00">Password (1-10 characters):</font> 
    <input type="password" name="pass" maxlength="10">
    </td></tr>
    <tr><td bgcolor="black"><font color="#00ff00">Confirm Password:</font> 
    <input type="password" name="pass2" maxlength="10">
    </td></tr>
    <tr><td bgcolor="black"><font color="#00ff00">Number of Starter Points:</font> 
    <input name="points" type="text" disabled value="20" maxlength="2" readonly="true" contenteditable="false">
    </td></tr>
    <tr><th colspan=2><input type="submit" name="submit" value="Finished please register me"></th></tr> </table>
    </form></center>
    <center><table border=3 cellpadding=6><tr><td bgcolor="black"><center><font color="#00ff00"><h4>Already registered? <a href = "login.php">Login</a></h4></font></center></td></tr></table></center>
    <?php include("foot.php"); ?>
    <?php 

    ?>
    this is the mysql from what i can gather so far for the username and the password but i cant figure out the points one!

    Code:
    CREATE TABLE users (ID MEDIUMINT NOT NULL AUTO_INCREMENT PRIMARY KEY, username VARCHAR(60), password VARCHAR(60), points INT)
    what this is about: i am working on making points and can anyone help figure out problems and correct my code?

    ok a lot of the php syntax is wrong i bet, but i cant figure out the whole mysql concept, and if im not good with that im not good with writing from php onto mysql

    help appreciated
    Last edited by Demonicman; 03-02-2007 at 09:21 PM.

  2. #2
    Join Date
    Feb 2007
    Location
    Earth
    Posts
    127
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    for some reason it says Points: 0 and it should say Points: 20 after your registered

  3. #3
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Try changing this section:

    Code:
    $_POST['pass'] = md5($_POST['pass']);
    if (!get_magic_quotes_gpc()) {
    $_POST['pass'] = addslashes($_POST['pass']);
    $_POST['username'] = addslashes($_POST['username']);
    $_POST['points'] = ($_POST['points']);
    to something like this:

    Code:
    $pass = md5($_POST['pass']);
    
    if (!get_magic_quotes_gpc()) {
    
    $pass = addslashes($pass);
    
    $username = addslashes($_POST['username']);
    
    $points = ($_POST['points']);
    Then change the following line:

    Code:
    $insert = "INSERT INTO users (username, password, points)
    VALUES ('".$_POST['username']."', '".$_POST['pass']."', '".$_POST['points']."')";
    to this:

    Code:
    $insert = "INSERT INTO users (username, password, points)
    VALUES ('$username', '$pass', '$points')";
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  4. #4
    Join Date
    Feb 2007
    Location
    Earth
    Posts
    127
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    it made it more readable, but it hasnt changed the points lol

    also i have added points INT to the mysql, although it doesnt start you off with 20

  5. #5
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Also, sorry I didn't take this out before, but look at the following:

    Code:
    $points = ($_POST['points']);
    Take out the parts in red.
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  6. #6
    Join Date
    Feb 2007
    Location
    Earth
    Posts
    127
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    thanks but what i really need is a way to start with 20 when writing the registration on the mysql table

  7. #7
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Also, delete the following part in red:

    Code:
    <input name="points" type="text" disabled value="20" maxlength="2" readonly="true" contenteditable="false">
    Didn't see that before, again sorry.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  8. #8
    Join Date
    Feb 2007
    Location
    Earth
    Posts
    127
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    it still hasnt made the points 20...

  9. #9
    Join Date
    Feb 2007
    Location
    Earth
    Posts
    127
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    hold it, nvm it worked! thank you thank you thank you thank you thank you

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •