I'm working on a form to add data to a Mysql database. First, I well mention I am adding rows to multiple tables witch I don't think is the problem, but I have no Idea at this point. basically, when I submit the form, it adds a row to Locations and Contributors table. however, when I check the database to see if it goes throw (I get now errors on my php page) there is columns missing data. I think I may have got my variables wrong, but I have looked over them many times and see no errors. However, that's the only resign I can think that it would add blank columns in the row.
The two functions to add data.
AddContributer($FirstName, $LastName, $OrgName);
AddLocation($Room, $Shelf, $Row, $Box, $Display, $Missing);
function AddContributer($FirstName, $LastName, $OrgName) {
include("DBConection.php");
$sql = "INSERT INTO `Contributor` (`Contributor ID`, `FirstName`, `LastName`, `Organization`) VALUES (NULL, '$FirstName', '$LastName', '$OrgName')";
if ($conn->query($sql) === TRUE) {
echo "New contributer created successfully";
} else {
echo "Error: " . $sql . "<br> Can not add contributer data";
}
}
function AddLocation($Room, $Shelf, $Row, $Box, $Display, $Missing)
{
include("DBConection.php");
$sql = "INSERT INTO `Location` (`Location ID`, `Room#`, `Shelf#`, `Row#`, `Box`, `Missing`, `OnDisplay`) VALUES (NULL, '$Room', '$Shelf', '$Row', '$Box', '$Missing', '$Display')";
if ($conn->query($sql) === TRUE) {
echo "New Location created successfully";
} else {
echo "Error: " . $sql . "<br> Can not add Location data";
}
}
Snippets of my code to get data that dose not show on sql.
$Room = $_POST["Room#"];
if($Room == "Item Room"){
$Room = "Unknown";
}
$Shelf = $_POST["Shelf#"];
if($Shelf == "Item Shelf"){
$Shelf = "Unknown";
}
$Row = $_POST["Row#"];
if($Row == "Item Row"){
$Row = "Unknown";
}
$Box = $_POST["Box"];
Picture of data base rows. (It only happens to the location table)
Some Other important info: Room#, Shelf#, and Row# are all select options in the database. Box is a text option with the same format as the contributor rows.
Sorry for the long post when I probably just spelled something wrong. :)