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