I am trying to have multiple SQL queries fire off on one summit, One that updates a form and one that updates a space in the db for a file ext so that image can be echoed out. I had it fire on a separate "post" BTN and that worked but, now that I am trying to ""combined queries I get undefined index for the info for my file. So the overall FM of this problem is to update all these records and then once that this done it will move a copy of the uploaded image to a folder and then foreach "customer " there will be a space in the db for a specific image to be assigned to them.
<?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();
?>
I have this and want to combined it with this
$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();
I get undefined index for image. I want to have this all go when if (!empty($_POST['customerID']))
because as of right now that image uploader sits in its own form and has its own "submit" it waits for.So I want to have the image uploader
<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>
This above is what the uploader looks like I know I would have to get rid of the action and (All the php sits at the top of the html form where it garbs all the rest of the data)