php script

Status
Not open for further replies.

jay_bo

Daemon Poster
Messages
889
what is wrong with this part of the script......


if($_POST['submit']){

}


_POST['username'] = trim($_POST['username']);
if($_POST['username'] && strlen($_POST['username']) >= 3){
$query = mysql_query(”SELECT `id` FROM `users` WHERE `username`='”.$_POST['username'].”‘ LIMIT 1″);
if(mysql_num_rows($query)){
$error['userexists'] = ‘Username exists';
}
} else {
$error['usernameinput'] = ‘Please enter a username of 3+ characters';
}





i do have the <?php and <? in but it wont save something about encodings arent ryt and utf-8, it only does this when i add this in.
 
Try this:

PHP:
if(isset ($_POST['submit'])){

}


$_POST['username'] = trim($_POST['username']);
if($_POST['username'] && strlen($_POST['username']) >= 3){
$query = mysql_query(”SELECT id FROM users WHERE username='{$_POST['username']}' LIMIT 1″);
if(mysql_num_rows($query)){
$error['userexists'] = 'Username exists';
}
} else {
$error['usernameinput'] = 'Please enter a username of 3+ characters';
}

First, at the top, you want to use the isset() function to see if the submit button was pressed, and then you can execute the rest of the script.

Another thing I saw was you had _POST['username'] when it should have been $_POST['username']. Then a few syntax errors in the query, etc.

I recommend getting a good script editing program so that you can see errors and whatnot. I use Editplus 2, works quite well and it's free.
 
i have a problem with this whihc i want to add after and it still anit right the other test.

if($_POST['submit']){

}

_POST['username'] = trim($_POST['username']);
if($_POST['username'] && strlen($_POST['username']) >= 3){
$query = mysql_query(”SELECT `id` FROM `users` WHERE `username`='”.$_POST['username'].”‘ LIMIT 1″);
if(mysql_num_rows($query)){
$error['userexists'] = ‘Username exists';
}
} else {
$error['usernameinput'] = ‘Please enter a username of 3+ characters';
}


_POST['email'] = trim($_POST['email']);
if($_POST['email']){
if(!eregi(”^[a-zA-Z0-9]+[a-zA-Z0-9_.-]*@[a-zA-Z0-9]+[a-zA-Z0-9_.-])*\.[a-z]{2,4}$”, $_POST['email'])){
$error['emailerror'] = ‘Email Incorrect';
}
} else {
$error['emailinput'] = ‘Please supply an email address';
}
if($_POST['password1'] && $_POST['password2']){
if($_POST['password1'] != $_POST['password2']){
$error['passmismatch'] = ‘Passwords don\'t match';
}
} else {
$error['passwordinput'] = ‘Please enter your password in both fields';
}
if(!$error && $_POST['submit']){

$query = mysql_query(”INSERT INTO `users` (username, email, password) VALUES ('”.$_POST['username'].”‘, ‘”.$_POST['email'].”‘, ‘”.md5($_POST['password1']).”‘)”);
if($query){
echo $_POST['username'].' is now registered';

} else {
 
What is the error exactly?

No offense, but that script is pretty sloppy and poorly made. I recommend reading some tutorials for PHP and re-writing it, using comments for clarification. That way when you have errors it's easier to read, easier to interpret, and easier to solve the problems.
 
oryt i did use a tutorial the only problem is now tht the errors keeping appearing at the last line now even when i get rid of the last line it carries on
 
if($_POST['submit']){

$_POST['username'] = trim($_POST['username']);
if($_POST['username'] && strlen($_POST['username']) >= 3){
$query = mysql_query("SELECT 'id' FROM 'users' WHERE 'username'='".$_POST['username']."' LIMIT 1");
if(mysql_num_rows($query)){
$error['userexists'] = 'Username exists';
}
} else {
$error['usernameinput'] = 'Please enter a username of 3 or more characters';
}
$_POST['email'] = trim($_POST['email']);
if($_POST['email']){
if(!eregi("^[a-zA-Z0-9]+[a-zA-Z0-9_.-]*@[a-zA-Z0-9]+[a-zA-Z0-9_.-])*\.[a-z]{2,4}$", $_POST['email'])){
$error['emailerror'] = 'Email Incorrect';
}
} else {
$error['emailinput'] = 'Please supply an email address';
}
if($_POST['password1'] && $_POST['password2']){
if($_POST['password1'] != $_POST['password2']){
$error['passmismatch'] = 'Passwords don\'t match';
}
} else {
$error['passwordinput'] = 'Please enter your password in both fields';
}
if(!$error && $_POST['submit']){
$query = mysql_query("INSERT INTO 'users' (username, email, password) VALUES ('".$_POST['username']."', '".$_POST['email']."', '".md5($_POST['password1'])."')");
if($query){
echo $_POST['username'].'is now registered';
} else {


the top line seems 2 be the prob
 
doesnt matter i have worked it out, i have manged to create a register and login form and an email 1 but having problem config the httpd.conf
 
Instead of
if ($_POST['submit'])
you could use
if($_SERVER['REQUEST_METHOD'] == 'POST')
although both should work.

What's wrong with the httpd.conf?

Also just for reference, it would be handy (for future questions) if you provided the error that PHP spit out too, as it's usually specific to the problem, just not the exact location. :)
 
when people register, they get an email sent to them except apache need to be set up right(httpd.conf) but i cant do it lol i ahve tired.the username ad password do work correct and they are in the database but they dont get sent
 
Status
Not open for further replies.
Back
Top Bottom