I am trying to grab the text in a list item that a user clicks on and then store it in a variable. I would then use that variable as a search term in an sql query. I would like to know if it is possible to do this.
I think I have most of the code written, I'm just confused on how to make all of the files work together.
Jquery script to change class names to whatever text the user clicks on:
$('li').click(function () {
var name = $(this).text();
var sqlname = name;
$('#prf').attr("class",name);
$('#pic').attr("class",name);
$('#info').attr("class",name);
});
SQL Code within a PHP document to search a MyPHPAdmin database for whatever value 'stagename' is equal to.
<?php
$link = mysqli_connect("host", "username", "pass","db_name") or die ("Error ". mysqli_error($link));
$query = "SELECT realname
FROM artistmaster
WHERE stagename = '**jQuery variable here**'";
$result = mysqli_query($link, $query) or die(mysqli_error($link));
$row = mysqli_fetch_assoc($result);
foreach($row as $key => $value) {
$$key = $value;
} ;
echo $realname;
?>
EDIT: I already have the MyPHPAdmin setup, and I have already created a database with the necessary data. (all stagenames and realnames of each artist)
So basically the user clicks on a list item that has the stage-name of musical artist, the stage-name then gets ran through an sql query that returns the real name of the musician.
I'm fairly new to programming in general, and have just started learning HTML, PHP, and JQuery within the past week. That being said, If i'm over-complicating this somehow or if anyone has a suggestion on how to simply if this, that would be great.