Jump to content

Parse error: syntax error, unexpected 'cities' (T_STRING) in line number 29


Sanjana

Recommended Posts

Hello everyone,
I am a total newbie in PHP and so do here. I am trying to build a table consisting foreign key and primary key and it is showing error like "Parse error: syntax error, unexpected 'cities' (T_STRING) in line number 29". I have marked up my lines according to sublime text 3 editor. I am trying to create a database. 

 

1 <?php
2 $servername = "localhost";
3 $username = "username";
4 $password = "password";
5 $dbname = "newDB";

7 // Create connection
8 $conn = new mysqli($servername, $username, $password, $dbname);

10 // Check connection
11 if ($conn->connect_error) {
12   die("Connection failed: " . $conn->connect_error);}

14 $firstname = $conn->real_escape_string($_REQUEST['firstname']);
15 $lastname = $conn->real_escape_string($_REQUEST['lastname']);
16 $address = $conn->real_escape_string($_REQUEST['address']);
17 $city = $conn->real_escape_string($_REQUEST['city']);
18 $country = $conn->real_escape_string($_REQUEST['country']);
19 $phone_number = $conn->real_escape_string($_REQUEST['phone_number']);
20 $email = $conn->real_escape_string($_REQUEST['email']);
 
22 // Attempt insert query execution
23 $sql1 = "INSERT INTO cities VALUES ('$city')";

25 $sql2 = "INSERT INTO countries VALUES ('$country')";

27 $sql3 = "INSERT INTO Contacts (firstname, lastname, address, city, country, phone, email) VALUES ('$firstname', '$lastname', '$address', $city, $country, '$phone_number','$email')";

29 SELECT * FROM cities;
SELECT * FROM countries;
SELECT * FROM Contacts;


if($conn->query($sql1) === true){
    echo "City added successfully.";
} else{
    echo "ERROR: Could not able to execute " . $conn->error;
}

if($conn->query($sql2) === true){
    echo "Çountry added successfully.";
} else{
    echo "ERROR: Could not able to execute " . $conn->error;
}

if($conn->query($sql3) === true){
    echo "Çontact added successfully.";
} else{
    echo "ERROR: Could not able to execute " . $conn->error;
}
 
// Close connection
$conn->close();
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.