Log in

View Full Version : points :)



Demonicman
03-02-2007, 09:26 PM
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
// 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
// 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!


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

Demonicman
03-02-2007, 10:07 PM
for some reason it says Points: 0 and it should say Points: 20 after your registered

thetestingsite
03-02-2007, 10:10 PM
Try changing this section:



$_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:



$pass = md5($_POST['pass']);

if (!get_magic_quotes_gpc()) {

$pass = addslashes($pass);

$username = addslashes($_POST['username']);

$points = ($_POST['points']);


Then change the following line:



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


to this:



$insert = "INSERT INTO users (username, password, points)
VALUES ('$username', '$pass', '$points')";


Hope this helps.

Demonicman
03-02-2007, 10:20 PM
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

thetestingsite
03-02-2007, 10:23 PM
Also, sorry I didn't take this out before, but look at the following:



$points = ($_POST['points']);


Take out the parts in red.
Hope this helps.

Demonicman
03-02-2007, 10:58 PM
thanks but what i really need is a way to start with 20 when writing the registration on the mysql table

thetestingsite
03-02-2007, 11:08 PM
Also, delete the following part in red:



<input name="points" type="text" disabled value="20" maxlength="2" readonly="true" contenteditable="false">


Didn't see that before, again sorry.

Demonicman
03-02-2007, 11:24 PM
it still hasnt made the points 20...

Demonicman
03-02-2007, 11:29 PM
hold it, nvm it worked! thank you thank you thank you thank you thank you