This question already has an answer here:
I am just fooling around with some sample web pages as I haven't touched form to database submissions for some time and I've noticed mysql_* is no longer widely used and has been replaced with mysqli_*. I have what I believe to be a simple form(can post if needed but I don't think the problem lies within the form). My connection code for the database is as follows,
<?php
//addslash() for sanitization
ExtendedAddslash($_POST);
//correct form name's for data to be inserted
$name = $_POST['name'];
$specName = $_POST['specName'];
$weight = $_POST['weight'];
$weightUnits = $_POST['weight-units'];
$description = $_POST['description'];
$conn = mysqli_connect("localhost","root","CENSORED","testDB");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL :" . mysqli_conect_error();
}
else {
echo "Connection was OK!
";
}
$result = mysqli_query($conn,"INSERT into 'testDB.users' (name, specName, description, weight, weightUnits) VALUES ('$name','$specName','$description', '$weight', '$weightUnits')");
if ($result) {
echo "Success
";
}
else {
echo "Error
";
}
mysqli_close($conn);
?>
In the past this worked out pretty straight forward but I have changed some of the syntax to match mysqli standards. The connection test always results in "Connection was OK" however I always seem to get the "Error". Is the problem the $result
variable? or am I just not executing this query properly.
</div>