Hey all,
Literally joined this forum in the last 10 mins as stackoverflow is full of jumped up a-holes that think they’re better than everyone else and i actually never get my questions answered. Hopefully, i’ll have a better experience here!
A bit of background of what i’m about, and what i’m trying to achieve: I’m 21 and a Junior Front End Software Developer (Technically). I work for a company called CodeMonkeyStudios which is an awesome small business. My boss saw my CV and decided to give me a go, even with my lack of experience. I’m currently building a front end Dispatch system for a local private ambulance service. All was going well, using my PHP, HTML and CSS skills, I made the majority of the site work, but then I moved onto the “Create Job” page. And what a nightmare this has been. I thought it would be just a form, but no, our customer wanted all sorts of fancy bits adding, like autocomplete on certain fields, and auto population of a hidden Div that will appear once a patients name is entered. So, I had to learn Javascript, which i already knew basics about, but also had to learn jQuery, which was new to me. But yeah, thats the background.
What this is about: Basically, I’ve done the autocomplete stuff, works a treat, and i’m rather proud of myself . Now i’m trying to tackle the whole “dynamic database results been fed into a hidden div” stuff. And, as I thought, this isn’t as simple as including a file that queries the database and adds “WHERE column = ‘input value’;” to the end of the query. Oh hell no. Then I learnt more and more about PHP and JS, and found that PHP is server side, JS is client side, which I knew, but didn’t really understand how it worked etc. So that was that idea out of the window. I’m now in the process of creating an AJAX request that will open the PHP file containing the query… and that’s where I need some assistance. So, i think I have created the AJAX request using this code:
var xmlhttp;
if(window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
function match() {
var patient = document.getElementById("patient_search").value;
xmlhttp.open("GET","/sql_queries/patients.php",true);
xmlhttp.send;
}
What I need the AJAX to also do (or the JS), is pass the patient var over to the PHP file to include in the query.
For example, I would IDEALLY like it to look something like the below. Say for this example the JS patients var was passed and saved as $patients…
$query = "SELECT * FROM patients WHERE account_id = ".$_COOKIE['acc_id']." AND patient_surname = '".$patients."';";
How can I achieve this? Or something similar? Is it possible? If not, then why?
Thank you in advance for anyone that has any input!
EDIT: Just found the below… Which I am going to try and implement…
xmlhttp.open("GET",".sql_queries/patients.php?surname="+ patients"",true);
xmlhttp.send();