@AfterLifeLochie: I have seperate file where it connects to the database, then I use include. I didn't type that up in the code I put up there, but it's in the actual code.
@Fierce: Thanks, I will check it out. I also have another problem, it looks like it doesn't like the or operator. I get this error:
Parse error: syntax error, unexpected T_BOOLEAN_OR in /home/divnxn5/public_html/register.php on line 25
Which is the line if(!$username) || (!$password).
Any idea to what ma be wrong?
Post has been edited 1 time(s), last time on Mar 17 2008, 3:36 pm by NexY.
None.
Yeah, you didn't enclose the if statement:
if(!$username || !$password)
is all that is necessary... or if you really feel the need to enclose each statement:
if((!$username) || (!$password))
None.
Oh thank you!
Edit: tried it out, when I click register it says invalid username or pass? x.X
Im such a noob D:
Post has been edited 1 time(s), last time on Mar 17 2008, 4:33 pm by NexY.
None.
You need to be a little more specific; it could be different things. If the username and password that you entered isn't exactly the same as whats in the database, it could display it. If there is an exact match, show us the code.
Make sure that if you are using sha1($_POST['password']); that the password in the database uses sha1 encryption. If it displays the regular password, remove the sha1(); encryption.
None.
Sorry was in a hurry, here's the code I used:
<?php
$username = $_POST['name'];
$password = sha1($_POST['pass']);
if(!$con)
{
echo "Registering is disabled right now.";
}
else
{
if(!$_POST['register'])
{
echo "<form action='register.php' method='post'> <br />
Username: <input type='text' name='user' id='user' />
Password: <input type='password' name='pass' id='pass' />
<input type='submit' value='Register' name='register' id='register' /></form>";
}
else
{
if(!$username || !$password)
{
echo "Username or Password is invalid";
}
else
{
mysql_select_db("mydb);
mysql_query("INSERT INTO users(username, password)
VALUES('$username', '$password')");
mysql_close($con);
}
}
}
?>
Like I said before, when I click register, it says "Username or Password is invalid." Thanks again!
None.
*checks it out
This is a way I make my registrations (usually):
if(!$username OR !$password OR !$email OR !$code)
{
echo ('You forgot to fill something out! <a href="javascript:history.go(-1);">Go back</a>');
}
else
{
// Do stuff
}
Post has been edited 2 time(s), last time on Mar 18 2008, 10:32 am by Fierce.
None.
I tried it your way, though I don't see any difference unless I'm missing something o.O. I changed it to this:
if(!$username OR !$password)
{
echo ("Username or Password is invalid!<br /><br /><a href='javascript:history.go(-1)'>Go
Back</a>");
}
else
{
//stuff
}
It's still saying "Username or Password is invalid". Here's the link, if you want to see it yourself:
Register ScriptThank You
None.
$username = $_POST['name'];
$password = sha1($_POST['pass']);
Username: <input type='text' name='user' id='user' />
Password: <input type='password' name='pass' id='pass' />
See a problem? I do.
Here's the anwser (in small text):
POST['name'] doesn't exist, so it'll always be empty... use POST['user'] or change form to name="name"
None.
lol omg i'm so stupid x.X
thanks xD
Edit: Don't mean to sound like a drag x.X but it won't add anything to the db >.< And i'm pretty sure im selecting the right db and table with the right fields. Triple checked D:...
Post has been edited 1 time(s), last time on Mar 18 2008, 5:11 pm by NexY.
None.
No sql error? Ugh... I hate mysql commands without a sql class to easy functions... Maybe I'll send you mine.
mysql_select_db("mydb
"); // need a " here
$query = mysql_query("INSERT INTO users(username, password) VALUES('{$username}', '{$password}')", $con); // dunno if you need $con here
if (!$query) echo "Query failed: " . mysql_errno() . '<br />' . mysql_error();
mysql_close($con);
Edit: One problem I just fixes is that you didn't have mysql_select_db in quotes. Just one quote.
None.
The error report came out with:
Query Failed: 1046
No database selectedWhich I think it's weird. Because I am selecting a database with mysql_select_db. I also added the other quotes that I missed. Here's the code again x.X:
<?php
$username = $_POST['user'];
$password = sha1($_POST['pass']);
function error()
{
if(!$query)
{
echo "Query Failed: " . mysql_errno() . '<br />' . mysql_error();
}
}
if(!$con)
{
echo "Registering is disabled right now.";
}
else
{
if(!$_POST['register'])
{
echo "<form action='register.php' method='post'> <br />
Username: <input type='text' name='user' id='user' />
Password: <input type='password' name='pass' id='pass' />
<input type='submit' value='Register' name='register' id='register' /></form>";
}
else
{
if(!$username || !$password)
{
echo ("Username or Password is invalid!<br /><br /><a href='javascript:history.go(-1)'>Go
Back</a>");
}
else
{
mysql_select_db("divnx5_web");
$query = mysql_query("INSERT INTO users(username, password)
VALUES('{$username}', '{$password}')", $con);
error();
mysql_close($con);
}
}
}
?>
Frustrating
None.
Obviously if it says no database selected, the database name is wrong?
Usually it's like site.account.name_name.you.gave.it
Like divnx5_web.
None.
Tell it to slect the database, not just let it sit there.
Try creatng a query and putting it into mysql_query($yourquery) or something like that.
BIG NOTE:
If your'e using a new version of PHP, use mysqli insead of old mysql.
None.
Hmmm... Looking back at input into field, data, looks like you need to drop the { and } around your variables.
I would try this:
$quelery = mysql_query("INSERT INTO users (username, password) VALUES('$username', '$password')", $con);
None.
And again, I'm so stupid
. The db name was wrong, I was missing an "n". >.> I really need to learn to debug better.
It ended up working thanks to all your help.
Guess I'll be back, since I can start learning new code now
.
Thanks
None.
Just wondering if this logic is right, since I get no errors:
else
{
if(!$username)
{
echo "The username you entered encountered a problem.";
check();
echo ('<br /><br /><a href="javascript:history.go(-1);">Go Back</a>');
}
if(!$password)
{
echo "The password field cannot be left empty!";
echo ('<br /><br /><a href="javascript:history.go(-1);">Go Back</a>');
}
if(!$email)
{
echo "The email you entered encountered a problem.";
echo ('<br /><br /><a href="javascript:history.go(-1);">Go Back</a>');
}
if(!$password == $password2)
{
echo "The passwords you entered do not match.";
echo ('<br /><br /><a href="javascript:history.go(-1);">Go Back</a>');
}
else
{
mysql_select_db("divnxn5_web");
$query = mysql_query("INSERT INTO users(username, password, email) VALUES('{$username}', '{$password}', '{$email}')");
error();
mysql_close($con);
}
Thank You.
None.
Looks ok, post us the whole code and requirements as attachments, and I'll see if it works with PHP 4.4.6!
None.
I attached register.php. There's also connect.php where I connect to my db, don't think that's needed to look at ;o.
Problem I have is, it never says username is invalid, pass is invalid, email.....,or the 2passwords dont match. And the function check(); gives back errors saying unexpected "`". So I commented it out.
Attachments:
None.