PHP根据所选行将MySQLi数据库值分配给PHP变量

PHP根据所选行将MySQLi数据库值分配给PHP变量,php,Php,我想根据数据库中所选学生的相应“联系人号码”分配“$numbers”的值。 我试过: $numbers = "SELECT contact_number from students where idnumber='$idnumber'"; 但它只选择所选学生的ID号 我的桌子图片: 守则: <?php $username = "******@****"; $hash = "*******"; // Config variables. Consult http://api.txtlo

我想根据数据库中所选学生的相应“联系人号码”分配“$numbers”的值。 我试过:

$numbers = "SELECT contact_number from students where idnumber='$idnumber'";
但它只选择所选学生的ID号

我的桌子图片:

守则:

<?php 
$username = "******@****";
$hash = "*******";

// Config variables. Consult http://api.txtlocal.com/docs for more info.
$test = "0";

// Data for text message. This is the text message data.
$sender = "CCA Update"; // This is who the message appears to be from.
$numbers = "SELECT contact_number from students where idnumber='$idnumber'";
// A single number or a comma-seperated list of numbers
$message = "Your grade has been updated!";
// 612 chars or less
// A single number or a comma-seperated list of numbers
$message = urlencode($message);
$data = "username=".$username."&hash=".$hash."&message="
.$message."&sender=".$sender."&numbers=".$numbers."&test=".$test;
$ch = curl_init('https://api.txtlocal.com/send/?');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch); // This is the result from the API
curl_close($ch);
print_r($result);  
?>

已解决!代码如下:

$numbers = $row['contact_number'];

您的代码容易受到相关攻击。甚至不能完全保护它。请学会使用它只是一个个人作业,我只需要具体的值。谢谢你@Madhurbhaiya。谢谢你的提醒@marioWelcome到堆栈溢出!感谢您提供的代码片段,它可能会提供一些有限的、即时的帮助。一个恰当的解释将通过描述为什么这是一个很好的问题解决方案来极大地改进its,并将使它对未来有其他类似问题的读者更有用。请编辑您的答案,添加一些解释,包括您所做的假设。