SELF SOLVED (see bottom code snippet)
Background knowledge: I am building a webpage for a cottage rental service. Currently I am displaying info about a specific cottage, where the data is being retrieved from a MySql database using a php script:
<?php
$servername = "---------";
$username = "----------";
$password = "----------";
$dbname = "----------";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$cottage = 1;
$cottage_name = "SELECT cottage FROM AidenLockeRates where id = 'cottage'";
$RegRate = "SELECT RegRate FROM AidenLockeRates where id = 'cottage'";
$PeakRate = "SELECT PeakRate FROM AidenLockeRates where id = 'cottage'";
$Blurb = "SELECT Blurb FROM AidenLockeRates where id = 'cottage'";
echo $cottage "<br>";
echo $cottage_name "<br>";
echo $RegRate "<br>";
echo $PeakRate "<br>";
echo $Blurb "<br>";
?>
Issue: When "compiling" the script at http://phpfiddle.org I get the error:
Line : 25, Error type : 4
Message : syntax error, unexpected '"
"' (T_CONSTANT_ENCAPSED_STRING), expecting ',' or ';'
The line the error relates to is highlighted in my script. I have tried several variations of the syntax and I am not sure what else to do! Hoping for a timely response, thanks!
Thanks to help from the commentators and digging on other forums I found a solution for anyone who comes across a similar issue:
<?php
$servername = "-------";
$username = "-------";
$password = "-------";
$dbname = "-------";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
else {
echo "conn success <br>";
}
$cottage = 1;
$cottage_name = mysqli_query($conn,"SELECT `cottage` FROM `AidenLockeRates` WHERE id = '$cottage'");
$reg_rate = mysqli_query($conn,"SELECT `RegRate` FROM `AidenLockeRates` WHERE id = '$cottage'");
$peak_rate = mysqli_query($conn,"SELECT `PeakRate` FROM `AidenLockeRates` WHERE id = '$cottage'");
$blurb = mysqli_query($conn,"SELECT `Blurb` FROM `AidenLockeRates` WHERE id = '$cottage'");
echo $cottage . "<br>";
while($cottage_name2 = mysqli_fetch_array($cottage_name))
echo $cottage_name2['cottage'] . "<br>";
while($reg_rate2 = mysqli_fetch_array($reg_rate))
echo $reg_rate2['RegRate'] . "<br>";
while($peak_rate2 = mysqli_fetch_array($peak_rate))
echo $peak_rate2['PeakRate'] . "<br>";
while($blurb2 = mysqli_fetch_array($blurb))
echo $blurb2['Blurb'] . "<br>";
$conn->close();
?>
"; all the echos missing **dot before "
";**. – Jah Nov 15 '15 at 22:59