PHP(PDO)注册表错误反馈

时间:2013-02-22 22:57:42

标签: php registration feedback

第一次提问者!

我正在制作一份注册表格,并且我已将其全部提交到我的数据库中,但我希望它在用户错过某些详细信息或已经注册了电子邮件地址等时向页面报告。

目前,我可以不断提取相同的数据,并想知道如何解决这个问题。

我的表单目前发布到另一个php文件,因此从中获取反馈令我感到困惑。

目前,如果用户注册这种情况发生在join.php(他们从html表单加入):

$join = $_GET['success'];
if($join=='yes')
{
echo "Well done!";
}
?>

因为在signup.php(查询所在的位置),如果已注册,则设置此项。

header('Location: join.php?success=yes');

这是非常基本的......                     

            <h1>Sign Up Form</h1>
            <p>Please join today!</p>
        <label>Username
        <span class="small">Type a username.</span>
        </label>
        <input type="text" name="un" id="un" maxlength="100" tabindex="1" />
        <label>Password
        <span class="small">Type a password.</span>
        </label>
        <input type="password" name="pw" id="pw" maxlength="100" tabindex="2" />
        <label>Confirm Password
        <span class="small">Confirm your password.</span>
        </label>
        <input type="password" name="pw2" id="pw2" maxlength="100" tabindex="3" />
        <div class="space"></div>
        <label>Title
        <span class="small">Select your title.</span>
        </label>
        <select name="titleName" id="titleName" tabindex="4">

        <option value="Mr">Mr</option>
        <option value="Mrs">Mrs</option>
        <option value="Ms">Ms</option>
        <option value="Miss">Miss</option>
        <option value="Dr">Dr</option>
        </select>
        <!--Standard form requirements are captured for users with a well designed layour of ordered boxes and set chracter limits. The tab indexes are in order for ease of use and sense to the user.-->
        <label>First Name
        <span class="small">Type your first name.</span>
        </label>
        <input type="text" name="firstName" id="firstName" maxlength="100" tabindex="5" />
        <label>Last Name
        <span class="small">Type your last name.</span>
        </label>
        <input type="text" name="lastName" id="lastName" maxlength="100" tabindex="6" />     
        <label>Email
        <span class="small">Type a valid email address.</span>
        </label>
        <input type="email" name="email" id="email" maxlength="100" tabindex="7" />
        <label>Address
        <span class="small">Type your address here. <br> (500 character limit)</span>
        </label>
        <textarea name="address" rows = "5" id="address" cols="20" maxlength="500" tabindex="8"></textarea>
        <label>Postcode
        <span class="small">Enter your postcode. <br> Eg: CV1 23H.</span>
        </label>
        <input type="text" name="postcode" id="postcode" maxlength="100" tabindex="9" />
        <div class="space"></div>
        <button input type="reset" tabindex="10">Reset</button>
        <button input type="submit" tabindex="11">Submit</button>


        </form>


//SIGNUP.PHP<?php
        $password=$_POST["pw"];
        $password2=$_POST["pw2"];

    if($password==$password2)
    {
        $conn = new PDO("mysql:host=host;dbname=DB",'UN','PASSWORD');

$id=null;
$user=$_POST["un"];
$pass=$_POST["pw"];
$title=$_POST["titleName"];
$fn=$_POST["firstName"];
$ln=$_POST["lastName"];
$email=$_POST["email"];
$address=$_POST["address"];
$postcode=$_POST["postcode"];

    $q=$conn->prepare('INSERT INTO Users(idUsers,username,password,title,firstName,lastName,email,address,postcode)
    VALUES(?,?,?,?,?,?,?,?,?)');

    $q->execute(array($id,$user,$pass,$title,$fn,$ln,$email,$address,$postcode));
    $affected_rows = $q->rowCount();


        $conn=null;

        header('Location: join.php?success=yes');

    }

        else
        {
            header('Location: index.php');

        }
?>

0 个答案:

没有答案