输入未提交到数据库[重复]

问题描述 投票:-1回答:1
我有一个带有表单输入字段和3个图像文件字段的HTML FORM。我想将所有表单数据插入到我的SETTINGS_TBL中(文本输入和图像)。对于图像,我想将其名称存储到其各自的“数据库”列中,然后将主图像上传到图像文件夹中。

上载效果很好-图像被保存到IMAGES文件夹中。但是问题是:什么都没有提交到数据库中。也许我做的不对。我经历了一些相关的答案,但没有一个回答我的问题

// HTML格式代码//

<?php //Select School Details $selectSchoolInfo = mysqli_query($GLOBALS['dbconn'], "SELECT * FROM settings_tbl"); $schoolInfoRow = mysqli_fetch_array($selectSchoolInfo); ?> <form action="update-school-settings.php" method="POST" class="general-settings-form" id="general-settings-form" role="form" enctype="multipart/form-data"> <div class="form-group"> <label>School Name</label> <input type="text" class="form-control" id="school-name" name="school-name" value="<?php echo $schoolInfoRow['school_name']; ?>" required /> </div> <div class="form-group"> <label>School Addess</label> <input type="text" class="form-control" id="school-address" name="school-address" value="<?php echo $schoolInfoRow['school_address']; ?>" required /> </div> <div class="row"> <div class="col col-sm-6 col-md-6"> <div class="form-group"> <label>School Phone #1</label> <input type="text" class="form-control" id="school-phone1" name="school-phone1" value="<?php echo $schoolInfoRow['school_phone1']; ?>" required /> </div> </div> <div class="col col-sm-6 col-md-6"> <div class="form-group"> <label>School Phone #2</label> <input type="text" class="form-control" id="school-phone2" name="school-phone2" value="<?php echo $schoolInfoRow['school_phone2']; ?>" required /> </div> </div> </div> <div class="form-group"> <label>School Email</label> <input type="email" class="form-control" id="school-email" name="school-email" value="<?php echo $schoolInfoRow['school_email']; ?>" required /> </div> <div class="form-group"> <label>Our Mission</label> <textarea class="form-control" id="mission" name="mission" rows="5" value="<?php echo $schoolInfoRow['school_mission']; ?>" required></textarea> </div> <div class="form-group"> <label>Our Vision</label> <textarea class="form-control" id="vision" name="vision" rows="5" value="<?php echo $schoolInfoRow['school_vision']; ?>" required></textarea> </div> <div class="row"> <div class="col-md-6"> <div class="form-group"> <label>Header Logo</label> <div class="custom-file"> <input type="file" class="custom-file-input" id="customFile" name="header-logo"> <label class="custom-file-label" for="customFile">Choose file</label> </div> </div> </div> <div class="col-md-6 center-block mt-4"> <div class="logo-div" id="logo-div"> <?php if (isset($schoolInfoRow['header_logo']) && !empty($schoolInfoRow['header_logo'])): ?> <img src="uploads/images/<?php echo $schoolInfoRow['header_logo']; ?>" alt="Image" class="img-fluid"> <?php else: ?> <img src="uploads/images/marker.png" class="img-fluid logo" id="logo" /> <?php endif; ?> </div> </div> </div> <div class="row"> <div class="col-md-6"> <div class="form-group"> <label>Footer Logo</label> <div class="custom-file"> <input type="file" class="custom-file-input" id="customFile" name="footer-logo"> <label class="custom-file-label" for="customFile">Choose file</label> </div> </div> </div> <div class="col-md-6 center-block mt-4"> <div class="logo-div" id="logo-div"> <?php if (isset($schoolInfoRow['footer_logo']) && !empty($schoolInfoRow['footer_logo'])): ?> <img src="uploads/images/<?php echo $schoolInfoRow['footer_logo']; ?>" alt="Image" class="img-fluid"> <?php else: ?> <img src="uploads/images/marker.png" class="img-fluid logo" id="logo" /> <?php endif; ?> </div> </div> </div> <div class="row"> <div class="col-md-6"> <div class="form-group"> <label>Favicon</label> <div class="custom-file"> <input type="file" class="custom-file-input" id="customFile" name="favicon"> <label class="custom-file-label" for="customFile">Choose file</label> </div> </div> </div> <div class="col-md-6 center-block mt-4"> <div class="logo-div" id="logo-div"> <?php if (isset($schoolInfoRow['favicon']) && !empty($schoolInfoRow['favicon'])): ?> <img src="uploads/images/<?php echo $schoolInfoRow['favicon']; ?>" alt="Image" class="img-fluid"> <?php else: ?> <img src="uploads/images/marker.png" class="img-fluid logo" id="logo" /> <?php endif; ?> </div> </div> </div> <div class="form-group"> <button type="submit" class="btn btn-dark rounded-button" id="save" name="save">Save <i class="icon-save"></i></button> </div> </form>

// PHP代码///

<?php session_start(); // require 'processes.php'; require '../incs/database/dbconfig.php'; $valid_extensions = array('jpeg', 'jpg', 'png', 'gif', 'ico'); if (isset($_POST['save'])) { $school_name = trim($_POST['school-name']); $school_address = trim($_POST['school-address']); $school_phone1 = trim($_POST['school-phone1']); $school_phone2 = trim($_POST['school-phone2']); $school_email = trim($_POST['school-email']); $school_mission = trim($_POST['mission']); $school_vision = trim($_POST['vision']); $header_logo = $_FILES['header-logo']['name']; $footer_logo = $_FILES['footer-logo']['name']; $favicon = $_FILES['favicon']['name']; // material file directory $target4Header = "uploads/images/".basename($header_logo); // material file directory $target4Footer = "uploads/images/".basename($footer_logo); // material file directory $target4Favicon = "uploads/images/".basename($favicon); // get the file extension $extension4Header = pathinfo($header_logo, PATHINFO_EXTENSION); // get the file extension $extension4Footer = pathinfo($footer_logo, PATHINFO_EXTENSION); // get the file extension $extension4Favicon = pathinfo($favicon, PATHINFO_EXTENSION); $header_file = $_FILES['header-logo']['tmp_name']; $footer_file = $_FILES['footer-logo']['tmp_name']; $favicon_file = $_FILES['favicon']['tmp_name']; if (in_array($extension4Header, $valid_extensions) && in_array($extension4Footer, $valid_extensions) && in_array($extension4Favicon, $valid_extensions)) { $selectSchoolInfo = mysqli_query($GLOBALS['dbconn'], "SELECT * FROM settings_tbl"); if (mysqli_num_rows($selectSchoolInfo) == 1) { if (move_uploaded_file($header_file, $target4Header) && move_uploaded_file($footer_file, $target4Footer) && move_uploaded_file($favicon_file, $target4Favicon)) { $updateSchoolInfoKwary = mysqli_query($GLOBALS['dbconn'], "UPDATE settings_tbl SET school_name = '$school_name', school_address = '$school_address', school_phone1 = '$school_phone1', school_phone2 = '$school_phone2', school_email = '$school_email', school_mission = '$school_mission', school_vision = '$school_vision', header_logo = '$header_logo', footer_logo = '$footer_logo', favicon = '$favicon' "); if ($updateSchoolInfoKwary) { $error = '<div class="alert alert-success alert-dismissible fade show"> <button type="button" class="close" data-dismiss="alert">&times;</button> <strong><span><i class="icon-check"></i></span></strong> School Settings Updated Successfully. </div>'; // header('Location: general-settings.php'); echo $error; }else{ $error= '<div class="alert alert-danger alert-dismissible fade show"> <button type="button" class="close" data-dismiss="alert">&times;</button> <strong><span><i class="icon-check"></i></span></strong> School Settings Updated Failed. </div>'; // header('Location: general-settings.php'); echo $error; } } }elseif (mysqli_num_rows($selectSchoolInfo) <= 0) { if (move_uploaded_file($header_file, $target4Header) && move_uploaded_file($footer_file, $target4Footer) && move_uploaded_file($favicon_file, $target4Favicon)) { $insertSchoolInfoKwary = mysqli_query($GLOBALS['dbconn'], "INSERT INTO `settings_tbl` (`school_name`, `school_address`, `school_phone1`, `school_phone2`, `school_email`, `school_mission`, `school_vision`, `header_logo`, `footer_logo`, `favicon`) VALUES ('$school_name', '$school_address', '$school_phone1', '$school_phone2', '$school_address', '$school_mission', '$school_vision', '$header_logo', '$footer_logo', '$favicon');"); if ($insertSchoolInfoKwary) { $error= '<div class="alert alert-success alert-dismissible fade show"> <button type="button" class="close" data-dismiss="alert">&times;</button> <strong><span><i class="icon-check"></i></span></strong> School Settings Added Successfully. </div>'; // header('Location: general-settings.php'); echo $error; }else{ // $_SESSION['school_settings_update_error'] $error = '<div class="alert alert-danger alert-dismissible fade show"> <button type="button" class="close" data-dismiss="alert">&times;</button> <strong><span><i class="icon-check"></i></span></strong> School Settings Submission Failed. </div>'; // header('Location: general-settings.php'); echo $error; } } } }else{ echo "<script>alert('Oops! Image Extension not Supported!')</script>"; } }

php html mysql image-uploading
1个回答
-2
投票
您可以使用两次分号“;”

$insertSchoolInfoKwary = mysqli_query($GLOBALS['dbconn'], "INSERT INTO `settings_tbl` (`school_name`, `school_address`, `school_phone1`, `school_phone2`, `school_email`, `school_mission`, `school_vision`, `header_logo`, `footer_logo`, `favicon`) VALUES ('".$school_name."', '".$school_address."', '".$school_phone1."', '".$school_phone2."', '".$school_address."', '".$school_mission."', '".$school_vision."', '".$header_logo."', '".$footer_logo."', '".$favicon."')");

现在复制并粘贴上面的代码,我认为效果很好
© www.soinside.com 2019 - 2024. All rights reserved.