I want to send data via AJAX to a PHP file and in the PHP file the data will save into a mysql database.
This is my AJAX code:
$('a').on('click', function(){
var href = $(this).attr('href');
var JsSessionID = $(this).data('info');
var data = 'url=' + href + '&JsSessionID=' + JsSessionID;
$.ajax({
url: "/wp-content/themes/twentyfifteen/js/test.php",
type: "POST",
data: data,
success: function(data) {
}
});
});
This is my PHP code: Yes no mysqli.. it is only for testing.
$url = $_POST['url'];
$JsSessionID = $_POST['JsSessionID'];
$verbindung = mysql_connect ("abc","db1", "123")
or die ("keine Verbindung möglich. Benutzername oder Passwort sind falsch");
mysql_select_db("db1")
or die ("Die Datenbank existiert nicht.");
$eintrag = "INSERT INTO test (ID, JsSessionID, URL) VALUES ('', $JsSessionID, $url)";
$eintragen = mysql_query($eintrag);
This code doesn't work.
The data weren't save into my database and I don't know why. The connection is right and the AJAX sends the data correct to my PHP file. I tested it - I try to catch the data and save it into a txt file.
This works.
$datei = fopen("daten.txt","w");
echo fwrite($datei, $url,100);