javascript - Trouble with inserting JS variable into MySQL table with PHP with AJAX -
i pretty beginner of these technologies, have been stuck day on thought simple process. basically, i'm trying pass parameter in js function through php code using ajax, , inserting parameter database.
the js function in .html file.
function pushdata(paramdata) { $.ajax({ url: "databasestuff.php", type: "post", data: paramdata }); }
i wish insert sql table whatever have put parameters. example below code should create 3 new database entries. have these hooked buttons in actual project.
pushdata('it wednesday'); pushdata('my dudes'); pushdata('ahhhhhhh!');
databasestuff.php
<?php $mysqli = new mysqli("localhost", "root", "default", "testdb"); if ($mysqli->connect_errno) { echo "failed connect mysql: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error; } echo $mysqli->host_info . "<br>"; $paramdata = $_post['paramdata']; $sql = "insert testdbtable (name, text) values ('joe', '$paramdata')"; ?>
my php connecting mysql db since getting proper 'localhost via tcp/ip' message, however, getting stuck on:
"notice: undefined index: paramdata in c:\wamp64\www\databasestuff.php on line 23
help appreciated! not concerned sql injection vulnerability code never leave localhost.
try writing ajax data parameters this
data: { 'paramdata':paramdata }
also, never queried data.
mysqli_query($mysqli, $sql);
but error you're getting, it's because of ajax data parameters.
Comments
Post a Comment