我在数据库中有8个表,其中7个表我能够成功插入数据, 在那里使用相同的语法,但无法将数据插入到最后一个。
我尝试显示传递的值并且它们都是正确的,
我尝试通过mysql workbench手动将值输入数据库,再次更正
php代码:
<?php
require "con.php";
$user_name = $_POST["email"];
$user_password = $_POST["password"];
$encrypted_password = md5($user_password);
$firstname = $_POST["firstname"];
$middlename = $_POST["middlename"];
$lastname = $_POST["lastname"];
$employer = $_POST["employer"];
$designation = $_POST["designation"];
$department = $_POST["department"];
$dob = $_POST["DOB"];
$birthplace = $_POST["birthplace"];
$nationality = $_POST["nationality"];
$gender = $_POST["gender"];
$currentaddress = $_POST["curraddr"];
$permanentaddress = $_POST["permaddr"];
$state = $_POST["state"];
$country = $_POST["country"];
$cityofpref = $_POST["cityofpref"];
$phone = $_POST["phone"];
$mobile = $_POST["mobile"];
$website = $_POST["website"];
$totalexperience = $_POST["experience"];
$workdescription = $_POST["workdesc"];
$twitter = $_POST["twitter"];
$facebook = $_POST["facebook"];
$skype = $_POST["skype"];
$linkedin = $_POST["linkedin"];
$researchgate = $_POST["researchgate"];
$googlescholar = $_POST["googlescholar"];
$status = $_POST["Status"];
$UG1 = $_POST["UG1"];
$UG2 = $_POST["UG2"];
$UG3 = $_POST["UG3"];
$PG1 = $_POST["PG1"];
$PG2 = $_POST["PG2"];
$PG3 = $_POST["PG3"];
$PHD1 = $_POST["PHD1"];
$PHD2 = $_POST["PHD2"];
$PHD3 = $_POST["PHD3"];
$others1 = $_POST["others1"];
$others2 = $_POST["others2"];
$others3 = $_POST["others3"];
$BroadArea = $_POST["BroadArea"];
$MajorArea = $_POST["MajorArea"];
$MinorArea = $_POST["MinorArea"];
$mysql_qry5 = "Insert into Faculty_Webpresence (Faculty_ID, TwitterID, SeobusID, LinkedinID, Skype_ID, Facebook_ID, GoogleScholarID) values
('$last_id','$twitter','$researchgate','$linkedin','$skype','$facebook','$googlescholar');";
if(mysqli_query($conn, $mysql_qry5))
{
echo " .5";
}
else
{
echo " '5";
}
$mysql_qry6 = "Insert into Faculty_Contact (Faculty_ID, PersonalEmail, OfficialEmail, CurrentAddress, PermanentAddress, Website, Phone, Mobile) values
('$last_id', '$user_name', '$user_name', '$currentaddress', '$permanentaddress', '$website', '$phone', '$mobile');";
if(mysqli_query($conn, $mysql_qry6))
{
echo " .6";
}
else
{
echo " '6";
}
$mysql_qry7 = "Insert into Faculty_Academia (Faculty_ID, UndergraduateUniversity, UndergraduateDiscipline, PostgraduateUniversity, PostgraduateDiscipline, DoctorateUniversity, DoctoratezDiscipline) values ('$last_id', '$UG2', '$UG1', '$PG2', '$PG1', '$PHD2', '$PHD1');";
if(mysqli_query($conn, $mysql_qry7))
{
echo " .7 ";
echo $last_id, $cityofpref, $BroadArea, $MajorArea, $MinorArea,$workdescription;
}
else
{
echo " '7";
echo $last_id, $cityofpref, $BroadArea, $MajorArea, $MinorArea,$workdescription;
}
$mysql_qry8 = "Insert into Faculty_Interest (Faculty_ID, StateofchoicecityinIndia, BroadArea, MajorArea, MinorArea, InterestDescription) values
('$last_id', '$cityofpref', '$BroadArea', '$MajorArea', '$MinorArea', '$workdescription');";
if(mysqli_query($conn, $mysql_qry8))
{
echo " .8";
}
else
{
echo " '8";
}
?>
con.php:
<?php
$db_name = "FacultyDB";
$mysql_username = "root";
$mysql_password = "<password>";
$server_name = "127.0.0.1";
$conn = mysqli_connect($server_name, $mysql_username, $mysql_password, $db_name);
if($conn)
{
echo "1 ";
}
else
{
echo "0 ";
}
?>
java代码:
String login_url = "http://127.0.0.1/signup.php";
URL url = new URL(login_url);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true);
OutputStream outputStream = httpURLConnection.getOutputStream();
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
String post_data = URLEncoder.encode("email", "UTF-8") +"="+URLEncoder.encode(email, "UTF-8")+"&"
+URLEncoder.encode("password", "UTF-8") +"="+URLEncoder.encode(password, "UTF-8")+"&"
+URLEncoder.encode("firstname", "UTF-8") +"="+URLEncoder.encode(params[3], "UTF-8")+"&"
+URLEncoder.encode("middlename", "UTF-8") +"="+URLEncoder.encode(params[4], "UTF-8")+"&"
+URLEncoder.encode("lastname", "UTF-8") +"="+URLEncoder.encode(params[5], "UTF-8")+"&"
+URLEncoder.encode("employer", "UTF-8") +"="+URLEncoder.encode(params[6], "UTF-8")+"&"
+URLEncoder.encode("designation", "UTF-8") +"="+URLEncoder.encode(params[7], "UTF-8")+"&"
+URLEncoder.encode("department", "UTF-8") +"="+URLEncoder.encode(params[8], "UTF-8")+"&"
+URLEncoder.encode("DOB", "UTF-8") +"="+URLEncoder.encode(params[9], "UTF-8")+"&"
+URLEncoder.encode("birthplace", "UTF-8") +"="+URLEncoder.encode(params[10], "UTF-8")+"&"
+URLEncoder.encode("nationality", "UTF-8") +"="+URLEncoder.encode(params[11], "UTF-8")+"&"
+URLEncoder.encode("gender", "UTF-8") +"="+URLEncoder.encode(params[12], "UTF-8")+"&"
+URLEncoder.encode("curraddr", "UTF-8") +"="+URLEncoder.encode(params[13], "UTF-8")+"&"
+URLEncoder.encode("permaddr", "UTF-8") +"="+URLEncoder.encode(params[14], "UTF-8")+"&"
+URLEncoder.encode("state", "UTF-8") +"="+URLEncoder.encode(params[15], "UTF-8")+"&"
+URLEncoder.encode("country", "UTF-8") +"="+URLEncoder.encode(params[16], "UTF-8")+"&"
+URLEncoder.encode("cityofpref", "UTF-8") +"="+URLEncoder.encode(params[17], "UTF-8")+"&"
+URLEncoder.encode("phone", "UTF-8") +"="+URLEncoder.encode(params[18], "UTF-8")+"&"
+URLEncoder.encode("mobile", "UTF-8") +"="+URLEncoder.encode(params[19], "UTF-8")+"&"
+URLEncoder.encode("website", "UTF-8") +"="+URLEncoder.encode(params[20], "UTF-8")+"&"
+URLEncoder.encode("experience", "UTF-8") +"="+URLEncoder.encode(params[21], "UTF-8")+"&"
+URLEncoder.encode("workdesc", "UTF-8") +"="+URLEncoder.encode(params[22], "UTF-8")+"&"
+URLEncoder.encode("twitter", "UTF-8") +"="+URLEncoder.encode(params[23], "UTF-8")+"&"
+URLEncoder.encode("facebook", "UTF-8") +"="+URLEncoder.encode(params[24], "UTF-8")+"&"
+URLEncoder.encode("skype", "UTF-8") +"="+URLEncoder.encode(params[25], "UTF-8")+"&"
+URLEncoder.encode("linkedin", "UTF-8") +"="+URLEncoder.encode(params[26], "UTF-8")+"&"
+URLEncoder.encode("researchgate", "UTF-8") +"="+URLEncoder.encode(params[27], "UTF-8")+"&"
+URLEncoder.encode("googlescholar", "UTF-8") +"="+URLEncoder.encode(params[28], "UTF-8")
+URLEncoder.encode("Status", "UTF-8") +"="+URLEncoder.encode(params[29], "UTF-8")+"&"
+URLEncoder.encode("UG1", "UTF-8") +"="+URLEncoder.encode(params[30], "UTF-8")+"&"
+URLEncoder.encode("UG2", "UTF-8") +"="+URLEncoder.encode(params[31], "UTF-8")+"&"
+URLEncoder.encode("UG3", "UTF-8") +"="+URLEncoder.encode(params[32], "UTF-8")+"&"
+URLEncoder.encode("PG1", "UTF-8") +"="+URLEncoder.encode(params[33], "UTF-8")+"&"
+URLEncoder.encode("PG2", "UTF-8") +"="+URLEncoder.encode(params[34], "UTF-8")+"&"
+URLEncoder.encode("PG3", "UTF-8") +"="+URLEncoder.encode(params[35], "UTF-8")+"&"
+URLEncoder.encode("PHD1", "UTF-8") +"="+URLEncoder.encode(params[36], "UTF-8")+"&"
+URLEncoder.encode("PHD2", "UTF-8") +"="+URLEncoder.encode(params[37], "UTF-8")+"&"
+URLEncoder.encode("PHD3", "UTF-8") +"="+URLEncoder.encode(params[38], "UTF-8")+"&"
+URLEncoder.encode("others1", "UTF-8") +"="+URLEncoder.encode(params[39], "UTF-8")+"&"
+URLEncoder.encode("others2", "UTF-8") +"="+URLEncoder.encode(params[40], "UTF-8")+"&"
+URLEncoder.encode("others3", "UTF-8") +"="+URLEncoder.encode(params[41], "UTF-8")+"&"
+URLEncoder.encode("BroadArea", "UTF-8") +"="+URLEncoder.encode(params[42], "UTF-8")+"&"
+URLEncoder.encode("MajorArea", "UTF-8") +"="+URLEncoder.encode(params[43], "UTF-8")+"&"
+URLEncoder.encode("MinorArea", "UTF-8") +"="+URLEncoder.encode(params[44], "UTF-8");
bufferedWriter.write(post_data);
bufferedWriter.flush();
bufferedWriter.close();
outputStream.close();
InputStream inputStream = httpURLConnection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1"));
String result="";
String line="";
while((line = bufferedReader.readLine())!=null)
{
result+=line;
}
bufferedReader.close();
inputStream.close();
httpURLConnection.disconnect();
return result;
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
答案 0 :(得分:-1)
您的查询语法错误:
$ mysql_qry5 =“插入Faculty_Webpresence (Faculty_ID,TwitterID,SeobusID,LinkedinID,Skype_ID,Facebook_ID,GoogleScholarID) 值( '$ last_id', '$叽叽喳喳', '$研究之门', '$ LinkedIn', '$ Skype的', '$ Facebook的', '$ Google学术搜索');“;
删除';''分号和结束引号,然后尝试