0

I want to assign the value of "$numbers" based on the respective "contact_number" of the selected student in the database. I have tried:

$numbers = "SELECT contact_number from students where idnumber='$idnumber'";

But it just selects the idnumber of the selected student.

Pic of my table: students table

The code:

<?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);  
?>

I can provide more info if needed.

  • Your code is open to [SQL injection](https://stackoverflow.com/q/332365/2469308) related attacks. Even [`real_escape_string`](https://stackoverflow.com/a/12118602/2469308) cannot secure it completely. Please learn to use [Prepared Statements](https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) – Madhur Bhaiya Nov 04 '18 at 14:00
  • it's just a personal assignment, i just need the specific value. Thanks tho! @MadhurBhaiya – Jerrell Punsalan Nov 04 '18 at 14:02
  • Edited. Thanks for the heads up! @mario – Jerrell Punsalan Nov 04 '18 at 14:11

1 Answers1

-1

solved! here's the code:

$numbers = $row['contact_number'];
  • 1
    Welcome to Stack Overflow! Thank you for the code snippet, which might provide some limited, immediate help. A proper explanation would greatly improve its [long-term value](https://meta.stackexchange.com/q/114762/206345) by describing why this is a good solution to the problem, and would make it more useful to future readers with other similar questions. Please edit your answer to add some explanation, including the assumptions you've made. – sepehr Nov 04 '18 at 22:08