如何克服以下错误:
Notice: Use of undefined constant temp_members_db - assumed 'temp_members_db'
in /var/www/signup_ac.php on line 10 Cannot send Confirmation link to
your e-mail address
以下是代码:
<?php
ini_set('display_errors',1);
error_reporting(E_ALL|E_STRICT);
include('config.php');
// table name
$tbl_name=temp_members_db;
// Random confirmation code
$confirm_code=md5(uniqid(rand()));
// values sent from form
$name=$_POST['name'];
$email=$_POST['email'];
$country=$_POST['country'];
// Insert data into database
$sql="INSERT INTO $tbl_name(confirm_code, name, email, password, country)VALUES('$confirm_code', '$name', '$email', '$password', '$country')";
$result=mysql_query($sql);
// if suceesfully inserted data into database, send confirmation link to email
if($result){
// ---------------- SEND MAIL FORM ----------------
// send e-mail to ...
$to=$email;
// Your subject
$subject="Your confirmation link here";
// From
$header="from: your name <your email>";
// Your message
$message="Your Comfirmation link \r\n";
$message.="Click on this link to activate your account \r\n";
//$message.="http://www.yourweb.com/confirmation.php?passkey=$confirm_code";
$message.="http://localhost/confirmation.php?passkey=$confirm_code";
// send email
$sentmail = mail($to,$subject,$message,$header);
}
// if not found
else {
echo "Not found your email in our database";
}
// if your email succesfully sent
if($sentmail){
echo "Your Confirmation link Has Been Sent To Your Email Address.";
}
else {
echo "Cannot send Confirmation link to your e-mail address";
}
?>
答案 0 :(得分:9)
要么你忘记了$
,要么你忘记了一些引用。
答案 1 :(得分:5)
您可能正在使用temp_members_db
作为数组键,但未正确引用该字符串:
$arr[temp_members_db] ⟶ $arr['temp_members_db']
这是错误的,但它确实有效。原因是此代码具有未定义的常量(
bar
)而不是字符串('bar'
- 注意引号)。 PHP可能在将来定义常量,不幸的是,这些代码具有相同的名称。它的工作原理是因为PHP自动将一个裸字符串(一个与任何已知符号不对应的不带引号的字符串)转换为包含裸字符串的字符串。例如,如果没有名为bar
的已定义常量,则PHP将替换字符串'bar'
并使用它。
答案 2 :(得分:1)
是我,还是这段代码中有大量的SQL注入和邮件注入?
(这不只是一些奇特的词,它意味着你不完全明白你在做什么......)
顺便说一下,PHP6尚未到达,所以函数get_magic_quotes_gpc()仍然存在,而且仍然是必要的......
答案 3 :(得分:1)
<?php
ini_set('display_errors',1);
error_reporting(E_ALL|E_STRICT);
include('config.php');
// table name
$tbl_name=temp_members_db;
你要么缺少引号:
$tbl_name='temp_members_db';
或常数定义:
define('temp_members_d', 'whatever');