I am trying to run this sql query where 2 input parameters are used which the user has entered on the website.
However somehow the query doesn't run because of this error and I have no clue what to change to make it run
I tried with $sourcecoin
and with "$sourcecoin" without in the query success. But is the query wrong or something else?
<?php
$servername = "xx";
$username = "xx";
$password = "xx";
$dbname = "xx";
$sourcecoin = strip_tags(trim($_POST["sourcecoin"]));
$destcoin = strip_tags(trim($_POST["destcoin"]));
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
echo "Connection not established. Check credentials";
}
$sql = "SELECT Pairs_Source.Exchange, Exchanges.HyperLink
FROM Pairs AS Pairs_Source INNER JOIN Pairs AS Pairs_Dest ON Pairs_Source.Exchange = Pairs_Dest.Exchange
Left join Exchanges on Pairs_Source.Exchange=Exchanges.Exchange
WHERE Pairs_Source.Coin='$sourcecoin' AND Pairs_Dest.Coin='$destcoin'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "They have got the following exchange(s) in common". $row["Exchanges.exchange"] " <br>";
}
} else {
echo "Unfortunately these 2 coins don't have an exchange in common";
}
$conn->close();
?>
I am getting the error message as stated in the subject field.
"PHP Parse error: syntax error, unexpected '$sourcecoin' (T_VARIABLE), expecting ',' or ';'"
";` It needs a `.` before `"
"`. – Barmar Apr 16 '19 at 16:09