0

Hello Dears Friends,
I want to make aRegistration form for users, and save data of user in my database.I tried my best best but cannt Please, check my Code.

<?php
include "conn.php";     //database connection file

if($_SERVER["REQUEST_METHOD"]=="POST"){

$username=filter_input(INPUT_POST,'uname',FILTER_SANITIZE_SPECIAL_CHARS);

$sql = "SELECT username FROM usersystem WHERE username = '$username'";

$result=$conn->query($sql);

    if (!$result) {

    echo "data has saved";
    }
    else{

  echo "user already exists" ;

  }
}


?>

apreaciated promp response...

2
Contributors
3
Replies
22
Views
2 Years
Discussion Span
Last Post by zebnoon1
0

i cearted db in adminphp.

conn.php

<?php
$username="root";
$password="";
$server="127.0.0.1";
$db="firs_db";

$conn=new mysqli($server,$username,$password,$db);
//echo "connection is established";
if(!$conn){

echo "Connection not established";

}

?>
0

i re-made plz check this code. It only saves data in database but don't compare.

<!DOCTYPE HTML>
   <?php
     //$connection=mysql_connect("localhost","user","password") or die("cannt connect");
     //mysql_select_db(firs_db,$connection) or die("error in open database");


   ?>
<html>

<head>
  <title>check</title>
</head>

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

$sq = "SELECT * FROM regtb11 WHERE user_name = '$username'";
$result=$conn->query($sq);
//$query="SELECT * From user WHERE username='$username'";
    if (!$result) {
        $sql1="INSERT INTO regtab11(user_name) VALUES('$username')";
        $result1=$conn->query($sql1);
    echo "data has saved";
    }
    else{

  echo "user already exists" ;

  }
}


?>

</body>

</html>

Database creation

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="generator" content="CoffeeCup HTML Editor (www.coffeecup.com)">
    <meta name="dcterms.created" content="Mon, 27 Oct 2014 18:22:03 GMT">
    <meta name="description" content="">
    <meta name="keywords" content="">
    <title>Mydb</title>

    <style type="text/css">
    <!--
    body {
      color:#000000;
      background-color:#FFFFFF;
      background-image:url('Background Image');
      background-repeat:no-repeat;
          }
    a  { color:#0000FF; }
    a:visited { color:#800080; }
    a:hover { color:#008000; }
    a:active { color:#FF0000; }
    -->
    </style>
<?php

$username="root";
$password="";
//$database="addressbook";
$server="127.0.0.1";
//*******************************connection to database***********************************************

                    $conn= mysqli_connect($server,$username,$password);
                if ($conn->connect_error) {
                                          die("Connection failed: " . $conn->connect_error);
                    }


//****************************** Creating DATABASE ****************************************************

                        $sql="CREATE DATABASE regdatabase";
                        if($conn->query($sql)== true){
                        echo "Database is created successfully";
                        }
                         else {
                               echo "Database not created". $conn->error;
                              }
                    $conn->close();
                        ?>
    <!--[if IE]>
    <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
  </head>
  <body>

  </body>
</html>

and my database tables

<!DOCTYPE html>
<html lang="en">
  <head>

    <title>Tables</title>

<?PHP

//connect to database

$servername = "127.0.0.1";
$username = "root";
$password = "";
$dbname = "regdatabase";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}
// sql to create table
$sql = "CREATE TABLE regtab11 (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
reg_Date DATE NOT NULL,
user_name VARCHAR(20) NOT NULL,
user_email VARCHAR(20) NOT NULL,
user_login VARCHAR(70) NOT NULL,
user_pass VARCHAR(20) NOT NULL
)";

if (mysqli_query($conn, $sql)) {
    echo "Table regtab created successfully";
} else {
    echo "Error creating table: " . mysqli_error($conn);
}

mysqli_close($conn);

?>
  </head>
  <body>

  </body>
</html>

and database connection

<?php
$username="root";
$password="";
$server="127.0.0.1";
$db="regdatabase";

$conn=new mysqli($server,$username,$password,$db);
//echo "connection is established";
if(!$conn){

echo "Connection not established";

}

?>
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.