1. 程式人生 > 實用技巧 >vue配合php上傳資料

vue配合php上傳資料

submit() {
      var params= new URLSearchParams();           //!!!
      params.append("text",this.textarea);
      this.$axios
        .post("http://tjks.tjslkj.net/text.php", params)
        .then(this.hand)
        .catch((err) => {
          console.log(`${err}`);
        });
    },

php

<?php
//處理登入操作 $text=$_POST['text']; // $username=123456; // $password=$_POST['password']; //連線 echo"<script> alert($text.text); </script>"; $link=mysqli_connect('localhost','root','ogMLZ1RU7T48qu2o'); //設定編碼方式 mysqli_query($link,'SET NAMES UTF8'); //開啟指定的資料庫 mysqli_select_db($link,'feedback');
//執行SQL語句 // $sql1="INSERT user(username,phone) // VALUES('$username','$password')"; $sql = "INSERT INTO `feed` (`id`, `feedpack`) VALUES (NULL, '{$text}')"; // $sql="SELECT * FROM user1 WHERE username='{$username}' AND password='{$password}'"; //echo $sql; $result = mysqli_query($link,$sql); //var_dump($result);
//得到結果集中的記錄條數mysqli_num_rows($result) //echo mysqli_num_rows($result); if($result){ // if($link){ // location.href='http://www.baidu.com';; echo "<script> alert('提交成功'+json_encode($text)); </script>"; }else{ // location.href='text.php'; echo "<script> alert('提交失敗'); </script>"; }

uniapp 還沒拿下,怎麼好意思休息