0

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

?> 
Arkadelic
  • 105
  • 2
  • 11
  • In each of your echos, put a dot after the variable and before the quotation mark. – Reeno Nov 15 '15 at 22:36
  • @JohnConde I checked out the duplicate answer and my problem is similar but not covered anywhere in the duplicate post, I am following the correct syntax closely (copied from http://www.w3schools.com/sql/sql_where.asp ) and still have not found a solution, please reconsider. – Arkadelic Nov 15 '15 at 22:38
  • http://stackoverflow.com/a/18092288 the second point is your error – Reeno Nov 15 '15 at 22:42
  • echo $PeakRate **.** "
    "; all the echos missing **dot before "
    ";**.
    – Jah Nov 15 '15 at 22:59
  • @Reeno Thank you this fixes the error, but now my SELECT statements are echoed as strings. Removing the quotes causes other errors, not sure what to do next... – Arkadelic Nov 15 '15 at 23:43
  • You never send any queries to the database. There's a lot missing in your script. You better search any tutorials. W3schools isn't a good site to learn anything. – Reeno Nov 16 '15 at 07:13

0 Answers0