I have been trying a few exercises for revision and I am having issues with a piece of PHP code - a small form / submit into a database - when I submit, the execution is not working as intended (it should state "Success!"
or atleast "Error"
:
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname ="whatdo";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " .$conn->connect_error);
}
$disc = $_POST["disc"];
$sql = "INSERT INTO whatdo (disc) VALUES ('$disc')";
if($conn->query($sql) === TRUE) {
echo "Success!";
}
else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
When submitted, the page displays the following:
connect_error) { die("Connection failed: " .$conn->connect_error); } $disc = $_POST["disc"]; $sql = "INSERT INTO whatdo (disc) VALUES ('$disc')"; if($conn->query($sql) === TRUE) { echo "Success!"; } else { echo "Error: " . $sql . "
" . $conn->error; } $conn->close(); ?>
I thought I had all my bases covered but I have obviously missed something obvious.
Howdy
"; a part og the sring is visible "Howdy;>? – Dan Buck Jun 28 '20 at 15:42