I am pretty new to PHP and am trying to create a simple (so I assumed) page to takes data from one html page(works fine) and updates a MYSQL Database. I am getting no error message, but the connect string down to the end of the body section is showing up as plain text in my browser window. I do not know how to correct this. I have tried using two different types of connect strings and have verified my names from the HTML page are the same as listed within the php page. Suggestions on what I need to look for to correct would be great. I have looked online, but so far all I am getting is how to connect, or how to create a comment, so I thought I would try here.
Thank you for any assistance I may get!! - Amy -
<body><font color="006600">
<div style="background-color:#f9f9dd;">
<fieldset>
<h1>Asset Entry Results</h1>
<?php
// create short variable names
$tag=$_POST['tag'];
$serial=$_POST['serial'];
$category=$_POST['category'];
$status=$_POST['status'];
$branch=$_POST['branch'];
$comments=$_POST['comments'];
if (!$tag || !$serial || !$category || !$status || !$branch) {
echo "You have not entered all the required details.<br />"
."Please go back and try again.";
exit;
}
if (!get_magic_quotes_gpc()) {
$tag = addslashes($tag);
$serial = addslashes($serial);
$category = addslashes($category);
$status = addslashes($status);
$branch = addslashes($branch);
$comments = addslashes($comments);
}
//@ $db = new mysqli('localhost', 'id', 'pw', 'inventory');
$db = DBI->connect("dbi:mysql:inventory:localhost","id","pw") or die("couldnt connect to database");
$query = "insert into assets values
('".$serial."', '".$tag."', '".$branch."', '".$status."', '".$category."', '".$comments."')";
$result = $db->query($query);
if ($result) {
echo $db->affected_rows." asset inserted into Inventory.";
} else {
echo "An error has occurred. The item was not added.";
}
$db->close();
?>
</fieldset>
</div>
</body>