I'm having problems with PHP and MySQL. I have this table called 'TestTable' in a databse in phpMyAdmin, which for now just holds names. I want to be able to add names from a webpage using PHP. Establishing connection has been succesful, but nothing seems to happen when I actually do the SQL query. I have tried using the query directly in phpMyAdmin, where it does work.
Here's the entire code (username and password are correctly filled in in the code, but I took them out for obvious reasons):
<?php
$hostname = "localhost";
$username = "";
$password = "";
$db = "jortmilan_form";
$link = mysqli_connect($hostname, $username, $password, $db)
or die ("Connection failed: " . mysqli_connect_error());
echo "Connection to database established!";
echo "<br>";
$sql = "INSERT INTO TestTable(Name) VALUES('peter');";
$result = mysqli_query($db, $sql);
echo "sql used: {$sql}";
echo "<br>";
echo "result was: {$result}";
echo "<br>";
if ($result) {
echo "data succesfully added! yaay";
}
else {
echo "data upload failed";
echo "<br>";
echo mysqli_error();
}
?>
This is the output on the webpage:
Connection to database established! sql used: INSERT INTO TestTable(Name) VALUES('peter'); result was: data upload failed