使用PHP-MyAdmin的SQL PHP多个查询

时间:2015-04-26 15:01:19

标签: php mysql

我遇到了在我的数据库中执行多个查询的问题。每次我只用一行SQL查询数据库时,它就会将数据存储在数据库中。但是当我尝试执行多行查询时,它就成了一个问题。我也试过使用mysqli_multi_query,但仍然没有运气。我甚至试图将SQL语句变成一个字符串,这也没有用。我在下面发布了我的代码,任何帮助将不胜感激。

P.S。这是一个SPA(单页面应用程序)所以如果我被抛出错误,我不能真正做到通常的“回应这个错误”。相反,我只是将错误打印到文件

Connection.php

    <?php

   //File used for connecting to a database

   //Location of the DB
   $dbhost = 'localhost';
   //User name of the DB
   $dbuser = 'root';
   //Password of the DB
   $dbpass ='';
   //Name of the DB
   $db = 'structures';
    // Connection to the database SERVER. Parameters include: Host, User, and Password
   $conn = mysqli_connect($dbhost,$dbuser,$dbpass,$db);
?>

Go2.php

<?php

include 'connection.php';

$firstName = $_POST["firstName"];
$middleName = $_POST["middleName"];
$lastName = $_POST["lastName"];
$NetIDQuest = $_POST["NetIDQuest"];
$NetID = $_POST["NetID"];
$InstQuest = $_POST["InstQuest"];
$Entity = $_POST["Entity"];
$Consulting = $_POST["Consulting"];
$Reimbursed = $_POST["Reimbursed"];
$Royalties = $_POST["Royalties"];
$Equity = $_POST["Equity"];
$PublicQuest = $_POST["PublicQuest"];
$PublicVal = $_POST["PublicVal"];
$SignConfirm = $_POST["SignConfirm"];

$sql = "INSERT INTO user_info(NetID) SELECT NetID from user where NetID = '$NetID';";    // Insert the FK of NetID into the user_signature table before update

$sql. =  "UPDATE user_info SET FirstName = '$firstName', MiddleName = '$middleName', LastName = '$lastName' WHERE NetID = '$NetID';"; //Update the User_Info Table
mysqli_multi_query($conn,$sql) or die (mysql_error());

/*
$sql = "INSERT INTO user_signature(NetID) SELECT NetID from user_info where NetID = '$NetID';";  // Insert the FK of NetID into the user_signature table before update
mysql_query($sql) or die (mysql_error());

$sql = "UPDATE user_signature SET Signature = '$SignConfirm' WHERE NetID = '$NetID';"; // Update the user_signature table
mysql_query($sql) or die (mysql_error());

$sql = "INSERT INTO financial(NetID) SELECT NetID from user_info where NetID = '$NetID';";  
mysql_query($sql) or die (mysql_error());
*/

$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
$txt = mysqli_error($conn);
fwrite($myfile, $txt);
fclose($myfile);


?>

0 个答案:

没有答案