uggg. PHP/HTML problem.

Live forum: http://forum.freeipodguide.com/viewtopic.php?t=35701

cwncool

21-03-2006 17:46:11

I am trying to create a correctly filled in form verification for my registration/login system. The register page is HTML and it sends to a php script that saves the info to a mysql database. As of now, with no verification, it works fine. I want a (hopefully) javascript to put into the HTML side or PHP that I can add into the PHP I already have that I can put into the PHP registration side to give an alert or message when someone fills something in wrong (like not filling in name, or not putting an email address with "@", etc.) and to not submit it to the PHP if it is wrong, but if it's right to submit it. Do you understand? Can I please get some help? This is what I have now....

[b8aae9c6b75]html register[/b8aae9c6b75]
[code18aae9c6b75]<html><head>
<title>User Registration</title>
</head><body>

<form action="register.php" method="post">
Pick a Username: <input type="text" name="username" size="20"><br>
Pick a Password: <input type="password" name="password" size="20"><br>
Email Address: <input type="text" name="email" size="20"><br>
Real Name: <input type="text" name="realname" size="20"><br>
Your Site Account: <input type="text" name="account" size="20"><br>
<input type="submit" value="Sign Up">
</form>

</body></html>[/code18aae9c6b75]

[b8aae9c6b75]Register PHP[/b8aae9c6b75]
[code18aae9c6b75]<?php

include("config.php");

// connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass)
or die ("Could not connect to mysql because ".mysql_error());url==http://=http:///url

// select the database
mysql_select_db($database)
or die ("Could not select database because ".mysql_error());url==http://=http:///url

// check if the username is taken
$check = "select id from $table where username = '".$_POST['username']."';";
$qry = mysql_query($check) or die ("Could not match data because ".mysql_error());url==http://=http:///url
$num_rows = mysql_num_rows($qry);
if ($num_rows != 0) {
echo "Sorry, there the username $username is already taken.<br>";
echo "<a href=register.html>Try again</a>";
exit;
} else {

// insert the data
$insert = mysql_query("insert into $table values ('NULL', '".$_POST['username']."', '".$_POST['password']."', '".$_POST['email']."', '".$_POST['realname']."', '".$_POST['account']."')")

// print a success message
echo "Your user account has been created!<br>";
echo "Now you can <a href=login.html>log in</a>";
}

?>[/code18aae9c6b75]
Could someone please help? Thanx!

Admin

21-03-2006 17:59:18

good god, i don't even know where to start

cwncool

21-03-2006 18:40:02

srry. i know im a newb, but i need some help... oops

darkscout

21-03-2006 18:44:28

[quote34d5bea78d="Admin"]good god, i don't even know where to start[/quote34d5bea78d]

Seconded.

Google for Javascript Verification. If you want to client side verify.

I always do client and server side verification, it's interesting stuff.

darkscout

21-03-2006 18:46:33

[quote92e598cbaa="cwncool"]srry. i know im a newb, but i need some help... oops[/quote92e598cbaa]

unless you like clear passwords floating around. I'd md5 or sha1 them.

Or if you like being retarded like I do, md5 the sha1 )

cwncool

21-03-2006 18:58:00

well, i have
this
[code1c3ca4aaee8]<html><head>
<title>User Registration</title>
<SCRIPT LANGUAGE="javascript">
//
// Verification script
//


// copyright © 2003 agitprop_mainman
//
// This is a free script by agitprop_mainman that is released under the
// Open Source Software copyright conventions.
//
// Please note that NO technical assistance is offered with this script.
//
//--------------------------------------------------------------------------
//
//Paste the script into the head of your page

function verify()
{
// This section just uses a simple regular expression to check the name
// input box. It checks for one or more characters, a space and another
// group of characters.
if (document.forms[0].username.value.search(/^.))url==http://=http:///url
{
alert("Please make sure you have included your username!")
return
}
if (document.forms[0].password.value.search(/^.))url==http://=http:///url
{
alert("Please make sure you have included your password!")
return
}
// This section also uses a regular expression to check the email input box.
// It checks for one or more characters, then it checks for the email @
// signifier, then another group of characters, then a full stop or period (.),
// then for another group of characters.

if (document.forms[0].email.value.search("@"))url==http://=http:///url
{
alert("Please include a valid email address!")
return
}
else
{
// If the form is correctly filled out you can submit the form to your mail cgi
// by deleting the next line, and uncommenting the following two lines.
document.forms[0].submit()url==http://=http:///url
return
}
}
</SCRIPT>

</head><body>

<form action="register.php" method="post">
Pick a Username: <input type="text" name="username" size="20"><br>
Pick a Password: <input type="password" name="password" size="20"><br>
Email Address: <input type="text" name="email" size="20"><br>
Real Name: <input type="text" name="realname" size="20"><br>
Your Account: <input type="text" name="account" size="20"><br>
<input type="submit" value="Sign Up">
</form>

</body></html>[/code1c3ca4aaee8]
but when i click submit, it just signs up and sends the info instead of validating the info before it submits. how would I make it verify the info first? Thanx!

compuguru

21-03-2006 20:35:07

Google "Javascipt Form Validation" => http//www.webdevelopersjournal.com/articles/javascript_validate_form.html

ajasax

21-03-2006 20:45:15

One [b650229d311]strong[/b650229d311] recommendation Use [i650229d311]both[/i650229d311] client- and server-side verification. If you just use Javascript to verify info. then someone could make their own webpage and direct its data to the PHP screwing it up....possibly revealing secret info. I always do the server-side 1st, that way I don't have to worry about security later on. As a general rule, do the backend before the frontend ) hope that helps.