2020年12月21日星期一

Is there a way to use two queries in php for mysql?

I think I need two queries for getting data from the database in the php. What I want is to get some data in the beginning and check the data of the database and get more data if the data on the database is specific.

<?php        $serverAddress = "localhost";      $dbName = "something";      $dbUserName = "something";      $dbUserPass = "someone";      $conn = new mysqli($serverAdd, $dbUserName, $dbUserPass, $dbName);      if ($conn->connect_error) {die('error');}              $accountNo = $_POST['accountNo'];      $source = $_POST['source'];      $password = $_POST['password'];            if (!$source == ""){          $sql = 'SELECT * FROM table1 WHERE accountNo="'.$accountNo.'"';          $result = mysqli_query($conn, $sql);          $row = mysqli_fetch_assoc($result);          $dbAccountNo = $row['accountNo'];          $dbPassword = $row['password'];          $passwordMatched = password_verify($password, $dbPassword);                if ($passwordMatched){              if ($condition1 == "no"){                  //Add token to the database start!                  $stringContains = "abcdefghijklmnopqrstuvwxyz1234567890";                  $stringKey = substr(str_shuffle($tokenContains), 0, $tokenLength);                  $stringSql = 'INSERT INTO `table2` (`stringNo`, `stringKey`, `accountNo`) VALUES (NULL, "'.$stringKey.'", '.$accountNo.')';                  $mysql2query = mysqli_query($conn, $stringSql);                                  if ($mysql2query) {                      $stringNo = mysqli_insert_id($conn);                      echo "data added";                  }else{                      $connectionError = mysqli_error($conn);                      echo "connection error";                  }              }          }                }    ?>    

I don't know if I can use the mySqli_query on this condition or I should use mysqli_multi_query in this context. Also, I want to know if there is/are some dis/advantage of using mysqli_query and/or mysqli_multi_query over one another.

https://stackoverflow.com/questions/65396241/is-there-a-way-to-use-two-queries-in-php-for-mysql December 22, 2020 at 12:16AM

没有评论:

发表评论