About ajax, an exception is reported, but null is inserted in mysql.

Source: Internet
Author: User
About ajax, an exception is reported, but null is inserted in mysql.
 












  • Homepage

  • Contact a Foreman

  • Odd Job Market

  • Bidding Platform

  • Personal Center




Script


Function isMobile (a) // verify the mobile phone number
{
Var reg =/^ (13 | 15 | 18 | 17) [0-9] {9} $/; // regular expression
Return reg. test ();
}

$ ('# Btn_submit'). click (function (){
// Xm xb sjhm jtdz gzlb cysj gzqy note
Var xm = $ ("# xm"). val ();
// Alert (xm );


If (xm = '')
{
$ ("# Msg" cmd.html ('No Name filled! ');
Return false;
}

Var xb = $ ("# xb"). val ();
If ($ (": radio: checked"). length = 0)
{
$ ("# Msg" ).html ('no sex is selected! ');
Return false;
}

Var sjhm = $ ("# sjhm"). val ();
If (isMobile (sjhm) = false)
{
$ ("# Msg" 2.16.html ('no mobile phone number filled in! ');
Return false;
}

Var jtdz = $ ("# jtdz"). val ();
If (jtdz = '')
{
$ ("# Msg" ).html ('home address not filled! ');
Return false;
}

Var gzlb = document. getElementById ("gzlb"). value; // selectid
// Var index = obj. selectedIndex; // select the index
// Var text = obj. options [index]. text; // select the text
// Var value = obj. options [index]. value; // The selected value.
If (gzlb = "0 ")
{
$ ("# Msg" ).html ('select a type of work! ');
Return false;
}
// Alert (obj );

Var cysj = $ ("# cysj"). val ();
If (cysj = '')
{
$ ("# Msg" pai.html ('no time selected for employment! ');
Return false;
}

Var gzqy = document. getElementById ("gzqy"). value;
If (gzqy = '0 ')
{
$ ("# Msg" ).html ('select the work area! ');
Return false;
}

Var note = $ ("# note"). val ();
If (note = '')
{
$ ("# Msg" ).html ('self-introduction is not entered! ');
Return false;
}


$. Ajax ({
Url: "./index_c.php ",
Type: "POST ",
Data: {"xm": xm, "xb": xb, "sjhm": sjhm, "jtdz": jtdz, "gzlb": gzlb, "cysj": cysj, "gzqy": gzqy, "note": note },
DataType: "json ",
Async: false,
Success: function (){
// Alert ('success ');
If (error = 0)
{
$ ("# Btn_submit"). attr ("disabled", "disabled ");
$ ("# Btn_submit" ).css ({"background": "#0000000 "});
$ ("# Msg" cmd.html ('submission successful! ');
}
Else {
$ ("# Msg" cmd.html (msg );
}
},
Error: function (){
Alert ('error ');
// $ ("# Msg" cmd.html ("submit exception! ");
}

});

Return false;
});


Script
This is all the code. please help me check it.


Reply to discussion (solution)

Data: {"xm": xm, "xb": xb, "sjhm": sjhm, "jtdz": jtdz, "gzlb": gzlb, "cysj": cysj, "gzqy": gzqy, "note": note },
None of the variables used in!

DataType: "json ",
Require the server to return json data

Data: {"xm": xm, "xb": xb, "sjhm": sjhm, "jtdz": jtdz, "gzlb": gzlb, "cysj": cysj, "gzqy": gzqy, "note": note },
None of the variables used in!

DataType: "json ",
Require the server to return json data


 200) {// throw new Exception ("self-introduction exceeds 200 characters! "); $ Data = array (" error "=> 1," msg "=>"
 <自我介绍>
  
The ". strlen ($ note)." character is entered. it exceeds 200 characters! "); Echo json_encode ($ data); exit;} * // * if (isset ($ _ POST ['xm ']) {$ xm = trim ($ _ POST ['xm ']); // check forms filled inif (empty ($ xm) {echo'
  

The user name must be entered. '.' enter it again and return
'; Exit ;}} */$ date = date ("Y-m-d H: I: s"); $ conn = mysql_connect ("localhost", "root ", "123456"); mysql_select_db ("test", $ conn); mysql_query ("set names 'utf8'"); $ SQL = "SELECT count (1) as RecordCount FROM fhzj where sjhm = '$ sjhm' "; $ result = mysql_query ($ SQL); if ($ result) {$ row = mysql_fetch_assoc ($ result ); $ recordCount = $ row ['recordcount']; if ($ RecordCount> 0) {$ data = array ("error" => 1, "msg" => "The mobile phone number already exists! "); Echo json_encode ($ data); exit ;}} else {$ data = array (" error "=> 1," msg "=> mysql_error ()); echo json_encode ($ data); exit;} $ SQL = "INSERT INTO 'fhzj' ('xm ', 'xb', 'sjhm ', 'jtdz', 'gzlb ', 'cys1', 'gzqy', 'note') "; $ SQL = $ SQL. "values ('xm ', 'xb', 'sjhm ', 'jtdz', 'gzlb', 'cys1', 'gzqy', 'note ')"; $ result = mysql_query ($ SQL, $ conn); if (! $ Result) {$ data = array ("error" => 1, "msg" => mysql_error (); echo json_encode ($ data ); throw new Exception ("Exception :". mysql_error (); // throw new Exception ($ SQL);} else {$ data = array ("error" => 0, "msg" => "submitted successfully"); echo json_encode ($ data);} $ data = array ("error" => 0, "msg" => "submitted successfully"); echo json_encode ($ data);} catch (Exception $ ex) {$ data = array ("error" => 1, "msg" = >$ ex-> getMessage (); echo json_encode ($ data) ;}?>

Set
Data: {"xm": xm, "xb": xb, "sjhm": sjhm, "jtdz": jtdz, "gzlb": gzlb, "cysj": cysj, "gzqy": gzqy, "note": note}
Check whether there is a value in the output.

Let's look at your SQL statement.

$ SQL = "INSERT INTO 'fhzj' ('xm ', 'xb', 'sjhm ', 'jtdz', 'gzlb', 'cys1', 'gzqy ', 'note ')";
$ SQL = $ SQL. "values ('xm ', 'xb', 'sjhm ', 'jtdz', 'gzlb', 'cys1', 'gzqy', 'note ')";

No value is assigned to your values.

Data: {"xm": xm, "xb": xb, "sjhm": sjhm, "jtdz": jtdz, "gzlb": gzlb, "cysj": cysj, "gzqy": gzqy, "note": note },
None of the variables used in!

DataType: "json ",
Require the server to return json data


This is my PHP code. Where should I assign a value? sorry, it's not very good for me to enter the line. please explain it.

$ SQL = "INSERT INTO 'fhzj' ('xm ', 'xb', 'sjhm ', 'jtdz', 'gzlb', 'cys1', 'gzqy ', 'note ')";
$ SQL = $ SQL. "values ('xm ', 'xb', 'sjhm ', 'jtdz', 'gzlb', 'cys1', 'gzqy', 'note ')";

No value is assigned to your values.


Should I write this?
var "xm" = xm

Sorry, I'm Tom.

$ SQL = $ SQL. "values ('xm ', 'xb', 'sjhm ', 'jtdz', 'gzlb', 'cys1', 'gzqy', 'note ')"; change to $ SQL = $ SQL. "values ('$ xm')"; // and so on

$ SQL = $ SQL. "values ('xm ', 'xb', 'sjhm ', 'jtdz', 'gzlb', 'cys1', 'gzqy', 'note ')"; change to $ SQL = $ SQL. "values ('$ xm')"; // and so on


I should have assigned a value in the previous judgment.

$ SQL = $ SQL. "values ('xm ', 'xb', 'sjhm ', 'jtdz', 'gzlb', 'cys1', 'gzqy', 'note ')"; change to $ SQL = $ SQL. "values ('$ xm')"; // and so on


Still unable to prompt error

You can add {} on both sides of the variable you want to use, because {variable} in double quotation marks can be parsed.

You can add {} on both sides of the variable you want to use, because {variable} in double quotation marks can be parsed.


Can you give an example?


You can add {} on both sides of the variable you want to use, because {variable} in double quotation marks can be parsed.


Can you give an example?


$ SQL = "insert into table name (the field name you want to use) values ('{$ xm}', '{$ xb}', '{$ sjhm }', '{$ jtdz}', '{$ gzlb}', '{$ cysj}', '{$ gzqy}', '{$ note }')";
In this way, you can try to output $ SQL to see if the variable parsing in double quotation marks does not exist.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.