我有一个网站,它有一个表单,可以将数据提交到数据库,还会向电子邮件地址发送电子邮件,该地址在 URL 末尾有一个随机 ID,它将提取特定数据并将其显示在网页上。基本上它是我正在做的情人节消息类型的事情
我已经将数据发送到数据库并完美存储,但由于某种奇怪的原因,我在提取数据时遇到了问题。
这是我的代码,有什么你可以看到可能导致问题的吗?
<?php
// since the id is being passed in the url, you will need to declare it using the get method
$rand = $_GET['rand'];
$action = $_GET['action'];
// if an id was sent to the script, then execute it
if ($rand)
{
// connection vars
$host = "localhost";
$user = "***";
$password = "***";
$dbname = "***";
$tablename = "cards";
$mysql = new mysqli('$host, $user, $password');
$result = $mysql->query('SELECT * FROM $tablename WHERE rand = $rand');
while (($row = $result->fetch_assoc()) !== null) {
print_r($row);
$youremail = urlencode($row['youremail']);
$name = urlencode($row['name']);
$receiveremail = urlencode($row['receiveremail']);
$message = $row['message'];
// replace non flash line breaks with the flash \r newline
$message = str_replace('\n', '\r', $message);
$message = str_replace('\r\n', '\r', $message);
$message = str_replace('<br>', '\r', $message);
$message = str_replace('%0D%0A', '\r', $message);
}
// if there was a result echo the stuff below
if($result)
{
// if we have a result we can show the movie and pass the vars along in the strings
// a set back with this is that you can only pass so much data in the string, think its like 256 characters, but Im not sure.
echo "Hello, $name <br />";
echo "$message";
exit();
}
mysql_close();
}
?>