我把以下脚本放在一起,它将搜索mysql数据库以查找在表单文本框中提交的某些成员ID,并为找到的每条记录写一个mail()字符串,但它似乎不起作用,我知道我正在连接,因为如果在“成功连接”后我删除了所有内容,我将获得“成功连接”。如果我按原样运行脚本,我会得到一个空白屏幕。任何有关逻辑的帮助都会得到批准。
op
FORM PAGE HTML
<?php
$servername = "";
$username = "";
$password = "";
$db = "";
// Create connection
$conn = new mysqli($servername, $username, $password, $db);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected Successfully";
if(isset($_POST['Submit'])) {
$MemberIDs = $_POST['MemberIDs']; // contains the values "100,107"
$SearchIDs = array($MemberIDs);
$SearchStr = implode(',', $SearchIDs); // returns 100,107
$sql = "SELECT * FROM members where id in ({$SearchStr})";
$sql->execute();
$raw_results = $sql->fetchAll();
$num_rows = count($raw_results);
if($num_rows > 0 ){
while($results = $sql->fetch($raw_results)) {
echo "mail(".$results['name']." <".$results['requestemail'].", $Subject2, $message2, $headers2);";
}
else
{
echo "No results";
}
}
}
$conn->close();
?>
答案 0 :(得分:2)
您希望对$ conn对象进行操作,这是您与数据库的mysqli连接。当然我无法测试这个或检查语法,但这应该让你接近。
if(isset($_POST['Submit'])) {
// Create connection
$conn = new mysqli($servername, $username, $password, $db);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected Successfully";
$MemberIDs = $_POST['MemberIDs']; // contains the values "100,107"
$SearchIDs = array($MemberIDs);
$SearchStr = implode(',', $SearchIDs); // returns 100,107
$sql = "SELECT * FROM members where id in ({$SearchStr})";
$results = $conn->query($sql);
if( $results->num_rows > 0 ) {
while($row = $results->fetch_assoc()) {
echo 'mail('.$row['name'].');';
}
}
else {
echo "No results";
}
$results->free();
$conn->close();
}