Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Closed Thread
Old 06-29-2007, 11:17 AM   #1 (permalink)
jay_bo's Avatar
 
Ultra Techie

Join Date: Jul 2006

Posts: 898

jay_bo is on a distinguished road

Exclamation php script

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.
jay_bo is offline  
Old 06-29-2007, 04:48 PM   #2 (permalink)
CrazeD's Avatar
 
Wizard Techie

Join Date: Feb 2006

Location: Maine

Posts: 3,683

CrazeD will become famous soon enough

Send a message via AIM to CrazeD Send a message via MSN to CrazeD
Default Re: php script

Try this:

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

}


$_POST['username'] = trim($_POST['username']);
if(
$_POST['username'] && strlen($_POST['username']) >= 3){
$query mysql_query(&#8221;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.
__________________

Need website help? PM me!
CrazeD is offline  
Old 06-30-2007, 12:51 PM   #3 (permalink)
jay_bo's Avatar
 
Ultra Techie

Join Date: Jul 2006

Posts: 898

jay_bo is on a distinguished road

Default Re: php script

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 {

Last edited by jay_bo; 06-30-2007 at 01:08 PM.
jay_bo is offline  
Old 06-30-2007, 08:05 PM   #4 (permalink)
CrazeD's Avatar
 
Wizard Techie

Join Date: Feb 2006

Location: Maine

Posts: 3,683

CrazeD will become famous soon enough

Send a message via AIM to CrazeD Send a message via MSN to CrazeD
Default Re: php script

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

Need website help? PM me!
CrazeD is offline  
Old 07-01-2007, 06:54 AM   #5 (permalink)
jay_bo's Avatar
 
Ultra Techie

Join Date: Jul 2006

Posts: 898

jay_bo is on a distinguished road

Default Re: php script

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
jay_bo is offline  
Old 07-01-2007, 07:45 AM   #6 (permalink)
jay_bo's Avatar
 
Ultra Techie

Join Date: Jul 2006

Posts: 898

jay_bo is on a distinguished road

Default Re: php 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 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
jay_bo is offline  
Old 07-02-2007, 07:47 AM   #7 (permalink)
jay_bo's Avatar
 
Ultra Techie

Join Date: Jul 2006

Posts: 898

jay_bo is on a distinguished road

Default Re: php script

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
jay_bo is offline  
Old 07-02-2007, 05:06 PM   #8 (permalink)
 
Monster Techie

Join Date: May 2004

Location: Tucson, AZ, USA

Posts: 1,183

Vormund

Send a message via AIM to Vormund Send a message via MSN to Vormund Send a message via Yahoo to Vormund
Default Re: php script

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.
__________________
Vormund is offline  
Old 07-03-2007, 07:02 AM   #9 (permalink)
jay_bo's Avatar
 
Ultra Techie

Join Date: Jul 2006

Posts: 898

jay_bo is on a distinguished road

Default Re: php script

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
jay_bo is offline  
Old 07-03-2007, 11:59 AM   #10 (permalink)
 
Monster Techie

Join Date: May 2004

Location: Tucson, AZ, USA

Posts: 1,183

Vormund

Send a message via AIM to Vormund Send a message via MSN to Vormund Send a message via Yahoo to Vormund
Default Re: php script

Username and password to what? This here, PHPMailer is an excellent overall mail handler, if you're into playing with stuff for a bit.
__________________
Vormund is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
New Site Project - Flash + PHP + MySQL + CSS theone_trent Web Graphics, Design, Digital Images 2 06-30-2007 01:12 PM
Need a good captcha generating php script surut Windows Operating Systems and Software 1 05-26-2007 09:23 AM
PHP captcha script needed iorgus Programming Discussions 2 05-20-2007 01:33 PM
PHP 2-player game? thejeremy Programming Discussions 4 04-09-2007 06:01 PM
Remote file access w/ IP + PHP? thejeremy Programming Discussions 2 04-04-2007 05:24 PM