登录 | 注册 | FAQ
Anonymous

PHP/HTML form confusing

+ 发表回复

3 篇帖子 分页: 1 / 1


PHP/HTML form confusing

kalzerd » 周四 9月 11, 2014 7:28 am

Hello and greetings fellow programmers!

I am still new and learning PHP/HTML. This is my first project. What I have to do is to create a registration/login form and store the data in database then display the data stored. I created 3 pages which is registration form, connect.php and page3.php(use to display stored data).

Here is my registration form :
代码: 全选
</head>
<body>
   
<div class="register-form">

<h1>Register</h1>
<form action="connect.php" method="POST">
    <p><label>User Name : </label>
   <input id="username" type="text" name="Username" placeholder="username" /></p>
   
   <p><label>E-Mail&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : </label>
    <input id="password" type="email" name="Email" required placeholder="example@email.com" /></p>

     <p><label>Password&nbsp;&nbsp; : </label>
    <input id="password" type="password" name="Password" placeholder="password" /></p>
   
    <p><label>UserID&nbsp;&nbsp;&nbsp;&nbsp; : </label>
    <input id="password" type="password" name="UserID" placeholder="ID" /></p>

    <a class="btn" href="login.php">Login</a>
    <input class="btn register" type="submit" name="submit" value="Register" />
    </form>
</div>
</body>
</html>


here is my connect.php :
代码: 全选
<html>
<body>
<?php
session_start();

$dbhost = "localhost";
$dbuser = "root";
$dbpass = "12345";
$dbname = "student";

$con = mysql_connect($dbhost,$dbuser,$dbpass);
if (!$con){
    die("Database Connection Failed" . mysql_error());
}else{
   $seldb = mysql_select_db($dbname);
   if(!$seldb){
      die("CANNOT SELECT Database");
   }else{
      header("Location: page3.php");
   }
}
?>
</body>
</html>


and here is my page3.php :
代码: 全选
<?php
   require('connect.php');
   
    if (isset($_POST['Username']) && isset($_POST['Password'])){
        $username = $_POST['Username'];
   $email = $_POST['Email'];
        $password = $_POST['Password'];
   $userid = $_POST['UserID'];

        $query = "INSERT INTO `user` (Username, Email, Password, UserID) VALUES ('$username','$email','$password','$userid')";
        $result = mysql_query($query);
        if($result){
            $msg = "User Created Successfully.";
        }
    }
    ?>


Ignore the page3.php for a while. My question is when I click register, it should go to connect.php to connect to database mysql and then proceed to page3.php and display "User Created Successfully", BUT it does not. When i click register, it just go to connect.php and display nothing. I did check my codes couple of times but still could not figure out what's wrong(**noted that i have my latest version of xampp running). I hope someone can help me because I'm out of idea. Sorry and Thanks!
头像

kalzerd

  • 帖子: 2
  • 注册: 周四 9月 11, 2014 7:21 am

Re: PHP/HTML form confusing

nanoverso » 周四 9月 11, 2014 6:50 pm

Database insertion is covered on lesson 19 here on HTML.net: http://html.net/tutorials/php/lesson19.php , maybe it can give you some directions.
Have you tried to put an debug error message on the else of the result testing of the SQL insertion statement ?
One thing I don´t understand is why you use two PHP files to make this insertion.

Good luck !
头像

nanoverso

  • 帖子: 253
  • 注册: 周六 5月 10, 2014 12:08 am
  • 地址: Brazil
--
Free VST Plugins Download.

Re: PHP/HTML form confusing

kalzerd » 周六 9月 13, 2014 12:39 pm

Thank You nanoverso! I checked the link you gave me and i merge connect.php and page3.php in one file. Everything works fine after that. Whew, simple things and i couldn't figure it out! Sorry I am still learning and THANKS AGAIN!
头像

kalzerd

  • 帖子: 2
  • 注册: 周四 9月 11, 2014 7:21 am


+ 发表回复

分页: 1 / 1