Ajax call in wordpress returns -1 & no code is run from the functions.php file - wordpress

I have to insert values into database table wp_ratings table using ajax in wordpress but it is not working. Below is the code i am using:
Ajax call:
$(function(){
$('#submit').click(function(){
var rating_allowed=document.getElementById("rating_allowed").value;
var product_id=document.getElementById("product_id").value;
var user_id=document.getElementById("user_id").value;
var pc_ip=document.getElementById("pc_ip").value;
var performance_input=document.getElementById("performance_input").value;
var features_input=document.getElementById("features_input").value;
var battery_input=document.getElementById("battery_input").value;
var overall_input=document.getElementById("overall_input").value;
var rating_cat_count=document.getElementById("rating_cat_count").value;
var rate_1_name_find=document.getElementById("rate_1_name_find").value;
var rate_2_name_find=document.getElementById("rate_2_name_find").value;
var rate_3_name_find=document.getElementById("rate_3_name_find").value;
var rate_4_name_find=document.getElementById("rate_4_name_find").value;
var pros=document.getElementById("pros").value;
var cons=document.getElementById("cons").value;
alert("g");
alert("action=updateRating&product_id=" + product_id + "&user_id=" + user_id + "&pc_ip=" + pc_ip + "&performance_input=" + performance_input + "&features_input=" + features_input + "&battery_input=" + battery_input + "&overall_input=" + overall_input + "&rating_cat_count=" + rating_cat_count +"&rate_1_name_find=" + rate_1_name_find + "&rate_2_name_find=" + rate_2_name_find + "&rate_3_name_find=" + rate_3_name_find + "&rate_4_name_find=" + rate_4_name_find + "&pros=" + pros + "&cons=" + cons);
$.ajax({
url:"/wp-admin/admin-ajax.php",
type:'POST',
data:"action=updateRating&product_id=" + product_id + "&user_id=" + user_id + "&pc_ip=" + pc_ip + "&performance_input=" + performance_input + "&features_input=" + features_input + "&battery_input=" + battery_input + "&overall_input=" + overall_input + "&rating_cat_count=" + rating_cat_count +"&rate_1_name_find=" + rate_1_name_find + "&rate_2_name_find=" + rate_2_name_find + "&rate_3_name_find=" + rate_3_name_find + "&rate_4_name_find=" + rate_4_name_find + "&pros=" + pros + "&cons=" + cons,
success:function(results)
{
alert(results);
}
});
}
);
});
in functions.php file:
function implement_ajax_updateRating()
{
$p_id = mysql_real_escape_string(htmlentities(trim($_POST['product_id'])));
$user_id = mysql_real_escape_string(htmlentities(trim($_POST['user_id'])));
$pc_ip = mysql_real_escape_string(htmlentities(trim($_POST['pc_ip'])));
$rate_1 = mysql_real_escape_string(htmlentities(trim($_POST['performance_input'])));
$rate_2 = mysql_real_escape_string(htmlentities(trim($_POST['features_input'])));
$rate_3 = mysql_real_escape_string(htmlentities(trim($_POST['battery_input'])));
$rate_4 = mysql_real_escape_string(htmlentities(trim($_POST['overall_input'])));
$rating_cat_numbers = mysql_real_escape_string(htmlentities(trim($_POST['rating_cat_count'])));
$rate_1_find = mysql_real_escape_string(htmlentities(trim($_POST['rate_1_name_find'])));
$rate_2_find = mysql_real_escape_string(htmlentities(trim($_POST['rate_2_name_find'])));
$rate_3_find = mysql_real_escape_string(htmlentities(trim($_POST['rate_3_name_find'])));
$rate_4_find = mysql_real_escape_string(htmlentities(trim($_POST['rate_4_name_find'])));
$pros = mysql_real_escape_string(htmlentities(trim($_POST['pros'])));
$cons = mysql_real_escape_string(htmlentities(trim($_POST['cons'])));
//add_post_meta('17', 'ff_value', "ff", true);
$rating_insert = mysql_query("INSERT INTO wp_rating (post_id, rating_1, rating_2,rating_3,rating_4,user_id,comment_id,pc_ip,pros,cons)
VALUES (".$p_id.", ".$rate_1.", ".$rate_2.",".$rate_3.",".$rate_4.",".$user_id.",".$comment_id.",'".$pc_ip."','".$pros."','".$cons."')");
//$multi_in = multiRatingWidth($p_id, $rating_cat_numbers, $rate_1_find, $rate_2_find, $rate_3_find, $rate_4_find);
die();
}
add_action('wp_ajax_updateRating', 'implement_ajax_updateRating');
add_action('wp_ajax_nopriv_updateRating', 'implement_ajax_updateRating');
But alert is returning -1 & nothing is saved in database.

Related

Asp.net , to_date Function

I want to update record in oracle db. But it gives me error "date format picture ends before converting..." I uses to_date function. datatype of column is DATE.
Here is my query
var updateddate = DateTime.Now;
var testing= this.hidvalue.Value;
var idrow = id.Text;
var anserrow = lblanswer.Text;
var weightpwd = lblweighted.Text;
var solvetimerow =lblsolvetime.Text;
var updatedby = Session["Name"];
string queryDuppass = "Update ADU.QAT_DATA set Question='" + idrow + "',Answer='" + anserrow + "', Question_Weighted='" + weightpwd + "', Resolve_Estimated_Time='" + solvetimerow + "', Updated_By='" + updatedby + "', Updated_Date= to_date('" + updateddate + "','mm-dd-yyyy hh12:mi:ss'" + ")" + " where ID='" + testing + "'";

Data from Firebase in Browser shows fine but in html page shows as undefined

I have data downloaded from firebase DB and the data is fine but when this data is loaded into HTML all table TD shows undefined, not able to understand why been check a whole lot of codes not able to understand whats wrong here.
Thank You
var registration = firebase.database().ref("REGISTRATION")
dataRef = firebase.database().ref().child("REGISTRATION");
dataRef.on("value", rData);
function rData(data){
console.log(data.val());
var gData = data.val();
for (gDatarow in gData)
{
alert(email);
var email = gDatarow.email;
var name = gDatarow.name;
var gender = gDatarow.gender;
var date = gDatarow.date;
var phone = gDatarow.phone;
var state = gDatarow.state;
var school = gDatarow.school;
var clas = gDatarow.clas;
var classname = gDatarow.classname;
$("#reData").append("<tr><td>" + email + "</td></td>" + name + "</td><td>" + gender + "</td></td>" + date + "</td><td>" + phone + "</td></td>" + state + "</td><td>" + school + "</td></td>" + clas + "</td><td>" + classname + "</td></tr>");
}
}
enter image description here
This is what worked in my case :
dataRef.on("child_added", function(data) {
var rData = data.val();
$("#reData").append("<tr><td>" + rData.email + "</td><td>" + rData.name + "</td><td>" + rData.gender + "</td><td>" + rData.birthdate + "</td><td>" + rData.phone + "</td><td>" + rData.state + "</td><td>" + rData.school + "</td><td>" + rData.class + "</td><td>" + rData.classname + "</td></tr>");
});
Thanks to all for their time.

Incorrect syntax near ',' while using update query

Following is my code.I have used class in my website.But i am getting error as "Incorrect syntax near ',' ".....can anyone tell me what is wrong in the code..
protected void btnadd_Click(object sender, EventArgs e)
{
s1 = "Update tckt_tbl Set class='" + ddlclass.Text + "',dist=" + lbldist.Text + ",no_of_adults=" + ddladults.Text + ",no_of_senior=" + ddlsenior.Text + ",n1='" + txtn1.Text + "',";
s1 += "n2='" + txtn2.Text + "',n3='" + txtn3.Text + "',n4='" + txtn4.Text + "',n5='" + txtn5.Text + "',n6='" + txtn6.Text + "',";
s1 += "ag1=" + txtag1.Text + ",ag2=" + txtag2.Text + ",ag3=" + txtag3.Text + ",ag4=" + txtag4.Text + ",ag5=" + txtag5.Text + ",ag6=" + txtag6.Text + ",";
s1 += "gen1='" + txtgen1.Text + "',gen2='" + txtgen2.Text + "',gen3='" + txtgen3.Text + "',gen4='" + txtgen4.Text + "',gen5='" + txtgen5.Text + "',gen6='" + txtgen6.Text + "',";
s1 += "cn1='" + txtchn1.Text + "',cn2='" + txtchn2.Text + "',cag1=" + txtcag1.Text + ",cag2=" + txtcag2.Text + ",cgen1='" + txtcgen1.Text + "',cgen2='" + txtcgen2.Text + "' Where userid=" + Session["suser"].ToString() + "";
con.ExecQuery(s1);
Response.Redirect("tcktbook_itckt.aspx");
}
First off, it is a really bad idea to build a query from user input. I suggest you use a parameterized query instead.
Try outputting s1 to see what the query looks like.
Chances are good that you have an unbalanced quote.
On third line there is problem.
s1 += "ag1=" + txtag1.Text + ",ag2=" + txtag2.Text + ",ag3=" + txtag3.Text + ",ag4=" + txtag4.Text + ",ag5=" + txtag5.Text + ",ag6=" + txtag6.Text + ",";
I think here commas and semicoluns are not given properly.
I suggest you use Parameter Query, rather than concatenate everything. But before that, are you sure that you already give all value? Because if you didn't give any value for numeric field, it should show an error, since the query become:
..cag1=,cag2..

The meaning of the ampersand

In this line:
var dataString = 'name='+ name + '&email=' + email + '&subject=' + subject + '&msg=' + msg;
What does the ampersand(&) mean?
I think the ampersands are meant for query string separation from each other
var dataString = 'name='+ name + '&email=' + email + '&subject=' + subject + '&msg=' + msg;
becomes
var dataString = 'name=John Doe&email=johndoe#gmail.com&subject=some email subject&msg=hey activate your account';
This can then be appended to your Url
var finalUrl = "http://mysite.com?" + dataString;

How to open popup at right corner?

I am opening a popup window from javascript using window.open. I want to open this popup window at right corner of the page (height="700px" width="400px"). How can i achieve this
You can call the following method as:
popUpAtMyWish("yourpage","windownamehere",500,600);
function popUpAtMyWish( pageToLoad, winName, width, height)
{
xposition=0; yposition=0;
if ((parseInt(navigator.appVersion) >= 4 )){
xposition = (screen.width - width);
yposition = (screen.height - height);
}
var args = "";
args += "width=" + width + "," + "height=" + height + ","
+ "location=0,"
+ "menubar=0,"
+ "resizable=0,"
+ "scrollbars=0,"
+ "statusbar=false,dependent,alwaysraised,"
+ "status=false,"
+ "titlebar=no,"
+ "toolbar=0,"
+ "hotkeys=0,"
+ "screenx=" + xposition + "," //NN Only
+ "screeny=" + yposition + "," //NN Only
+ "left=" + xposition + "," //IE Only
+ "top=" + yposition; //IE Only
var dmcaWin = window.open(pageToLoad,winName,args );
dmcaWin.focus();
}

Resources