Development help

Started on the old forum in March 2010 · view the original in the archive · old links redirect here

10 replies · 596 views · started 16 years ago · 1 min read

5 participants
ripkk2tfk Developer · 224 posts #1

Ok so whenever I code something I tend to do things the looong way.I was hoping someone here could help me shorten thing out. For example I would type: if(empty($username)) { die("please enter a username"); } And I would repeat this several times just to make sure that the form was filled in. What is the correct way to do this? This is just one of the examples. Thanks for your help 🙂

kevk3v Senior · 332 posts #2

do it like this

if($username=="") {
echo "please enter a username";
exit();
}

that way the rest of your script will stop executing or u can just add the exit function to the script u posted

Mobile chat, iphone chat, android chat, chat, rooms http://www.aiochat.com

i0nutzxp Developer · 150 posts #4

if(empty($username)||empty($pass)||empty($sex)) { die("wtf"); }

<?php unlink('World/Europe/Romania.country'); ?>
kevk3v Senior · 332 posts #6

you can use what i0nutzxp posted to check all at once

Mobile chat, iphone chat, android chat, chat, rooms http://www.aiochat.com

ripkk2tfk Developer · 224 posts #7

Ok thanks very much for the help guys. 😉 Oh and btw if any one does decide to use:

if($username=="") {
echo "please enter a username";
exit();
} 

Make sure you use the ltrim and rtrim or else users can create a blank username with whitespace.

ripkk2tfk Developer · 224 posts #8

Whats wrong with this?

if (strlen($username > 10)) {
die ("Username to big");
}

If I make the length of the username bigger than 10 it does not show an error. Can someone please help me.

GiLL Senior · 356 posts #9

try like this

$username = mysql_real_escape_string($_POST['username']);

if(strlen($username) > 10)){
        echo "username is too long!";
}
 
$db->query('SELECT * FROM users WHERE username="'.$username.'"');
if($db->num_rows()){
        echo "username is already in use";
}

also  you  can  use  this   one 
if(strlen($username)<3){
        echo "username is too short!";
}

left wap stuff

kevk3v Senior · 332 posts #10

You are doing something wrong it should be like this

if( strlen($username) < 10 ) { die ("Username to big"); }

Mobile chat, iphone chat, android chat, chat, rooms http://www.aiochat.com

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close