我有一个MySql表,我想从中获取一个用户的电子邮件,其中给出了用户ID以指出信息。我想接收这封电子邮件,将其存储在一个变量中,然后用它给脚本中的某个人发送电子邮件。
到目前为止,我的代码仍未显示:
<
?php
$appid = $_POST["appid"];
$option1 = $_POST['radio'];
$servername = "localhost";
$username = "mcxjb";
$password = "password";
$dbname = "members1";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "UPDATE users SET user_level='$option1' WHERE userid=$appid";
if (mysqli_query($conn, $sql)) {
echo "Success!";
} else {
echo "Error " . mysqli_error($conn);
}
$emailsql = "SELECT email_address FROM users WHERE userid=$appid";
$query = mysql_query($emailsql);
mysqli_close($conn);
?>
该脚本允许用户批准或拒绝某个人申请。然后,它会将用户级别更新为已批准或已拒绝。然后我想通过使用他们给出的用户ID来提取他们的电子邮件,然后从SQL表中获取它来给用户发送电子邮件!
谢谢, 标记
答案 0 :(得分:1)
while ($row = mysqli_fetch_array($query))
{
//access Email using $row['email_address']
// use PHP mail function here
}
答案 1 :(得分:0)
对于您的更新查询,您需要更改此内容:
if(mysqli_query($conn, $sql))..
惠特:
if(mysqli_query($sql))...
要访问select查询的结果,您需要这样做:
while ($row = mysqli_fetch_array($query))
{
//access Email using $row['email_address']
// use PHP mail function here
}
所以代码将是:
<?php
$appid = $_POST["appid"];
$option1 = $_POST['radio'];
$servername = "localhost";
$username = "mcxjb";
$password = "password";
$dbname = "members1";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "UPDATE users SET user_level='$option1' WHERE userid=$appid";
if (mysqli_query($conn, $sql)) {
echo "Success!";
} else {
echo "Error " . mysqli_error($conn);
}
$emailsql = "SELECT email_address FROM users WHERE userid=$appid";
$query = mysqli_query($conn, $emailsql);
while ($row = mysqli_fetch_array($query))
{
//access Email using $row['email_address']
// use PHP mail function here
}
mysqli_close($conn);
?>