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)
add.php (registration page)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
}
?>
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!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
}
?>
what this is about: i am working on making points and can anyone help figure out problems and correct my code?Code:CREATE TABLE users (ID MEDIUMINT NOT NULL AUTO_INCREMENT PRIMARY KEY, username VARCHAR(60), password VARCHAR(60), points INT)
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



Reply With Quote

Bookmarks