嘿伙计们我对此非常陌生,所以如果我在这里缺少一些完全愚蠢的东西,我很抱歉。我有以下注册表格。在URL http://www.rockaholics-cologne.de/root/signup.php?e=cataras@gmx.de中,我正在尝试提交值e。但是,在所有情况下,e都是空的或未定义的:
<?php
// Ajax calls this REGISTRATION code to execute
if(isset($_POST["u"])){
// CONNECT TO THE DATABASE
include_once("php_includes/db_conx.php");
// GATHER THE POSTED DATA INTO LOCAL VARIABLES
$u = preg_replace('#[^a-z0-9]#i', '', $_POST['u']);
$p = $_POST['p'];
$e = $_GET['e'];
echo "test";
echo "$e";
// GET USER IP ADDRESS
$ip = preg_replace('#[^0-9.]#', '', getenv('REMOTE_ADDR'));
// DUPLICATE DATA CHECKS FOR USERNAME AND EMAIL
$sql = "SELECT id FROM team WHERE username='$u' LIMIT 1";
$query = mysqli_query($db_conx, $sql);
$u_check = mysqli_num_rows($query);
// FORM DATA ERROR HANDLING
if($u == "" || $p == ""){
echo "The form submission is missing values.";
exit();
} else if ($u_check > 0){
echo "The username you entered is alreay taken";
exit();
} else if (strlen($u) < 3 || strlen($u) > 16) {
echo "Username must be between 3 and 16 characters";
exit();
} else if (is_numeric($u[0])) {
echo 'Username cannot begin with a number';
exit();
} else {
// END FORM DATA ERROR HANDLING
// Begin Insertion of data into the database
// Hash the password and apply your own mysterious unique salt
$cryptpass = crypt($p);
include_once ("php_includes/randStrGen.php");
$p_hash = randStrGen(20)."$cryptpass".randStrGen(20);
// Add user info into the database table for the main site table
$sql = "UPDATE team
SET username='$u',password='$p_hash',ip='$ip',signup=now(),lastlogin=now(),notecheck=now()
WHERE email='$e'";
$query = mysqli_query($db_conx, $sql);
$uid = mysqli_insert_id($db_conx);
// Create directory(folder) to hold each user's files(pics, MP3s, etc.)
if (!file_exists("user/$u")) {
mkdir("user/$u", 0755);
}
// Email the user their activation link
$to = "$e";
$from = "auto_responder@yoursitename.com";
$subject = 'Account Activation';
$message = '<!DOCTYPE html><html><head><meta charset="UTF-8">
<title>yoursitename Message</title></head>
<body style="margin:0px; font-family:Tahoma, Geneva, sans-serif;">
<div style="padding:10px; background:#333; font-size:24px; color:#CCC;">
<a href="http://www.yoursitename.com"><img src="http://www.rockaholics-cologne.de/root/images/logo.png" width="36" height="30" alt="yoursitename" style="border:none; float:left;"></a>Account Activation</div>
<div style="padding:24px; font-size:17px;">Hello '.$u.',<br /><br />Click the link below to activate your account when ready:<br /><br /><a href="http://www.rockaholics-cologne.de/root/activation.php?id='.$uid.'&u='.$u.'&p='.$p_hash.'">Click here to activate your account now</a><br /><br />Login after successful activation using your:<br />* Username: <b>'.$u.'</b></div></body></html>';
$headers = "From: $from\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
mail($to, $subject, $message, $headers);
echo "signup_success";
exit();
}
exit();
}
?>
填写表单时,我会在数据库中输入新条目。但它既没有给我发电子邮件,也没有在指定的电子邮件中更新数据库。它只是用空白电子邮件更新所有条目。脚本中的回显“$ e”也没有返回任何内容。
我用这段代码检查:
<?php
echo "<pre>";
print_r($_GET);
echo "</pre>";
$e = $_GET['e'];
echo "$e";
?>
在这种情况下,它确实返回一个带有[e] =cataras@gmx.de的数组,它还打印出$ e。但为什么它不能在另一个skript工作?我使用完全相同的方法从URL获取e。
当我运行我的Javascript函数时:
function signup(){
var u = _("username").value;
var p1 = _("pass1").value;
var p2 = _("pass2").value;
var status = _("status");
if(u == "" || p1 == "" || p2 == ""){
status.innerHTML = "Fill out all of the form data";
} else if(p1 != p2){
status.innerHTML = "Your password fields do not match";
} else {
_("signupbtn").style.display = "none";
status.innerHTML = 'please wait ...';
var ajax = ajaxObj("POST", "signup.php");
ajax.onreadystatechange = function() {
if(ajaxReturn(ajax) == true) {
if(ajax.responseText.replace(/^\s+|\s+$/g, "") == "signup_success"){
status.innerHTML = ajax.responseText;
_("signupbtn").style.display = "block";
} else {
window.scrollTo(0,0);
_("signupform").innerHTML = "OK "+u+", check your email inbox and junk mail box at <u>"+e+"</u> in a moment to complete the sign up process by activating your account. You will not be able to do anything on the site until you successfully activate your account.";
}
}
}
ajax.send("u="+u+"&p="+p1);
}
}
我得到Uncaught ReferenceError:e未定义。该网站停在“请等待......”。我刚拿出js中的+ e +来到上面的php。对不起,很长的帖子,但我真的没有想法。谢谢!
答案 0 :(得分:0)
我认为$ _GET [&#39; e&#39;]无法在您的原始脚本中运行,因为它没有从您的表单页面传递到该处理脚本。我访问了您提供的网址(http://www.rockaholics-cologne.de/root/signup.php?e=cataras@gmx.de)。请注意,当您提交表单时,&#34; e&#34;在您的URL中没有传递给处理您的脚本的任何内容。在您的表单中,您需要执行以下操作:
<form action="{yourscripturl}?e=<?php echo $_GET['e']?>" {rest of form tag}>
或者,添加一个隐藏来保存&#34; e&#34;的值,然后在处理脚本上使用$ _POST [&#39; e&#39;]而不是$ _GET [&#39;] E&#39;]
<input type="hidden" name="e" value="<?php echo $_GET['e']?>" />