• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 13:15
CET 19:15
KST 03:15
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10[ASL20] Finals Preview: Arrival13
Community News
[TLMC] Fall/Winter 2025 Ladder Map Rotation12Weekly Cups (Nov 3-9): Clem Conquers in Canada4SC: Evo Complete - Ranked Ladder OPEN ALPHA8StarCraft, SC2, HotS, WC3, Returning to Blizzcon!45$5,000+ WardiTV 2025 Championship7
StarCraft 2
General
Mech is the composition that needs teleportation t RotterdaM "Serral is the GOAT, and it's not close" RSL Season 3 - RO16 Groups C & D Preview [TLMC] Fall/Winter 2025 Ladder Map Rotation TL.net Map Contest #21: Winners
Tourneys
RSL Revival: Season 3 Sparkling Tuna Cup - Weekly Open Tournament Constellation Cup - Main Event - Stellar Fest Tenacious Turtle Tussle Master Swan Open (Global Bronze-Master 2)
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 499 Chilling Adaptation Mutation # 498 Wheel of Misfortune|Cradle of Death Mutation # 497 Battle Haredened Mutation # 496 Endless Infection
Brood War
General
FlaSh on: Biggest Problem With SnOw's Playstyle What happened to TvZ on Retro? SnOw's ASL S20 Finals Review BW General Discussion Brood War web app to calculate unit interactions
Tourneys
[Megathread] Daily Proleagues Small VOD Thread 2.0 [BSL21] RO32 Group D - Sunday 21:00 CET [BSL21] RO32 Group C - Saturday 21:00 CET
Strategy
PvZ map balance Current Meta Simple Questions, Simple Answers How to stay on top of macro?
Other Games
General Games
Path of Exile Stormgate/Frost Giant Megathread Nintendo Switch Thread Clair Obscur - Expedition 33 Beyond All Reason
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread SPIRED by.ASL Mafia {211640}
Community
General
Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread US Politics Mega-thread Artificial Intelligence Thread Canadian Politics Mega-thread
Fan Clubs
White-Ra Fan Club The herO Fan Club!
Media & Entertainment
Movie Discussion! [Manga] One Piece Anime Discussion Thread Korean Music Discussion Series you have seen recently...
Sports
2024 - 2026 Football Thread Formula 1 Discussion NBA General Discussion MLB/Baseball 2023 TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
Dyadica Gospel – a Pulp No…
Hildegard
Coffee x Performance in Espo…
TrAiDoS
Saturation point
Uldridge
DnB/metal remix FFO Mick Go…
ImbaTosS
Reality "theory" prov…
perfectspheres
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2038 users

The Big Programming Thread - Page 107

Forum Index > General Forum
Post a Reply
Prev 1 105 106 107 108 109 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
Millitron
Profile Blog Joined August 2010
United States2611 Posts
Last Edited: 2012-01-15 23:07:36
January 15 2012 23:00 GMT
#2121
On January 14 2012 06:00 billy5000 wrote:
programming nub w/ a question lol

so in java i figured out how to make a simple program that finds the distance between two points on a regular x y plane. however, the first time i tried it, the answer didn't come out right but when i just tweaked the formula, it's right.

1st method whose answer is off:
double x = Double.parseDouble(args[0]);
double y = Double.parseDouble(args[1]);

double a = Double.parseDouble(args[2]);
double b = Double.parseDouble(args[3]);

double Dformula = Math.sqrt(Math.pow((b-y), 2) + Math.pow((a-x), 2));

2nd method whose answer is correct:

double x = Double.parseDouble(args[0]);
double y = Double.parseDouble(args[1]);

double a = Double.parseDouble(args[2]);
double b = Double.parseDouble(args[3]);

double Dformula = Math.sqrt((b-y)*(b-y) + (a-x)*(a-x));

Why does the second method work, but the first one doesn't?

I just remembered, I have a 2nd question..why does System.out.print('b' + 'c'); produce a number?

First, next time put code in spoilers with proper indentation, its tough to read otherwise.

When you say that the first method doesn't give the correct answer, is it off by a tiny bit, or a huge amount?

Either way, I would try the first way with more careful use of parenthesis, like so.

double Dformula = Math.sqrt((Math.pow((b-y), 2)) + (Math.pow((a-x), 2)));

I'm not making any guarantees that this will work, but its worth a shot.



As for your second question, chars are stored as integers, according to UNICODE or some other character encoding. So Java defines 'b' + 'c' as 97 + 98 (in unicode anyways, exact numbers will be different in other encodings). You can get it to print a char like so:

System.out.print((char)('b' + 'c');

It should print whatever unicode 195 is.

On January 14 2012 06:21 billy5000 wrote:
3rd question:

trying to make a program that verifies cos squared + sin squared = 1

double a = Double.parseDouble(args[0]);
double b = Double.parseDouble(args[1]);

double cos = Math.cos(a);
double sin = Math.sin(b);

double formula = Math.pow(cos, 2) + Math.pow(sin, 2);

System.out.print(formula);

Why isn't the answer exactly 1? this exercise even asks you why it isn't exactly 1. Also, how would you do this to make it always equal to 1?

The answer will not be exactly 1 because floats and doubles are not perfectly precise. They are VERY accurate, but not PERFECTLY accurate, so any answers produced with them either needs to use some rounding, or just accept the fact that a few of the right-most digits will be garbage.
Who called in the fleet?
marconi
Profile Joined March 2010
Croatia220 Posts
January 15 2012 23:23 GMT
#2122
Hey guys I'm searching for someone in the IT business for a short interview for my college project. If anyone's interested plz pm me so we can work something over skype or bnet
LunaSea
Profile Joined October 2011
Luxembourg369 Posts
Last Edited: 2012-01-16 02:38:14
January 16 2012 02:18 GMT
#2123
Just wanted to correct the OP when he's saying in his reply to an email that Ruby is a "Web Language".

Actually it isn't !
Ruby is a lot like Python, so more software based BUT if you talk about "Ruby on Rails" which is a framework, then yes it's also a "Web Framework" !
"Your f*cking wrong, but I respect your opinion" --Day[9]
NoSlack
Profile Joined November 2010
United States112 Posts
January 17 2012 04:20 GMT
#2124
Hey guys. I'm new to PHP, just wondering why this is happening. This form is a registration form. There is no MySQL code in it yet. I am just trying to validate the data properly and then I will struggle through the db code. I'm self taught with a few books, and I'm sure there are better ways to do this, but let's keep it simple please . Also I'm sure the regular expressions aren't right either, I didn't read much about them yet.

Question: When I submit the form blank, why does the post password and post email if statements evaluate to true yet every other post related conditional evaluates to false? This is saying that $_POST['password'] and $_POST['email'] are set, but they should not be from what I can tell. Thanks for helping me understand!

+ Show Spoiler +

<?php

require_once 'header.php';
require_once 'code.php';

$username = $password = $confpassword = $email = $confemail = $error = '';

if (isset($_SESSION['user']))
session_destroy();

if (isset($_POST['username'])) {
$username = sanstring($_POST['username']);
if (preg_match('/[^A-Za-z0-9_]/', $username)){
$error .= '<br />Invalid username. Usernames consist of the following letters: A-Z, a-z, 0-9 and underscore (_).';
}
}
if (isset($_POST['password'])) {
$password = sanstring($_POST['password']);
if (!preg_match('/[A-Za-z0-9!@#$%^&*_]/', $password)) {
$error .= '<br />Invalid password. Password must consist of the following characters: A-Z, a-z, 0-9, and !@#$%^&*_';
}
}
if (isset($_POST['password'])) {
$confpassword = sanstring($_POST['confpassword']);
if (!strcmp($password, $confpassword) == 0){
$error .= '<br />Your password confirmation does not match.';
}
}
if (isset($_POST['email'])) {
$email = sanstring($_POST['email']);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)){
$error .= '<br />The email address you entered is not valid.';
}
}
if (isset($_POST['confemail'])) {
$confemail = sanstring($_POST['confemail']);
if (!$email == $confemail){
$error .= '<br />The email confirmation does not match.';
}
}

if ($error) echo $error;

if (!$username) {
echo <<< _END
<div>
<form action="register.php" method="post">
Desired Username: <input type="text" maxlength="16" name="username" /><br />
Desired Password: <input type="password" maxlength="16" name="password" /><br />
Confirm Password: <input type="password" maxlength="16" name="confpassword" /><br />
Email Address: <input type="text" name="email" /><br />
Confirm Email: <input type="text" name="confemail" /><br />
<input type="submit" value="Submit" />
</form>
</div>
_END;
}


/*
* TODO:
* Add check to $username to make sure it's a-z, A-Z, 0-9, _ only.
* Check password to ensure it is 6-12 character long with at least one number and one letter
* Check confpassword to make sure it matches the password
* Check email to make sure it is in a valid format
* Check confemail to make sure it matches email
*
*/
?>

Alvin853
Profile Joined December 2011
Germany149 Posts
January 17 2012 07:28 GMT
#2125
On January 17 2012 13:20 NoSlack wrote:
Hey guys. I'm new to PHP, just wondering why this is happening. This form is a registration form. There is no MySQL code in it yet. I am just trying to validate the data properly and then I will struggle through the db code. I'm self taught with a few books, and I'm sure there are better ways to do this, but let's keep it simple please . Also I'm sure the regular expressions aren't right either, I didn't read much about them yet.

Question: When I submit the form blank, why does the post password and post email if statements evaluate to true yet every other post related conditional evaluates to false? This is saying that $_POST['password'] and $_POST['email'] are set, but they should not be from what I can tell. Thanks for helping me understand!

+ Show Spoiler +

<?php

require_once 'header.php';
require_once 'code.php';

$username = $password = $confpassword = $email = $confemail = $error = '';

if (isset($_SESSION['user']))
session_destroy();

if (isset($_POST['username'])) {
$username = sanstring($_POST['username']);
if (preg_match('/[^A-Za-z0-9_]/', $username)){
$error .= '<br />Invalid username. Usernames consist of the following letters: A-Z, a-z, 0-9 and underscore (_).';
}
}
if (isset($_POST['password'])) {
$password = sanstring($_POST['password']);
if (!preg_match('/[A-Za-z0-9!@#$%^&*_]/', $password)) {
$error .= '<br />Invalid password. Password must consist of the following characters: A-Z, a-z, 0-9, and !@#$%^&*_';
}
}
if (isset($_POST['password'])) {
$confpassword = sanstring($_POST['confpassword']);
if (!strcmp($password, $confpassword) == 0){
$error .= '<br />Your password confirmation does not match.';
}
}
if (isset($_POST['email'])) {
$email = sanstring($_POST['email']);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)){
$error .= '<br />The email address you entered is not valid.';
}
}
if (isset($_POST['confemail'])) {
$confemail = sanstring($_POST['confemail']);
if (!$email == $confemail){
$error .= '<br />The email confirmation does not match.';
}
}

if ($error) echo $error;

if (!$username) {
echo <<< _END
<div>
<form action="register.php" method="post">
Desired Username: <input type="text" maxlength="16" name="username" /><br />
Desired Password: <input type="password" maxlength="16" name="password" /><br />
Confirm Password: <input type="password" maxlength="16" name="confpassword" /><br />
Email Address: <input type="text" name="email" /><br />
Confirm Email: <input type="text" name="confemail" /><br />
<input type="submit" value="Submit" />
</form>
</div>
_END;
}


/*
* TODO:
* Add check to $username to make sure it's a-z, A-Z, 0-9, _ only.
* Check password to ensure it is 6-12 character long with at least one number and one letter
* Check confpassword to make sure it matches the password
* Check email to make sure it is in a valid format
* Check confemail to make sure it matches email
*
*/
?>



actually all your isset($_POST[]) statements evaluate to true, because all of these are set to empty string, but only your password and email conditionals check whether there are certain characters in the string and therefor return an error message.
DMTsyncope
Profile Joined March 2011
Netherlands46 Posts
Last Edited: 2012-01-17 12:22:07
January 17 2012 12:07 GMT
#2126
Hey TL!

I was wondering if there is anyone around here that could help me with some Actionscript 3.0 in flash.

Im making a simple game where to the player has to click away bombs before they destroy the city. (I know, its really original).
This is the first game im building on my own from the ground up, but im stuck.

+ Show Spoiler +

This is the function used for the spawning of the bombs:

public function SpawnBombs(Bombs:Number) {
for (var i=0;i<Bombs;i++) {
var Bomb:bomb = new bomb;
var score = i;
stage.addChild(Bomb);
Bomb.addEventListener(MouseEvent.CLICK, function(){
currentScore++;
scoreScreen.text = currentScore.toString();
startGameLoop(score);
});
}
}


I wrote the class called Bomb myself, that class contains the spawning position and the movementspeed.

But what i want to do, is to create a variable (a number) which keeps track of the amount of Bombs that have reached 940 px or more in the y axis. For instance:

+ Show Spoiler +

public var BombsonGround:Number = 0;

Bomb.addEventListener(Event.ENTER_FRAME, checkPosition);

public function checkPosition(event:Event) {
if (Bomb.y >= 940) {
BombsonGround++;
}
}


But the problem with this is, that if a bomb goes over 940px on the y axis, it will keep looping the IF loop and it will keep adding more and more to my BombsonGround value.


I hope i explained my problem well enough for people to understand, if anyone has any clue/idea/suggestion for this problem, please let me know!

Thanks in advance,

Syncope!
Proflo
Profile Blog Joined October 2010
United States148 Posts
January 17 2012 13:02 GMT
#2127
On January 16 2012 11:18 LunaSea wrote:
Just wanted to correct the OP when he's saying in his reply to an email that Ruby is a "Web Language".

Actually it isn't !
Ruby is a lot like Python, so more software based BUT if you talk about "Ruby on Rails" which is a framework, then yes it's also a "Web Framework" !


Noone is gonna talk about ruby and NOT be talking about ruby on rails.... The web framework is about the only reason to code in ruby.
Happiness in intelligent people is the rarest thing I know.
tofucake
Profile Blog Joined October 2009
Hyrule19152 Posts
January 17 2012 15:14 GMT
#2128
On January 17 2012 13:20 NoSlack wrote:
Hey guys. I'm new to PHP, just wondering why this is happening. This form is a registration form. There is no MySQL code in it yet. I am just trying to validate the data properly and then I will struggle through the db code. I'm self taught with a few books, and I'm sure there are better ways to do this, but let's keep it simple please . Also I'm sure the regular expressions aren't right either, I didn't read much about them yet.

Question: When I submit the form blank, why does the post password and post email if statements evaluate to true yet every other post related conditional evaluates to false? This is saying that $_POST['password'] and $_POST['email'] are set, but they should not be from what I can tell. Thanks for helping me understand!

+ Show Spoiler +

<?php

require_once 'header.php';
require_once 'code.php';

$username = $password = $confpassword = $email = $confemail = $error = '';

if (isset($_SESSION['user'])
session_destroy();

if (isset($_POST['username']) {
$username = sanstring($_POST['username'];
if (preg_match('/[^A-Za-z0-9_]/', $username)){
$error .= '<br />Invalid username. Usernames consist of the following letters: A-Z, a-z, 0-9 and underscore (_).';
}
}
if (isset($_POST['password']) {
$password = sanstring($_POST['password'];
if (!preg_match('/[A-Za-z0-9!@#$%^&*_]/', $password)) {
$error .= '<br />Invalid password. Password must consist of the following characters: A-Z, a-z, 0-9, and !@#$%^&*_';
}
}
if (isset($_POST['password']) {
$confpassword = sanstring($_POST['confpassword'];
if (!strcmp($password, $confpassword) == 0){
$error .= '<br />Your password confirmation does not match.';
}
}
if (isset($_POST['email']) {
$email = sanstring($_POST['email'];
if (!filter_var($email, FILTER_VALIDATE_EMAIL)){
$error .= '<br />The email address you entered is not valid.';
}
}
if (isset($_POST['confemail']) {
$confemail = sanstring($_POST['confemail'];
if (!$email == $confemail){
$error .= '<br />The email confirmation does not match.';
}
}

if ($error) echo $error;

if (!$username) {
echo <<< _END
<div>
<form action="register.php" method="post">
Desired Username: <input type="text" maxlength="16" name="username" /><br />
Desired Password: <input type="password" maxlength="16" name="password" /><br />
Confirm Password: <input type="password" maxlength="16" name="confpassword" /><br />
Email Address: <input type="text" name="email" /><br />
Confirm Email: <input type="text" name="confemail" /><br />
<input type="submit" value="Submit" />
</form>
</div>
_END;
}


/*
* TODO:
* Add check to $username to make sure it's a-z, A-Z, 0-9, _ only.
* Check password to ensure it is 6-12 character long with at least one number and one letter
* Check confpassword to make sure it matches the password
* Check email to make sure it is in a valid format
* Check confemail to make sure it matches email
*
*/
?>



Use isset($_POST['submit']) on whatever you named your submit button to check if the form was submitted. If not, do whatever. If it was, use empty($_POST['username']) etc to check for data.
Liquipediaasante sana squash banana
NoSlack
Profile Joined November 2010
United States112 Posts
January 17 2012 16:36 GMT
#2129
On January 17 2012 16:28 Alvin853 wrote:
Show nested quote +
On January 17 2012 13:20 NoSlack wrote:
Hey guys. I'm new to PHP, just wondering why this is happening. This form is a registration form. There is no MySQL code in it yet. I am just trying to validate the data properly and then I will struggle through the db code. I'm self taught with a few books, and I'm sure there are better ways to do this, but let's keep it simple please . Also I'm sure the regular expressions aren't right either, I didn't read much about them yet.

Question: When I submit the form blank, why does the post password and post email if statements evaluate to true yet every other post related conditional evaluates to false? This is saying that $_POST['password'] and $_POST['email'] are set, but they should not be from what I can tell. Thanks for helping me understand!

+ Show Spoiler +

<?php

require_once 'header.php';
require_once 'code.php';

$username = $password = $confpassword = $email = $confemail = $error = '';

if (isset($_SESSION['user']))
session_destroy();

if (isset($_POST['username'])) {
$username = sanstring($_POST['username']);
if (preg_match('/[^A-Za-z0-9_]/', $username)){
$error .= '<br />Invalid username. Usernames consist of the following letters: A-Z, a-z, 0-9 and underscore (_).';
}
}
if (isset($_POST['password'])) {
$password = sanstring($_POST['password']);
if (!preg_match('/[A-Za-z0-9!@#$%^&*_]/', $password)) {
$error .= '<br />Invalid password. Password must consist of the following characters: A-Z, a-z, 0-9, and !@#$%^&*_';
}
}
if (isset($_POST['password'])) {
$confpassword = sanstring($_POST['confpassword']);
if (!strcmp($password, $confpassword) == 0){
$error .= '<br />Your password confirmation does not match.';
}
}
if (isset($_POST['email'])) {
$email = sanstring($_POST['email']);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)){
$error .= '<br />The email address you entered is not valid.';
}
}
if (isset($_POST['confemail'])) {
$confemail = sanstring($_POST['confemail']);
if (!$email == $confemail){
$error .= '<br />The email confirmation does not match.';
}
}

if ($error) echo $error;

if (!$username) {
echo <<< _END
<div>
<form action="register.php" method="post">
Desired Username: <input type="text" maxlength="16" name="username" /><br />
Desired Password: <input type="password" maxlength="16" name="password" /><br />
Confirm Password: <input type="password" maxlength="16" name="confpassword" /><br />
Email Address: <input type="text" name="email" /><br />
Confirm Email: <input type="text" name="confemail" /><br />
<input type="submit" value="Submit" />
</form>
</div>
_END;
}


/*
* TODO:
* Add check to $username to make sure it's a-z, A-Z, 0-9, _ only.
* Check password to ensure it is 6-12 character long with at least one number and one letter
* Check confpassword to make sure it matches the password
* Check email to make sure it is in a valid format
* Check confemail to make sure it matches email
*
*/
?>



actually all your isset($_POST[]) statements evaluate to true, because all of these are set to empty string, but only your password and email conditionals check whether there are certain characters in the string and therefor return an error message.


The other if statements don't run. I checked it with debugger, stepping through it all, and these two run while the others don't. I'll use the $_POST['submit'] method that tofu suggested, and it'll take less steps to load the page initially so that's good. I'm still wondering why this is though, for learning purposes if anybody knows. They are all set to empty strings when you press submit (without entering any data) but the If statements don't run on some and do on email and password.
ArmyyStrongg
Profile Joined September 2010
United States39 Posts
January 17 2012 19:39 GMT
#2130
On January 09 2012 05:16 Jaso wrote:
Question:

I'm currently learning C using Harvard's cs50.net course; it's extremely helpful.
However, as a sophomore in high school right now, I'm also hoping to take the AP Computer Science test before I apply for college which gives me about a year and some to teach myself AP-level Java. Unfortunately, my school does not offer APCS because it is small .

Does anyone have any recommendations? Should I get a strong foundation before moving to Java (even though I know it's more like obj-c), should I just buy an APCS book and jump in, or something else..?

Thanks!


Continue doing what your doing because no matter what it will help you in the long run. I know what your talking about and if I were I would continue using the Harvard course but also get you a APCS book, and look over it till either you finish the Harvard course of you think you have enough knowledge that you can move into the APCS book.

Also make sure that you take practice test so you dont take the test blind. Knowing what to expect will really help you.
cheat till you win
LunaSea
Profile Joined October 2011
Luxembourg369 Posts
January 17 2012 20:12 GMT
#2131
On January 17 2012 22:02 Proflo wrote:
Show nested quote +
On January 16 2012 11:18 LunaSea wrote:
Just wanted to correct the OP when he's saying in his reply to an email that Ruby is a "Web Language".

Actually it isn't !
Ruby is a lot like Python, so more software based BUT if you talk about "Ruby on Rails" which is a framework, then yes it's also a "Web Framework" !


Noone is gonna talk about ruby and NOT be talking about ruby on rails.... The web framework is about the only reason to code in ruby.


That's absolutely not true !
For example, the computer security framework (non-web) refference, Metasploit, is coded in Ruby and not with the Rails framework .
"Your f*cking wrong, but I respect your opinion" --Day[9]
NoSlack
Profile Joined November 2010
United States112 Posts
Last Edited: 2012-01-18 05:49:18
January 17 2012 21:08 GMT
#2132
Ok here's my new code. Is it better? Basically I added a name of 'submit' to the submit button and nested all the error checking inside the if ($_POST['submit']) statement. What should I do to improve it before adding database code? For those that didn't see my above post this is PHP and it is a website registration page. Thus far the intent is to validate the user input. The other functions called are kept in a code behind, and all it does is sanitize the strings so I can't get injected (I think anyway).

After much reading and web surfing, I cannot for the life of me find an article that agrees on how to check for a valid email address. Are these people just nitpicking at the articles for the lulz? Should I just find something that checks to see if it has an @ symbol and a (dot) something at the end?

+ Show Spoiler +



<?php

require_once 'header.php';
require_once 'code.php';

if (isset($_POST['submit'])) {
$error = $username = $password = $confpassword = $email = $confemail = "";
if ($_POST['username']) {
$username = sanstring($_POST['username']);
if (strlen($username) > 12) $error .= '<div>The username you entered is too long. Username must be 6 to 12 characters.</div>';
if (strlen($username) < 6) $error .= '<div>The username you entered is too short. Username must be 6 to 12 characters.</div>';
if (preg_match('/[^a-z0-9_]/', $username)) $error .= '<div>The username you entered contains invalid characters. Username may contain A-Z, a-z, 0-9, and _.</div>';
} else {
$error .= '<div>You did not enter a username. Please try again.</div>';
}if ($_POST['password']) {
$password = sanstring($_POST['password']);
if (strlen($password) > 12) $error .= '<div>The password you entered is too long. Password must be 6 to 12 characters.</div>';
if (strlen($password) < 6) $error .= '<div>The password you entered is too short. Password must be 6 to 12 characters.</div>';
if (preg_match('/[^a-z0-9]i/', $password)) $error .= '<div>The password you entered contains invalid characters. Password may contain A-Z, a-z, 0-9, and !@#$%^&*()</div>';
} else {
$error .= '<div>You did not enter a password. Please try again.</div>';
}if ($_POST['confpassword']) {
$confpassword = sanstring($_POST['confpassword']);
if (strcmp($password, $confpassword)) $error .= '<div>The password confirmation does not match your password. Please try again.</div>';
} else {
$error .= '<div>You did not enter your password confirmation. Please try again.</div>';
}
if ($_POST['email']) {
$email = sanstring($_POST['email']);
} else {
$error .= '<div>You did not enter your email address. Please try again.</div>';
}if ($_POST['confemail']) {
$confemail = sanstring($_POST['confemail']);
if (strcasecmp($email, $confemail)) $error .= '<div>The email confirmation does not match your email. Please try again.</div>';
} else {
$error .= '<div>You did not enter your email confirmation. Please try again.</div>';
}
if ($error) {
echo $error;
}
} else {
echo <<< _END
<div>
<form action="register2.php" method="post">
Desired Username: <input type="text" maxlength="16" name="username" /><br />
Desired Password: <input type="password" maxlength="16" name="password" /><br />
Confirm Password: <input type="password" maxlength="16" name="confpassword" /><br />
Email Address: <input type="text" name="email" /><br />
Confirm Email: <input type="text" name="confemail" /><br />
<input name="submit" type="submit" value="Submit" />
</form>
</div>
_END;
}

/*
* TODO:
* Function to ensure username starts with a letter.
* Function to ensure password contains one letter and one number.
* Function to ensure email address is valid in text as well as lookup.
*
*/
?>


tec27
Profile Blog Joined June 2004
United States3702 Posts
January 18 2012 01:27 GMT
#2133
Can you use code tags or put it in a gist next time? Absolutely awful to read as is

Anyway, your code looks fine. For checking a valid email address, most people use regular expressions ( http://www.regular-expressions.info/email.html ).

As an improvement, you should try and separate your content as much as possible from your code. IE: instead of echoing your form, put it outside of the php tags as regular html. Instead of setting error to some html, set error to just the error string, or better yet, an array of error strings and put it in your html like so:

<?php
[ ... your validation code ... ]
?>
<? if(count($errors) > 0) { ?>

<ul class="error">
<? foreach($errors as $error) { ?>
<li><? echo $error; ?></li>
<? } ?>
</ul>

<? } ?>
Can you jam with the console cowboys in cyberspace?
guyabs
Profile Joined May 2010
Philippines103 Posts
January 18 2012 01:46 GMT
#2134
What do you guys prefer between VB.net and C#?
In terms of usefulness and can open more doors for job opportunities.
tec27
Profile Blog Joined June 2004
United States3702 Posts
January 18 2012 01:48 GMT
#2135
On January 18 2012 10:46 guyabs wrote:
What do you guys prefer between VB.net and C#?
In terms of usefulness and can open more doors for job opportunities.

C#, absolutely no question. You probably don't want to do any of the jobs that involve using VB.NET, and C# is a much, much better language.
Can you jam with the console cowboys in cyberspace?
Millitron
Profile Blog Joined August 2010
United States2611 Posts
January 18 2012 03:30 GMT
#2136
Speaking of VB, I had to use it last semester in my database management class.

It was not a good experience. The absolute worst part, was in Visual Basic for Access, it lets you use variables you haven't yet defined, unlike in pretty much any other language where the compiler would bitch at you. Instead of giving you an error, or crashing, it just ignores any statements with undefined variables.

Now, here's what happened to me. I had a major assignment, which was to build a program to allow users to access and use a database, while being restrictive enough that only valid data could be entered, and no data could be lost. I had done most of the work in other, shorter assignments already, the assignment was mostly just a lot of copy/pasting. Once I start testing it, I start seeing lots inexplicable errors. I even have the prof look at it; he suggests some fixes, and they help a little, but I still have tons of problems. 30 minutes before the assignment was due, I'm in panic mode, going over the code as carefully as I can, oh, and did I mention, this assignment was like, 20% of the final grade. Well, mere minutes before it needed to be handed in, I finally notice that when I copy/pasted everything, I missed the line:

Dim recCount as Integer

No line involving recCount was ever executing, and the compiler didn't think that was worth telling me........
Who called in the fleet?
NoSlack
Profile Joined November 2010
United States112 Posts
January 18 2012 05:03 GMT
#2137
On January 18 2012 10:27 tec27 wrote:
Can you use code tags or put it in a gist next time? Absolutely awful to read as is

Anyway, your code looks fine. For checking a valid email address, most people use regular expressions ( http://www.regular-expressions.info/email.html ).

As an improvement, you should try and separate your content as much as possible from your code. IE: instead of echoing your form, put it outside of the php tags as regular html. Instead of setting error to some html, set error to just the error string, or better yet, an array of error strings and put it in your html like so:

<?php
[ ... your validation code ... ]
?>
<? if(count($errors) > 0) { ?>

<ul class="error">
<? foreach($errors as $error) { ?>
<li><? echo $error; ?></li>
<? } ?>
</ul>

<? } ?>


Sorry I didn't know there was a code tag! I was looking for it but it's not a button and I didn't see it on the 'Smilies and BBCode' link either. I'll go edit my post now .

Thanks for the advice I'll definitely be doing this. This should make the code much easier to read. I have a very OOP mindset, having started with VB, C# mostly, but I haven't grasped the concept of how to apply this to the web. Really, I'd like to have the entire thing be a class, stored in a separate file (that the user can't get to) and just have it spit out the HTML to this php file. I feel like this is overkill though for a PHP page, the OOP (class, object, property, method) mentality doesn't seem to apply as easily yet for me. Does it for you when it comes to PHP? Maybe once my project gets more complicated it will? Also thanks for the link that's a good one to have for sure!

As for the C# vs VB debate, it seems like personal preference to me. I've read books on both of them and done a bunch of tutorials on both of them and they seem pretty much the same to me. Personally I liked VB 2010 more for Windows business type applications. It also made object oriented programming easier to see for me as it's using english instead of symbols. I'd say try them both and pick. I downloaded Visual Studio Express and just went to town on VB, C#, C++, and even ASP just to see which one I liked most.

Ended up on PHP... go figure.
enigmaticcam
Profile Blog Joined October 2010
United States280 Posts
Last Edited: 2012-01-18 17:53:43
January 18 2012 17:53 GMT
#2138
On January 18 2012 10:48 tec27 wrote:
Show nested quote +
On January 18 2012 10:46 guyabs wrote:
What do you guys prefer between VB.net and C#?
In terms of usefulness and can open more doors for job opportunities.

C#, absolutely no question. You probably don't want to do any of the jobs that involve using VB.NET, and C# is a much, much better language.

There is no difference between C# and VB.NET other than syntax. They will ultimately perform exactly the same. However, C# is the recommendation because: (1) there is an unfounded stigma that C# > VB.NET, hence most jobs are looking for the former, (2) C# background makes it easier to transition to other similar languages such as C and PHP.


On January 18 2012 12:30 Millitron wrote:
Speaking of VB, I had to use it last semester in my database management class.

It was not a good experience. The absolute worst part, was in Visual Basic for Access, it lets you use variables you haven't yet defined, unlike in pretty much any other language where the compiler would bitch at you. Instead of giving you an error, or crashing, it just ignores any statements with undefined variables.

OPTION EXPLICIT
Bigpet
Profile Joined July 2010
Germany533 Posts
Last Edited: 2012-01-18 18:12:14
January 18 2012 18:08 GMT
#2139
On January 18 2012 12:30 Millitron wrote:
Speaking of VB, I had to use it last semester in my database management class.

It was not a good experience. The absolute worst part, was in Visual Basic for Access, it lets you use variables you haven't yet defined, unlike in pretty much any other language where the compiler would bitch at you. Instead of giving you an error, or crashing, it just ignores any statements with undefined variables.


VBA != VB. Syntax may be similar but VBA is interpreted and therefore the compiler doesn't "bitch" because there is no compiler. There are plenty of scripting languages out there that assign default values to undeclared variables.

edit: vba is actually compiled into an intermediate language . But still it just behaves like a scripting language, nothing out of the ordinary.
I'm NOT the caster with a similar nick
Frigo
Profile Joined August 2009
Hungary1023 Posts
January 18 2012 19:09 GMT
#2140
Hey guys, any idea how to mock databases in CodeIgniter/PHP, or how to create a fast in-memory one?
http://www.fimfiction.net/user/Treasure_Chest
Prev 1 105 106 107 108 109 1032 Next
Please log in or register to reply.
Live Events Refresh
IPSL
17:00
Ro16 Group D
ZZZero vs rasowy
Napoleon vs KameZerg
Liquipedia
PSISTORM Gaming Misc
15:55
FSL teamleague CNvsASH, ASHvRR
Freeedom33
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Railgan 184
IndyStarCraft 110
BRAT_OK 47
MindelVK 29
EmSc Tv 13
StarCraft: Brood War
Britney 25290
Calm 2532
Shuttle 775
Stork 341
firebathero 288
Dewaltoss 113
Barracks 68
Mong 61
Rock 43
Shine 18
Dota 2
Gorgc5830
qojqva1713
Dendi963
Counter-Strike
ScreaM1084
byalli378
Heroes of the Storm
Khaldor535
Liquid`Hasu237
Other Games
Beastyqt573
DeMusliM291
Hui .222
Fuzer 215
Lowko213
Trikslyr46
CadenZie18
Organizations
Dota 2
PGL Dota 2 - Main Stream8971
Other Games
EGCTV625
gamesdonequick359
StarCraft 2
angryscii 24
EmSc Tv 13
EmSc2Tv 13
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 22 non-featured ]
StarCraft 2
• HappyZerGling 71
• HeavenSC 61
• printf 5
• LaughNgamezSOOP
• sooper7s
• AfreecaTV YouTube
• Migwel
• intothetv
• Kozan
• IndyKCrew
StarCraft: Brood War
• Airneanach42
• HerbMon 6
• Michael_bg 3
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• C_a_k_e 2455
• WagamamaTV359
• Ler79
League of Legends
• Nemesis2825
Other Games
• imaqtpie1125
• Shiphtur313
Upcoming Events
OSC
45m
davetesta15
BSL 21
1h 45m
Tarson vs Julia
Doodle vs OldBoy
eOnzErG vs WolFix
StRyKeR vs Aeternum
Sparkling Tuna Cup
15h 45m
RSL Revival
15h 45m
Reynor vs sOs
Maru vs Ryung
Kung Fu Cup
17h 45m
Cure vs herO
Reynor vs TBD
WardiTV Korean Royale
17h 45m
BSL 21
1d 1h
JDConan vs Semih
Dragon vs Dienmax
Tech vs NewOcean
TerrOr vs Artosis
IPSL
1d 1h
Dewalt vs WolFix
eOnzErG vs Bonyth
Replay Cast
1d 4h
Wardi Open
1d 17h
[ Show More ]
Monday Night Weeklies
1d 22h
WardiTV Korean Royale
2 days
BSL: GosuLeague
3 days
The PondCast
3 days
Replay Cast
4 days
RSL Revival
4 days
BSL: GosuLeague
5 days
RSL Revival
5 days
WardiTV Korean Royale
5 days
RSL Revival
6 days
WardiTV Korean Royale
6 days
IPSL
6 days
Julia vs Artosis
JDConan vs DragOn
Liquipedia Results

Completed

Proleague 2025-11-14
Stellar Fest: Constellation Cup
Eternal Conflict S1

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
SOOP Univ League 2025
YSL S2
BSL Season 21
CSCL: Masked Kings S3
SLON Tour Season 2
RSL Revival: Season 3
META Madness #9
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025

Upcoming

BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter 2026: Closed Qualifier
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.