Page 1 of 1

Copied from a thenewboston tut, doesn't work?

Posted: Wed Aug 10, 2011 5:49 am
by Jackount
I have set up xampp on my computer, and I am 100% that all works(PHP, Apache and mySQL).

Then when I go to the temp site I've made, http://localhost/Hjemmeside/index.php, it works all fine. I write in all the inputs, and when i submit, it seems to work fine, it tells me if the passwords don't match etc. BUT it ALWAYS outputs this first:
Notice: Use of undefined constant username - assumed 'username' in [text]C:\xampp\htdocs\Hjemmeside\register.php on line 4

Notice: Use of undefined constant password - assumed 'password' in C:\xampp\htdocs\Hjemmeside\register.php on line 5

Notice: Use of undefined constant password2 - assumed 'password2' in C:\xampp\htdocs\Hjemmeside\register.php on line 6

Deprecated: Function eregi() is deprecated in C:\xampp\htdocs\Hjemmeside\register.php on line 9

Notice: Use of undefined constant password - assumed 'password' in C:\xampp\htdocs\Hjemmeside\register.php on line 26

Notice: Use of undefined constant password2 - assumed 'password2' in C:\xampp\htdocs\Hjemmeside\register.php on line 26[/text]

I have this index.php page:

Code: Select all

<!--#include file="header.html"-->

<form action="register.php" method="post">
	<p>Brugernavn: <br> <input type="text" name="username" size="20" maxlength="30" value=""></p>
	<p>E-mail: <br> <input type="text" name="email" size="20" maxlength="50"></p>
	<p>Kodeord: <br> <input type="password" name="password" size="20" maxlength="30"></p>
	<p>Skriv kodeord igen: <br> <input type="password" name="password2" size="20" maxlength="30"></p>
	<p><input type="submit" name="submit" value="Opret Bruger"></p>
</form>

<!--#include file="bottom.html"-->
the form is referring to register.php, which is like this:

Code: Select all

<?php
include('config.php');

$test = $_POST[username]; //Line 4
$pass = $_POST[password]; //Line 5
$pass2 = $_POST[password2]; //Line 6

//alphanumeric
if (!eregi("([^A-Za-z0-9])", $test)) { //Line 9
	
		//duplicate names
		$query = "SELECT * FROM users WHERE username ='$_POST[username]'";
		$result = mysql_query($query);
		$num = mysql_num_rows($result);
		
		if ($num == 0){
			
		}else{
			error("Brugernavn er allerede i brug.");
		}
	
} else {
	error("Du må kun bruge bogstaver og tal.");	
}

if ($_POST[password] != $_POST[password2]) { //Line 26
		error("Kodeordene er ikke ens.");
	}
	
//ERROR FUNCTION
function error($t) {
	echo "<p style='color:red'>" . $t . "</p>";
	include('index.php');
}
?>
and the config.php is like this, which probably doesn't matter, but anyway:

Code: Select all

<?php

$host="localhost"; 
$username="root"; 
$db_name="database";

//connecting
mysql_connect($host, "$username")or die("cannot connect to server");
mysql_select_db("$db_name")or die("cannot connect to DB");

?>
I sincerely hope anyone can discover/explain the problem for me. It all works fine, excepts it outputs what I wrote above.
Thanks in advance! :)

Re: Copied from a thenewboston tut, doesn't work?

Posted: Wed Aug 10, 2011 6:05 am
by Dodon
You're forgetting quotes in your $_POST

Code: Select all

$test = $_POST[username]; //Line 4
$pass = $_POST[password]; //Line 5
$pass2 = $_POST[password2]; //Line 6
 
becomes

Code: Select all

$test = $_POST['username']; //Line 4
$pass = $_POST['password']; //Line 5
$pass2 = $_POST['password2']; //Line 6
 
There are more occurrences but you get the idea

Re: Copied from a thenewboston tut, doesn't work?

Posted: Wed Aug 10, 2011 6:18 am
by Jackount
GREAT; thank you! Typically such a stupid mistake...
Now left is only the
Deprecated: Function eregi() is deprecated in C:\xampp\htdocs\Hjemmeside\register.php on line 9
...

Re: Copied from a thenewboston tut, doesn't work?

Posted: Wed Aug 10, 2011 6:31 am
by Dodon

Re: Copied from a thenewboston tut, doesn't work?

Posted: Wed Aug 10, 2011 3:58 pm
by McInfo
Actually, all of the POSIX Extended Regular Expression (ERE) functions (ereg*, etc.) are deprecated in favor of Perl Compatible Regular Expression (PCRE) functions (preg*). The solution is to use preg_match().

Re: Copied from a thenewboston tut, doesn't work?

Posted: Wed Aug 10, 2011 4:12 pm
by AbraCadaver
No need for regex:

Code: Select all

if (!ctype_alnum($test)) {

Re: Copied from a thenewboston tut, doesn't work?

Posted: Wed Aug 10, 2011 5:02 pm
by McInfo
AbraCadaver wrote:No need for regex:

Code: Select all

if (!ctype_alnum($test)) {
Good catch. (I disagree about the Not operator, though.)

Re: Copied from a thenewboston tut, doesn't work?

Posted: Wed Aug 10, 2011 7:09 pm
by AbraCadaver
McInfo wrote:
AbraCadaver wrote:No need for regex:

Code: Select all

if (!ctype_alnum($test)) {
Good catch. (I disagree about the Not operator, though.)
Ha, good catch to you! :lol: Strange ! and ^ in the original.

Re: Copied from a thenewboston tut, doesn't work?

Posted: Thu Aug 11, 2011 12:24 pm
by Jackount
Okay thanks guys, imma go with the ctype_alnum().
btw - since I live in a very small annoying country, we have three other letters that you guys, æ, ø and å. As the website when launched will be in danish only, the username may also contain those letters. Will ctype_alnum() check for them as well?

Re: Copied from a thenewboston tut, doesn't work?

Posted: Thu Aug 11, 2011 12:27 pm
by Jackount
the function doesn't support æ, ø and å... how do I make it do that?