douhuike3199 2015-04-26 15:01
浏览 58

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

I ran into a problem with performing multiple queries in my DB. Each time I query the DB with just a single line of SQL, it stores that data in the DB just fine. But when I try to execute a multi-line query, it becomes a problem. I tried using mysqli_multi_query as well, but still no luck. And I even tried to make the SQL statement into one string, and that also didn't work. I've posted my code below, and any help would be greatly appreciated.

P.S. This is a SPA (Single Paged App) so I cant really do the usual "echo this error out" if I'm getting thrown a error. Instead I'm just having it print the error to a file

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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 BP神经网络控制倒立摆
    • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
    • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
    • ¥30 Unity接入微信SDK 无法开启摄像头
    • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
    • ¥20 cad图纸,chx-3六轴码垛机器人
    • ¥15 移动摄像头专网需要解vlan
    • ¥20 access多表提取相同字段数据并合并
    • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
    • ¥20 Java-Oj-桌布的计算