I am using AJAX to send values to PHP and retrieve the values from PHP. The problem is the value i am getting from PHP is viewed as undefined in AJAX. Please help me solve this
Set the dataType parameter as json.
$.ajax({
type:"GET",
url:"dash2.php",
dataType: 'json',
data:{channel:channel},
success:function(data){
}
});
Quoting the jQuery.ajax documentation
dataType defines the type of data that you're expecting back from the server. If none is specified, jQuery will try to infer it based on the MIME type of the response.
Few observations from your code.
1) As discussed in some of the above posts, your code is vulnerable to SQL injection attacks.
2) The mysql_* functions have been DEPRECATED and the extension will be removed in the future. DO NOT RELY ON THEM. I used CAPITAL CASE to emphasize my point.
For both the above points, try using either PDO or MySQLi. Either PDO or MySQLi could be used to shield your code from SQL injection attacks.
Here's a post on how to write code that protects your code from SQL injection attacks.
3) Shift your DB configuration details to a separate config.php so that you don't have to put in the same code in every file, you'd want to put an SQL query in.