Staredit Network > Forums > Technology & Computers > Topic: PHP Ongoing Assistance
PHP Ongoing Assistance
Mar 9 2008, 4:20 pm
By: InsolubleFluff
Pages: < 1 « 2 3 4 5 6 >
 

Mar 17 2008, 3:22 pm NexY Post #61



@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.

Mar 17 2008, 3:53 pm Forsaken Archer Post #62



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.

Mar 17 2008, 4:27 pm NexY Post #63



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.

Mar 17 2008, 7:01 pm Forsaken Archer Post #64



With what code?



None.

Mar 17 2008, 9:39 pm Fierce Post #65



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.

Mar 18 2008, 3:06 am NexY Post #66



Sorry was in a hurry, here's the code I used:

Quote
<?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.

Mar 18 2008, 10:16 am Fierce Post #67



*checks it out

This is a way I make my registrations (usually):
Quote
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.

Mar 18 2008, 3:04 pm NexY Post #68



I tried it your way, though I don't see any difference unless I'm missing something o.O. I changed it to this:

Quote
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 Script

Thank You



None.

Mar 18 2008, 4:32 pm Forsaken Archer Post #69



Quote from NexY
$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.

Mar 18 2008, 5:04 pm NexY Post #70



lol omg i'm so stupid x.X :lol:

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.

Mar 18 2008, 5:23 pm Forsaken Archer Post #71



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.

Mar 19 2008, 4:03 am NexY Post #72



The error report came out with:

Query Failed: 1046
No database selected


Which 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:
Quote
<?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 :dontgetit:



None.

Mar 19 2008, 4:28 am Forsaken Archer Post #73



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.

Mar 19 2008, 8:50 am AfterLifeLochie Post #74



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.

Mar 19 2008, 8:55 am AfterLifeLochie Post #75



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.

Mar 19 2008, 3:02 pm NexY Post #76



And again, I'm so stupid :unsure: . 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 :lol: .

Thanks



None.

Mar 20 2008, 4:19 am InsolubleFluff Post #77



edit



None.

Mar 20 2008, 4:30 am NexY Post #78



Just wondering if this logic is right, since I get no errors:

Quote
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.

Mar 20 2008, 6:11 am AfterLifeLochie Post #79



Looks ok, post us the whole code and requirements as attachments, and I'll see if it works with PHP 4.4.6!



None.

Mar 20 2008, 3:11 pm NexY Post #80



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:
register.php
Hits: 4 Size: 2.92kb



None.

Options
Pages: < 1 « 2 3 4 5 6 >
  Back to forum
Please log in to reply to this topic or to report it.
Members in this topic: None.
[03:02 am]
Ultraviolet -- I'm gonna send inf to have sex with their moms
[03:02 am]
Ultraviolet -- fuck those motherfuckers
[11:02 pm]
NudeRaider -- PSA: ASUS apparently decided their RMA department needs to "become profitable" and for a while now outright tries to scam customers. They were called out on it a year ago, promised to change, but didn't. https://www.youtube.com/watch?v=7pMrssIrKcY so my recommendation: Stop buying ASUS, and if you already have and need something RMA'd, make sure to not let them bully you into paying.
[03:08 pm]
Oh_Man -- example of wat u mean?
[2024-5-15. : 5:59 am]
NudeRaider -- *is
[2024-5-15. : 5:17 am]
NudeRaider -- despite all its flaws the sound design its fantastic
[2024-5-14. : 10:29 pm]
Oh_Man -- homeworld 3 = massive disappointment
[2024-5-14. : 10:05 am]
Moose -- ya
[2024-5-14. : 5:23 am]
zsnakezz -- yes
[2024-5-12. : 8:51 pm]
l)ark_ssj9kevin -- Are you excited for Homeworld 3?
Please log in to shout.


Members Online: Roy, 5miae7791ga5, 7avac6691rh7