我試圖創建一個簡單的用戶註冊,它將數據保存到數據庫中。 但我有一個錯誤,我不能擊敗。 它說註冊表中未定義的索引PHP
注意:未定義指數:pass_conf在C:上 線27
\ WAMP \ WWW \書\ reg.php但我pass_config似乎是正確的。
任何想法最新問題?這是PHP代碼
///更新我的代碼,這一個工程
<?php
$host = "localhost";
$dbuser = "root";
$dbpass = "";
$dbname = "pagination";
$connection = mysql_connect($host,$dbuser,$dbpass);
$db = mysql_select_db($dbname,$connection);
/*
$name = $_POST["username"];
$pass = $_POST["password"];
$pass_conf = $_POST["pass_conf"];
$email = $_POST["email"];
$ip = $_POST["ip"]; */
$name = isset($_POST['username']) ? $_POST['username'] : 0;
$pass = isset($_POST['password']) ? $_POST['password'] : 0;
$pass_conf = isset($_POST["pass_conf"]) ? $_POST["pass_conf"] : 0; // 0 equals your default off value.
$email = isset($_POST['email']) ? $_POST['email'] : 0;
$ip = isset($_POST['ip']) ? $_POST['ip'] : 0;
if($name == false || $pass == false || $pass_conf == false || $email == false){
echo "Please fill in all the required fields.";
};
if($pass != $pass_conf){
echo "Passwords do not match.";
}else {
$connection = mysql_connect($host,$dbuser,$dbpass);
$db = mysql_select_db($dbname,$connection);
$sql = "INSERT INTO user (username,password,email,ip) VALUES ($name, $pass, $email, $ip)";
$result = mysql_query($sql);
echo "Thank you for your registration to Our Site";
};
?>
我將添加我的form.php的也是因爲我得到了它的請求。
<?php
$IP = $_SERVER['REMOTE_ADDR'];
?>
<form name=reg action=reg.php method=post>
Username : <input type=text name=username><br>
Password : <input type=password name=password><br>
Confirm :<input type=password name=pass_conf><br>
Email : <input type=text name=email><br>
<input type=hidden name=ip value='<?php echo $IP ?>'>
<input type=submit value='Register'>
</form>
感謝
$ _POST [「pass_conf」]實際上有一個值/是否設置?你可以發佈var_dump()嗎? – Bono 2012-04-21 15:04:40
你能發佈提交給這個PHP腳本的html表單嗎? – gimg1 2012-04-21 15:07:26
讓我也告誡你,你的代碼容易受到SQL注入的影響。 – Jasper 2012-04-21 15:08:18