I am a pretty much a beginner to all of these technologies, I have been stuck all day on what I thought would be a fairly simple process. Basically, I'm trying to pass a parameter in a JS function through to my PHP code using AJAX, and then inserting the parameter into my database.
The JS function in my .html file.
function pushData(paramData) {
$.ajax({
url: "databaseStuff.php",
type: "post",
data: paramData
});
}
I wish to insert into my SQL table whatever I have put into the Parameters. For example the below code should create 3 new database entries. I have these hooked up to buttons in my actual project.
pushData('It is Wednesday');
pushData('My Dudes');
pushData('AHHHHHHH!');
databaseStuff.php
<?php
$mysqli = new mysqli("localhost", "root", "default", "testDB");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " .
$mysqli->connect_error;
}
echo $mysqli->host_info . "<br>";
$paramData = $_POST['paramData'];
$sql = "INSERT INTO testDBtable (Name, Text) VALUES ('Joe', '$paramData')";
?>
My PHP is successfully connecting to the MySQL DB since I am getting the proper 'localhost via TCP/IP' message, however, I am getting stuck on:
"Notice: Undefined index: paramData in C:\wamp64\www\databaseStuff.php on line 23
Help is appreciated! I am not concerned with SQL injection vulnerability as this code will never leave localhost.