我知道这个问题比教堂里的阿门问过的次数多。但无论如何我会问。
我将参加丹麦的桌面游戏大会,我认为"嘿,我们可以使用定位玩家短信服务" 所以我建立它。但是,当我必须从一个数据库中取出一些数据,如phonenumber和名称。我需要将其插入另一个数据库(我的短信注入看起来)但一个变量只能存储1个数字,我需要存储10〜50个数字和名称 这是我到目前为止所得到的。
// escape variables for security
$Name = mysqli_real_escape_string($con, $_POST['Name']);
$Players = mysqli_real_escape_string($con, $_POST['Players']);
$Game = mysqli_real_escape_string($con, $_POST['Game']);
$besked = "Du har oprettet et spil med navn $Name og er et $Game som mangler $Players spiller(e).";
echo $besked;
echo "<br>";
$result = mysqli_query($con,"SELECT * FROM brugere where $Game = 'Ja'");
while($row = mysqli_fetch_array($result)) {
echo $row['Navn'] . " " . $row['VCNummer'];
echo "<br>";
$PhoneNumber = $row['Phonenumber'];
}
mysqli_close($con);
?>
<html>
<body>
<form action="smssend.php" method="post">
<input type="hidden" name="besked" value="<?php echo "$besked"; ?>"><br>
<input type="hidden" name="PhoneNumber" value="<?php echo "$PhoneNumber"; ?>"><br>
<input type="submit" value="Send data">
</form>
</body>
</html>
当我试图把它放在其他数据库中时
<?php
$con=mysqli_connect("localhost","USER","PASSWORD","SMSDATABASE");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// escape variables for security
$besked = mysqli_real_escape_string($con, $_POST["besked"]);
$PhoneNumber = mysqli_real_escape_string($con, $_POST["PhoneNumber"]);
$sql="INSERT INTO outbox (DestinationNumber, Class, TextDecoded)
VALUES ('$PhoneNumber', '1', '$besked')";
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
mysqli_close($con);
?>
<meta http-equiv="refresh" content="0;url=../index.php">
我希望这是有道理的。
我试过以下
<?php
$con=mysqli_connect("localhost","USER","PASSWORD","DATABASE");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// escape variables for security
$Name = mysqli_real_escape_string($con, $_POST['Name']);
$Players = mysqli_real_escape_string($con, $_POST['Players']);
$Game = mysqli_real_escape_string($con, $_POST['Game']);
$besked = "Du har oprettet et spil med navn $Name og er et $Game som mangler $Players spiller(e).";
echo $besked;
echo "<br>";
$result = mysqli_query($con,"SELECT * FROM brugere where $Game = 'Ja'");
$phone_numbers = array();
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
$phone_numbers[] = $row['Phonenumber'];
}
mysqli_close($con);
?>
<html>
<body>
<form action="smssend.php" method="post">
<input type="hidden" name="besked" value="<?php echo "$besked"; ?>"><br>
<input type="hidden" name="PhoneNumber" value="<?php echo serialize($phone_numbers); ?>">
<input type="submit" value="Send data">
</form>
</body>
</html>
下一个PHP文件
<?php
$con=mysqli_connect("localhost","USER","PASSWORD","SMSDATABASE");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// escape variables for security
$besked = mysqli_real_escape_string($con, $_POST["besked"]);
$Phone = unserialize($_POST["PhoneNumber"]);
var_dump($Phone);
/*$sql="INSERT INTO outbox (DestinationNumber, Class, TextDecoded)
VALUES ('$PhoneNumber', '1', '$besked')";
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
echo "Beskeden er sendt";
mysqli_close($con);
*/
?>
请注意我已在此部分取消了插入数据库。
但是当我尝试运行该文件时,我得到以下内容
布尔(假)
答案 0 :(得分:0)
而不是
while($row = mysqli_fetch_array($result)) {
echo $row['Navn'] . " " . $row['VCNummer'];
echo "<br>";
$PhoneNumber = $row['Phonenumber'];
}
试试这个
$phone_numbers = array();
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
$phone_numbers[] = $row['Phonenumber'];
}
然后尝试
var_dump($phone_numbers);