1
  1. Summarize the problem

After sign in using the username = user, I want to update the id_team field in the tb_user table by sending user id = id, username = update to the data.

by sending id user = id, username = user. From the team management page. But the team management from the tb_team table. tb_team table has no data, id user = id, username = user. For use in the update

How to get or keep the session id user = id, username = user for use in conditions, the update, I want advice about this problem.

  1. Provide background including what you've already tried
var saveidUser: String?
saveidUser  = ????   <——  I do not know how to send the  id, username
  1. Show some code PHP code:
//Web Service
if (isset($_GET)) {
    if ($_GET['isAdd'] == 'true') {
        $idTeam = $_GET['idteam'];
        $idUser = $_GET['iduser']
        $User = $_GET['username'];

        UPDATE `tb_user` SET `id_team` = '$idTeam' WHERE `id` = '$iduser' and `username` = '$user'
        $result = mysqli_query($sql) or die mysql_error();
        if ($result) {
          echo $idTeam;
        } else {
          echo "False";
        }
    } 
    else echo "Welcome";
}

Swift code:

//swift code constant
class Myconstant {
    func findURLSaveidTeam(idTeam: String, idUser: String) -> String {
        let urlGetidTeam = "http://www.test.com/myWebService/updateidTeam.php?isAdd=true&idteam=\(idTeam)&iduser=\(idUser)"
        return urlGetidTeam
    }
}//My Constant

//swift code view controller management team
class getAllTeamViewController: UIViewController {
    var selectValue: String?
    var saveidTeam: String?
    var saveidUser: String?  <— for id, username

    @IBOutlet weak var hiddenidTeamTextField: UITextField!
    @IBOutlet weak var showSelectValuePickerView: UITextField!

    func saveValue(idteam: String, iduser: String ) -> Void {
        let myconstant_idTeam = Myconstant()
        let urlSaveData: String = myconstant_idTeam.findURLSaveidTeam(idTeam: idteam, idUser: iduser)
        print("urlSaveData ==>\(urlSaveData)")
        //Save Value Process
        let url = URL(string: urlSaveData)!
        let request = NSMutableURLRequest(url: url) 
        let task = URLSession.shared.dataTask(with: request as URLRequest){ data,response, error in
            //Check nil value
            if error != nil {
                print("Error! Have nil value")
            }else{
                //Receive Value
                if let responseData = data {
                    let canReadData = NSString(data: responseData, encoding: String.Encoding.utf8.rawValue)
                    print("Can Read Data ==> \(String(describing: canReadData))")

                    //Show alert save success or failed upload to database on log panel
                    let myResponse = canReadData
                    if((myResponse) != nil){
                      print("Save Success")
                    }else{
                      print("Cannot Upload")
                    }//if
                }//if
            }//if
        }//End task
        task.resume()
    }//saveValue

    //Save Button
    @IBAction func SavevaluePicker(_ sender: UIButton) {
        selectValue = showSelectValuePickerView.text
        saveidTeam = hiddenidTeamTextField.text
        saveidUser  = ????   <——  I do not know how to send the  id,username

        //Call use function checkSpace
        if(checkSpace(picker: selectValue!)){
            print("Have Space")
        }else{
            print("No Space")
            //Call function Save data to database
            saveValue(idteam: saveidTeam!, iduser: saveidUser!)
        }//if
    }// SavevaluePicker
}//Main Class
  1. Describe expected and actual results including any error messages Value from show log panel
     NameTeam database ==>2 - AvengersEndgame
  1. Image team management page

enter image description here

1 Answers1

0

You need to start the session at the time of login success. after successful login, define a session variable by giving it the value of user id. and make a check in the start of the page that either session variable is created or not if the session variable is not created then redirect to login page else redirect to your desired page.

At the time of logout, you need to undefine the session variable.