一次提交多个sql语句

时间:2019-05-07 20:54:23

标签: php html sql post

我正在尝试在一个首脑会议上触发多个SQL查询,一个高峰会议更新一个表单,另一个高峰会议在db中更新文件ext的空间,以便可以回显图像。我在一个单独的“ post” BTN上启动它,并且可以正常工作,但是,现在,我尝试“组合查询”,但未获取文件信息的索引。因此,此问题的总体FM是更新所有这些记录,然后完成此操作后,它将把上载图像的副本移动到文件夹中,然后对于每个“客户”,数据库中将有一个空间用于特定图像被分配给他们。

<?php

    $servername = "localhost";
    $username = "root";
    $password = "";
    $dbname = "techfusioncustomers";

    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);

    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }

    // Get the customer ID.
    $customerId = intval($_GET['id']);

    // If form was submitted, update the customer.
    if (!empty($_POST['customerID'])) {

        $customerUpdated = true;

        $sql = "UPDATE customers
            SET
                address = ?,
                bPhone = ?,
                city = ?,
                companyName = ?,
                cPhone = ?,
                customerStatus = ?,
                email = ?,
                faxNumber = ?,
                firstName = ?,
                gradDate = ?,
                howDidYouHear = ?,
                hPhone = ?,
                isCustTaxExempt = ?,
                lastName = ?,
                leadRating = ?,
                leadServiceIntrest = ?,
                leadSource = ?,
                leadStatus = ?,
                Ext = ?,
                state = ?,
                studentStatus = ?,
                zip = ?
            WHERE customerID = ?";

        $stmt = $conn->prepare($sql);

        if ($stmt === false) {
            die($conn->error);
        }

        $stmt->bind_param(
            'ssssssssssssssssssssssi',
            $_POST['address'],
            $_POST['bPhone'],
            $_POST['city'],
            $_POST['companyName'],
            $_POST['cPhone'],
            $_POST['customerStatus'],
            $_POST['email'],
            $_POST['faxNumber'],
            $_POST['firstName'],
            date("Y-m-d", strtotime($_POST['gradDate'])),
            $_POST['howDidYouHear'],
            $_POST['hPhone'],
            $_POST['isCustTaxExempt'],
            $_POST['lastName'],
            $_POST['leadRating'],
            $_POST['leadServiceIntrest'],
            $_POST['leadSource'],
            $_POST['leadStatus'],
            $_POST['Ext'],
            $_POST['state'],
            $_POST['studentStatus'],
            $_POST['zip'],
            $_POST['customerID']
        );

        $stmt->execute();

        if ($stmt->error) {
            die($stmt->error);
        }

        $stmt->close();
    }

        /

    / Load the customer.
            $result = $conn->query("SELECT * FROM customers WHERE customerID = {$customerId}") or die($conn->error);
            $customer = $result->fetch_assoc();

            $conn->close();



    ?>

我有这个,想与这个结合

$servername = "localhost";
    $username = "root";
    $password = "";
    $dbname = "techfusioncustomers";

    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);

    $msg = "";
    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }

    // Get the customer ID.
    $customerId = $_POST['customerId'];
    $image = $_FILES['image']['name'];
    $image_text = mysqli_real_escape_string($conn, $_POST['image_text']);
    $target = "images/" . basename($image);

    // If form was submitted, update the customer.
    if (isset($_POST['upload'])) {

        $sql = "UPDATE customers set image = '$image', image_text = 
        '$image_text' 
                 where customerID = '$customerId'";

        mysqli_query($conn, $sql) or die(mysqli_error($conn));

        $query = mysqli_query($conn, $sql);

        if (!$query){
            exit("file could not be moved");
        }

        if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) {
          echo  $msg = "Image uploaded successfully";
        } else {
           echo $msg = "Failed to upload image";
        }
    }

    // Load the customer.
    $result = $conn->query("SELECT * FROM customers WHERE customerID = 
    {$customerId}") or die($conn->error);
    $customer = $result->fetch_assoc();

    $conn->close();

我获得了图像的未定义索引。我想在(!empty($_POST['customerID']))的情况下全部使用,因为截至目前该图像上传器以其自己的形式放置并等待其自己的“提交”。所以我想要一个图像上传器

<form method="POST" action="test.php" enctype="multipart/form-data">
            <input type='hidden' name='customerId' value='<?= $customerId 
             ?>'>

            <div>
                <input type="file" name="image">
            </div>
            <div>
                <textarea id="text" cols="40" rows="4" name="image_text" placeholder="Say something about this image..."></textarea>
            </div>
            <div>
                <button type="submit" name="upload">POST</button>
            </div>

        </form>

以上是上载器的外观,我知道我必须摆脱该操作,并且(所有php都位于html表单的顶部,在其中乱写所有其他数据)

0 个答案:

没有答案