PDA

View Full Version : register page


kasiarakos
08-05-2010, 09:42 AM
hello. I want to create a register page i want to put 4 fields (name surname password and password again ) my problem is how can i compare the fields(password and password again) and if they are not the same, give me a message.
if you have any tutorial please give me the url
thank you!!!

edbr
08-05-2010, 09:53 AM
first i would validate this using javascript for speed of use before getting into serverside

http://www.tizag.com/javascriptT/javascriptform.php

kasiarakos
08-05-2010, 12:15 PM
thank you for your help...
i made this but when i push the submit button it doesn' t work, what seem's to be the broblem?...

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script>
function checkPass(){
var guess = document.form1.password.value;
var secret = document.form1.repassword.value;
if (guess != secret){
alert('eisai lathos');
return -1;
}
}
</script>
</head>

<body>
<form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
<table width="800" border="1">
<tr>
<th scope="row">onoma</th>
<td><label for="onoma"></label>
<input type="text" name="onoma" id="onoma" /></td>
</tr>
<tr>
<th scope="row">epwnymo</th>
<td><input type="text" name="epwnymo" id="epwnymo" /></td>
</tr>
<tr>
<th scope="row">password</th>
<td><label for="epwnymo">
<input type="password" name="password" id="password" />
</label></td>
</tr>
<tr>
<th scope="row">rewrite password</th>

<td> <input type="password" name"repassword" id="repassword" />
<label for="password"></label></td>
</tr>
<tr>
<th scope="row">&nbsp;</th>
<td><input type="submit" name="submit" id="submit" value="Submit" onclick="checkPass"/></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1" />
</form>

Corrosive
08-05-2010, 12:18 PM
I'm not sure I like the look of...

action="<?php echo $editFormAction; ?>">

kasiarakos
08-05-2010, 12:34 PM
sorry this isnt all of the code.... i fixed the problem with the javascript and i see the allert window on my screen but even now the registry passes in the database. what should i do to stop the registry and the next page i see will be the register again?
sorry for my English....

kasiarakos
08-05-2010, 12:35 PM
here is all of my code


<?php require_once('Connections/game.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO users (onoma, epwnymo, password) VALUES (%s, %s, %s)",
GetSQLValueString($_POST['onoma'], "text"),
GetSQLValueString($_POST['epwnymo'], "text"),
GetSQLValueString($_POST['password'], "text"));

mysql_select_db($database_game, $game);
$Result1 = mysql_query($insertSQL, $game) or die(mysql_error());

$insertGoTo = "index.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}

mysql_select_db($database_game, $game);
$query_game = "SELECT onoma, epwnymo, password FROM users";
$game = mysql_query($query_game, $game) or die(mysql_error());
$row_game = mysql_fetch_assoc($game);
$totalRows_game = mysql_num_rows($game);
?>





<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script>
function checkPass(){
var guess = document.form1.password.value;
var secret = document.form1.repassword.value;
if (guess != secret){
alert('eisai lathos');

}
}
</script>
</head>

<body>
<form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
<table width="800" border="1">
<tr>
<th scope="row">onoma</th>
<td><label for="onoma"></label>
<input type="text" name="onoma" id="onoma" /></td>
</tr>
<tr>
<th scope="row">epwnymo</th>
<td><input type="text" name="epwnymo" id="epwnymo" /></td>
</tr>
<tr>
<th scope="row">password</th>
<td><label for="epwnymo">
<input type="password" name="password" id="password" />
</label></td>
</tr>
<tr>
<th scope="row">rewrite password</th>

<td> <input type="password" name"repassword" id="repassword" />
<label for="password"></label></td>
</tr>
<tr>
<th scope="row">&nbsp;</th>
<td><input type="submit" name="submit" id="submit" value="Submit" onclick="checkPass()"/></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1" />
</form>


</body>
</html>
<?php
mysql_free_result($game);
?>

edbr
08-06-2010, 01:30 AM
this may stop the insert, it but not tested as editing the dreamweaver code is a PIA. there are tutorials on theis site for php which will cover this. and one member provides 1-1 lessons (donation based) if you want to learn

if($_POST['password']==$_POST['repassword']){

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO users (onoma, epwnymo, password) VALUES (%s, %s, %s)",
GetSQLValueString($_POST['onoma'], "text"),
GetSQLValueString($_POST['epwnymo'], "text"),
GetSQLValueString($_POST['password'], "text"));

mysql_select_db($database_game, $game);
$Result1 = mysql_query($insertSQL, $game) or die(mysql_error());

$insertGoTo = "index.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
}

kasiarakos
08-06-2010, 07:26 AM
thank you for your suggestion but i don't think that I am intresed in taking lessons from the internet, i have not money to spend on it....
eventually i fount a way to resolve my problem, i used a javascript...
here is the code and it works perfect:

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>register page</title>
<script type="text/javascript">
function validate(form){
var repassword= form.repassword.value;
var password = form.password.value;

if (password.length === repassword.length) {
return true;
}
else{
alert("You must enter the same password.");
return false;
}
}
</script>
</head>

<body>
...
<form name="form" action="<?php echo $editFormAction; ?>" method="POST" onsubmit="return validate(this);">
.....
</body>

edbr
08-06-2010, 08:02 AM
so if javascript is turned off in the browser they can still submit

kasiarakos
08-06-2010, 09:19 AM
and if i use the way you told me, how can i navigate to a failed registration page? or create a message that tell : the registration failed?

edbr
08-06-2010, 09:23 AM
thought you didnt want to learn

kasiarakos
08-06-2010, 09:42 AM
ok then send me an e-mail to tell me about the lessons and the donation and others details my e-mail is kasiarakos@windowslive.com

edbr
08-06-2010, 10:04 AM
you can check the FREE tutorials om this site made by the same guy . his site is in his signature, davidj

http://codezenith.co.uk/