0

hi guys pls help me with this problem i realy can't fix this problem

<?php

function protect($string){
$string = mysql_real_escape_string($string);
$string = strip_tags($string);
$string = addslashes($string);

return $string;
}

function connect(){
$con = mysql_connect('127.0.0.1','root', '') or die(mysql_error());
$db = mysql_select_db("users",$con);
}

?> // this is for the protect function and connection

//i have a problem on "submit" line 6

<?php
include_once "functions.php";

connect();

if(!$_POST['submit']){ //line 6
echo "<table border=>
<form id=\"form1\" name=\"form1\" method=\"post\" action=\"register.php\">
<table width=\"355\" height=\"240\" border=\"1\">
<tr>
<td colspan=\"2\"><div align=\"center\">Registration Form </div></td>
</tr>
<tr>
<td width=\"161\">Username:</td>
<td width=\"178\"><input type=\"text\" name=\"username\" /></td>
</tr>
<tr>
<td>Password:</td>
<td><input type=\"password\" name=\"password\" /></td>
</tr>
<tr>
<td>Confirm Password: </td>
<td><input type=\"password\" name=\"password\" /></td>
</tr>
<tr>
<td colspan=\"2\">&nbsp;</td>
</tr>
<tr>
<td>E-Mail:</td>
<td><input type=\"text\" name=\"email\" /></td>
</tr>
<tr>
<td>Name:</td>
<td><input type=\"text\" name=\"name\" /></td>
</tr>
<tr>
<td>Address:</td>
<td><input type=\"text\" name=\"address\" /></td>
</tr>
<tr>
<td>Contact::</td>
<td><input type=\"text\" name=\"contact\" /></td>
</tr>
<tr>
<td colspan=\"2\"><input type=\"submit\" name=\"Submit\" value=\"Register\" /></td>
</tr>
</table>
</form>";

}else {
$username = protect($_POST['username']);
$password = protect($_POST['password']);
$confirm = protect($_POST['password']);
$email = protect($_POST['email']);
$name = protect($_POST['name']);
$address = protect($_POST['address']);
$contact = protect($_POST['contact']);


$errors = array();

if(!$username){
$errors[] = "Username is not defined:";
}

if(!$password){
$errors[] = "Password is not defined:";
}

if($password){
if(!$confirm)
$errors[] = "Confirmation password is not defined:";
}

if(!$email){
$errors[] = "E-mail is not defined";
}

if(!$name){
$errors[] = "Name is not defined:";
}

if(!$address){
$errors[] = "Address is not defined:";
}

if(!$contact){
$errors[] = "Contact is not defined:";
}



if($username){
if(!ctype_alnum($username)){
$errors[] = "Username can only contain numbers and letters:";
}

$range = range(1,32);
if(!in_array(strlen($username),$range)){
$errors[] = "Username must be between 1 and 32 characters";
}

}

if($password && $confirm){
if($password != $confirm){
$errors[] = "Passwords do not match";
}
}

if ($email){
$checkmail = "dsdsadsa";
if(!preg_match($checkmail, $email)){
$errors[] = "Email is not valid, must be name@server.tld!";
}
}


if ($name){
$range2 = range(3,64);
if(!in_array(strlen($name),$range2)){
$errors[] = "Your name must be between 3 and 64 characters!";
}
}

if($username){
$sql = "SELECT * FROM 'users' WHERE 'username' = '($username)'";
$res = mysql_query($sql) or die(mysql_error());

if(mysql_num_rows($res)>0){
$errors[] = "The username you supplied is already in use!";
}
}

if($email){
$sql2 = "SELECT = FROM 'users' WHERE 'email' = '($email)'";
$res2 = mysql_query($sql2) or die(mysql_error());

if(mysql_num_rows($res2) > 0){
$errors[] = "The e-mail address you supplied is already in use of another user!";
}
}
if(count($errors)>0){
foreach($errors AS $error){
echo $error . "<br>\n";
}
}
else{
$pw = md5($password);
$sql3 = "INSERT INTO users
('username','password','email','name','address','c ontact')
VALUES ('$username','".md5($password)."','$email','$name' ,'$address','$contact')";
$res3 = mysql_query($sql4) or die(mysql_error());
echo "You have successfully registered with the username <b>($username)</b> and the password of <b>($password)</b>";
}


}
?>
3
Contributors
2
Replies
15
Views
5 Years
Discussion Span
Last Post by zebnoon1
0

Instead of using:

if(!$username)

or
if(!$_POST['submit'])

use:

if(empty($username))

and

if(!isset($_POST['submit']))

You will have to change all of the if(!$password) to what i said above for it to all work properly.

0

thank you guys i got it. below is is correct code

<?php
include "conn.php";
//if($_SERVER["REQUEST_METHOD"]=="POST"){
if (isset($_POST['uname']))
{
$username=filter_input(INPUT_POST,'uname',FILTER_SANITIZE_SPECIAL_CHARS);

$sql = "SELECT  * FROM regtab11 WHERE user_name='$username'";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
  echo "user already exists" ;

    }
    else{
        $sql1="INSERT INTO regtab11(user_name) VALUES('$username')";
        $result1=$conn->query($sql1);
    echo "data has saved";

  }
}


?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.