Skip to content

Instantly share code, notes, and snippets.

@blakewrege
Created November 11, 2014 21:16
Show Gist options
  • Save blakewrege/ee190ed8b243c9a051a5 to your computer and use it in GitHub Desktop.
Save blakewrege/ee190ed8b243c9a051a5 to your computer and use it in GitHub Desktop.
<html>
<body>
<?php
$servername = "localhost";
$username = "testuser";
$password = "test623";
$dbname = "lab2";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$CNO=$_POST["CNO"];
settype($CNO, "integer");
$CNAME=$_POST["CNAME"];
$STREET=$_POST["STREET"];
$ZIP=$_POST["ZIP"];
$PHONE=$_POST["PHONE"]"
$sql = "INSERT INTO customers (CNO, CNAME, STREET, ZIP, PHONE)
VALUES ('$CNO', '$CNAME', '$STREET', '$ZIP', '$PHONE')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully\n";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
CNO:<?php echo $_POST["CNO"]; ?><br>
CNAME:<?php echo $_POST["CNAME"]; ?><br>
STREET:<?php echo $_POST["STREET"]; ?><br>
ZIP:<?php echo $_POST["ZIP"]; ?><br>
PHONE:<?php echo $_POST["PHONE"]; ?><br>
<br>
</body>
</html>
@blakewrege
Copy link
Author

Error: INSERT INTO customers (CNAME, STREET, ZIP, PHONE)
VALUES ('John','West Main','49008','4280746')
Cannot add or update a child row: a foreign
key constraint fails (lab2.customers, CONSTRAINT customers_ibfk_1 FOREIGN KEY (zip) R

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment