Click to See Complete Forum and Search --> : Sign up, Log on.. PHP & MySQL


Sux0rZh@jc0rz
11-23-2003, 11:07 PM
alrighty... I hope pyro is on to come to my rescue and point out an easy answer that i just cant find cause am a phpnewb...(As in "has no experience with SQL at all in php" newb.)

ready for this? here goes....

Config.php file:$host = "www.****.org:3306";
$user = "****";
$dbpassword = "****";
$database = "xaxei";
$prefix = "loginadv_";
$Link = mysql_connect ($host, $user, $dbpassword);

Signup.html<form action="/signup.php">
<input type="text name="username"><br>
<input type="password" name="password"<br>
<input type="submit">
</form>

Signup.php<?php
include "http://www.aspfreeserver.com/xaxei/config.php";
$username = $_POST["username"];
$userpass = $_POST["password"];
if (($username) AND ($userpass)){
$query = "SELECT * from ". $prefix . "users where(`username` = '$username')";
$result = mysql_db_query($database,$query,$Link);
$logindetail = mysql_fetch_array($result);
$userpass = md5($userpass);
if (($username == $logindetail[username]) AND ($userpass == $logindetail[password])){
print "<h2>Signup Successful.</h2>"
} else {
print "Incorrect login";
}
} else {
print "please login";
print "<br><a href=login.php>login</a>";
}
?>

now my friend made that signup.php.... and i think he was confused as to what i wanted him to do and i think he made an actual login instead of signup... shouldn't it be CREATE blah blah blah? please post the code i should be using to CREATE a username and password into my database so that i can actually use a login script to search the database... if you want to put the code for a signup AND a login, that would be most helpful... i am trying to learn how sql works by example... and so far i understand alot, but i cant make it work for me yet because i have gaps still..

thanks in advance,
cheers.

pyro
11-24-2003, 08:37 AM
To create a new row, it would look something like this:

$sql = "INSERT INTO `tablename` (`id`, `username`, `password`) VALUES ('', '$username', '$password');";
mysql_query($sql);

Sux0rZh@jc0rz
11-24-2003, 05:37 PM
Originally posted by pyro $sql = "INSERT INTO `tablename` (`id`, `username`, `password`) VALUES ('', '$username', '$password');";
mysql_query($sql);

ok...wait... im a complete newb to SQL and this is the first time i have seen it other than a brief glimpse earlier at www.w3schools.com ... so the INSERT INTO = where it is insertered(duh) then the tablename i understand... then username and password i understand.. but what would the ID be??? im confuzzled... but i understand it perfectly and ty for the script.. but what is ID used for...?

pyro
11-24-2003, 08:14 PM
I make all my database tables with an id field, which is set to primary and auto-increment. This is so that each row will be gaurenteed to have something unique. I'd recommend doing so...

Sux0rZh@jc0rz
11-24-2003, 08:59 PM
oh... ok... uhm... what? let me think this through... the id field... how would i set the properties on that?? i have phpmyadmin, so tell me if i can do it from there? also: what would i put in my script for the ID?

pyro
11-24-2003, 10:21 PM
Something like this should be good:

name: id
type: int
length: 11
auto-increment
primary

Sux0rZh@jc0rz
11-27-2003, 11:17 AM
ok... so my script should look like this?

$username = $_POST('username');
$password = $_POST('password');
$sql = "INSERT INTO `users` (`id`, `username`, `password`) VALUES ('', '$username', '$password');";
mysql_query($sql);

and it will work? or do i need to change `id` to something else? also: why do you use ` in SQL statements instead of 's?

pyro
11-27-2003, 11:32 AM
Your $_POST variables should use [] rather than ()...

Sux0rZh@jc0rz
11-27-2003, 11:44 AM
k. ty.

pyro
11-27-2003, 11:52 AM
Sure thing...