2017-06-02 57 views
0

的插入數據我在數據庫表8,其中7,我能夠使用相同的語法有成功插入數據, ,但無法將數據插入到最後一個。儘管無法正確語法

我試圖顯示正在傳遞的值,並且它們是正確的,

我試圖通過MySQL工作臺輸入值到數據庫中手動,再次正確

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(); 
      } 
+1

查看關於parametrised查詢立即 – Strawberry

+0

MD5是不夠的密碼哈希使用['password_hash()'](HTTP:!//us3.php達網絡/手動/ EN/function.password-hash.php)和['password_verify()'](http://us3.php.net/manual/en/function.password-verify.php)來代替。 –

回答

-1

查詢有語法錯誤:

$ mysql_qry5 =「INSERT INTO Faculty_Webpresence (Faculty_ID,TwitterID,SeobusID,LinkedinID,Skype_ID,Facebook_ID,GoogleScholarID) VALUES( '$ last_id','$ Twitter的」, '$研究之門', '$ LinkedIn', '$ Skype的', '$ Facebook的', '$ Google學術搜索');「;

刪除 ';「' 分號和收盤價,並嘗試

+0

其不是語法錯誤 –

+0

好吧,它不是一個語法錯誤,那麼你能解釋我嗎? –