- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 HTML 表单
,其中包含一些文本输入和一些文件输入。我正在尝试使用 ajax 将文本和图像上传到数据库来执行它。我尝试过解决方案here和 here但这都不适合我。下面是我的代码
HTML 表单
<form action="genformexec.php" name="genreg" id="genreg" method="post" enctype="multipart/form-data">
<label class="type" for="ccode">*Your confirmation code is the series of numbers sent to your mail after payment verification</label>
<input class="half" type="text" name="ccode" id="ccode" placeholder="Confirmation Code">
<input class="half" type="email" name="uemail" id="uemail" placeholder="Email Address">
<input class="half" type="text" name="fname" id="fname" placeholder="First Name">
<input class="half" type="text" name="lname" id="lname" placeholder="Last Name">
<input class="full" type="text" name="cname" id="cname" placeholder="Company Name">
<input class="full" type="text" name="crcnum" id="crcnum" placeholder="Company RC/BN Number">
<input class="full" type="text" name="uaddress" id="uaddress" placeholder="Residential Address">
<input class="full" type="text" name="caddress" id="caddress" placeholder="Company Address">
<textarea class="full" rows="7" name="briefdes" id="briefdes" placeholder="Brief description about your company"></textarea>
<input class="half" type="text" name="uname" id="uname" placeholder="Username">
<input class="half" type="text" name="uphone" id="uphone" placeholder="Phone Number">
<input class="half" type="text" name="pword" id="pword" placeholder="Password">
<input class="half" type="text" name="cfpword" id="cfpword" placeholder="Re-Type Password">
<div class="profImage"><img id="logo_prev" src=""></div><br>
<label for="profimages">Upload Company Logo/Profile Picture</label><br><br>
<input type="file" onchange="logo_prev()" name="profimages" id="profimages">
<div class="coverimage"><img id="cover_prev"src=""></div>
<label for="coverimage">Upload a cover image for your profile</label><br><br>
<input type="file" onchange="cover_prev()" name="coverimage" id="coverimage">
<input type="file" name="profimages" id="profimages">
<label class="type">Receive request about</label>
<div class="postLimit">
<p class="limitType">Food Commodities</p>
<div class="checkin"><input type="checkbox" name="postValue[]" value="Fresh Yam">Fresh Yam</div>
<div class="checkin"><input type="checkbox" name="postValue[]" value="Garri">Garri</div>
<div class="checkin"><input type="checkbox" name="postValue[]" value="Banana and Plantain">Banana and Plantain</div>
<div class="checkin"><input type="checkbox" name="postValue[]" value="Plantain Flour">Plantain Flour</div>
<div class="checkin"><input type="checkbox" name="postValue[]" value="Cassava Flour">Cassava Flour</div>
<div class="checkin"><input type="checkbox" name="postValue[]" value="Chilli Pepper">Chilli Pepper</div>
<div class="checkin"><input type="checkbox" name="postValue[]" value="Kola Nut">Kola Nut</div>
<div class="checkin"><input type="checkbox" name="postValue[]" value="Palm Oil">Palm Oil</div>
<div class="checkin"><input type="checkbox" name="postValue[]" value="Smoked Fish">Smoked Fish</div>
<div class="checkin"><input type="checkbox" name="postValue[]" value="Dried Vegetable">Dried Vegetable</div>
<div class="checkin"><input type="checkbox" name="postValue[]" value="Cray Fish">Cray Fish</div>
<div class="checkin"><input type="checkbox" name="postValue[]" value="Shea Butter">Shea Butter</div>
<div class="checkin"><input type="checkbox" name="postValue[]" value="Cassava Chips">Cassava Chips</div>
<div class="checkin"><input type="checkbox" name="postValue[]" value="Fresh Onions">Fresh Onions</div>
<div class="checkin"><input type="checkbox" name="postValue[]" value="Curry Leaves">Curry Leaves</div>
<div class="checkin"><input type="checkbox" name="postValue[]" value="Bitter Kola">Bitter Kola</div><br><br><br>
<div class="checkin"><input type="checkbox" name="postValue[]" value="Bitter Kola, Fresh Yam, Garri, Banana and Plantain, Plantain Flour, Cassava Flour, Chilli Pepper, Kola Nut, Palm Oil, Smoked Fish, Dried Vegatables, Cray Fish, Shea Butter, Cassava Chips, Fresh Onions, Curry Leaves">All</div>
</div><br><br><br><br>
<label class="type" for="regas">You are registering as:</label>
<input type="text" class="full readonly" readonly name="regas" id="regas" value="Exporter">
<label class="type" for="package">Package type:</label>
<input type="text" class="full readonly" readonly name="package" id="package" value="Bronze">
<input type="submit" name="regSubmit" id="regSubmit" value="Submit">
</form>
Ajax 请求
$("#genreg").submit(function(e) {
var formData = new FormData($(this)[0]);
$.ajax({
url: "genformexec.php",
type: "POST",
data: formData,
async: false,
success: function (msg) {
alert(msg)
},
cache: false,
contentType: false,
processData: false
});
e.preventDefault();
});
PHP 脚本
<?php
error_reporting(0);
session_start();
require_once ("db.php");
$db = new MyDB();
if (isset($_POST['regSubmit']))
{
$fname = strip_tags(@$_POST['fname']);
$lname = strip_tags(@$_POST['lname']);
$cname = strip_tags(@$_POST['cname']);
$crnum = strip_tags(@$_POST['crcnum']);
$uaddress = strip_tags(@$_POST['uaddress']);
$caddress = strip_tags(@$_POST['caddress']);
$briefdes = strip_tags(@$_POST['briefdes']);
$uname = strip_tags(@$_POST['uname']);
$uphone = strip_tags(@$_POST['uphone']);
$pword = $_POST['pword'];
$cfpword = $_POST['cfpword'];
$uemail = $_POST['uemail'];
$regas = strip_tags(@$_POST['regas']);
$package = strip_tags(@$_POST['package']);
$imagedir = './profimages/';
$profimages = $_FILES['profimages']['name'];
$profimagestmpname = $_FILES['profimages']['tmp_name'];
$profimages = $_FILES['profimages']['type'];
$profimages = $_FILES['profimages']['size'];
$regdate = date('d/m/Y');
$ccode = strip_tags(@$_POST['ccode']);
$posttype = join(", ", $_POST['postValue']);
$status = "0";
$verified = "0";
$zero = "0";
$website = strip_tags(@$_POST['website']);
$coverimage = $_FILES['coverimage']['name'];
$coverimagetmpname = $_FILES['coverimage']['tmp_name'];
$coverimage = $_FILES['coverimage']['type'];
$coverimage = $_FILES['coverimage']['size'];
$csql = "SELECT COUNT(*) as count FROM paymentverification WHERE code = $ccode";
$psql = $db->prepare("SELECT * FROM paymentverification WHERE code = ?");
$psql->bindParam(1, $ccode, SQLITE3_TEXT);
$cret = $db->querySingle($csql);
$pret = $psql->execute();
if ($cret == 1)
{
while ($prow = $pret->fetchArray(SQLITE3_ASSOC))
{
$cpackage = $prow['package'];
if ($cpackage == $package)
{
$cql = <<<EOF
SELECT COUNT(*) FROM users WHERE ccode = $ccode;
EOF;
$count = $db->querySingle($cql);
if ($count == 1)
{
echo "This code as already been used";
}
else
{
if ($pword != $cfpword)
{
echo 'The passwords you entered do not match. Please try again!.';
}
else
{
if (strlen($pword) <= 8)
{
echo 'Your password must be more than 8 characters';
}
else
{
$imagepath = $imagedir . $profimages;
$imagepath_2 = $imagedir . $coverimage;
$imageresult = move_uploaded_file($profimagestmpname, $imagepath);
$imageresult_2 = move_uploaded_file($coverimagetmpname, $imagepath_2);
if (!$imageresult && !$imageresult_2)
{
echo "Error uploading Company Logo/Profile Picture";
}
if (!get_magic_quotes_gpc())
{
$profimages = addslashes($profimages);
$imagepath = addslashes($imagepath);
$coverimage = addslashes($coverimage);
$imagepath_2 = addslashes($imagepath_2);
}
$stmt = $db->prepare('INSERT INTO users (fname, lname, cname, crcnum, caddress, uaddress, briefdes, uemail, uphone, uname, regas, pword, cfpword, profimages, package, regdate, ccode, posttype, status, verified, website, coverimage)
VALUES (:fname, :lname, :cname, :crnum, :caddress, :uaddress, :briefdes, :uemail, :uphone, :uname, :regas, :pword, :cfpword, :profimages, :package, :regdate, :ccode, :posttype, :status, :verified, :website, :coverimage)');
$stmt->bindValue(':fname', $fname, SQLITE3_TEXT);
$stmt->bindValue(':lname', $lname, SQLITE3_TEXT);
$stmt->bindValue(':cname', $cname, SQLITE3_TEXT);
$stmt->bindValue(':crnum', $crnum, SQLITE3_TEXT);
$stmt->bindValue(':caddress', $caddress, SQLITE3_TEXT);
$stmt->bindValue(':uaddress', $uaddress, SQLITE3_TEXT);
$stmt->bindValue(':briefdes', $briefdes, SQLITE3_TEXT);
$stmt->bindValue(':uemail', $uemail, SQLITE3_TEXT);
$stmt->bindValue(':uphone', $uphone, SQLITE3_TEXT);
$stmt->bindValue(':regas', $regas, SQLITE3_TEXT);
$stmt->bindValue(':regdate', $regdate, SQLITE3_TEXT);
$stmt->bindValue(':uname', $uname, SQLITE3_TEXT);
//Come back to password_hash password $stmt->bindValue(':pword', password_hash($pword, PASSWORD_BCRYPT));
$stmt->bindValue(':pword', password_hash($pword, PASSWORD_BCRYPT));
$stmt->bindValue(':cfpword', password_hash($cfpword, PASSWORD_BCRYPT));
$stmt->bindValue(':profimages', $imagepath, SQLITE3_TEXT);
$stmt->bindValue(':package', $package, SQLITE3_TEXT);
$stmt->bindValue(':ccode', $ccode, SQLITE3_INTEGER);
$stmt->bindValue(':posttype', $posttype, SQLITE3_TEXT);
$stmt->bindValue(':status', $status, SQLITE3_INTEGER);
$stmt->bindValue(':verified', $verified, SQLITE3_INTEGER);
$stmt->bindValue(':website', $website, SQLITE3_TEXT);
$stmt->bindValue(':coverimage', $imagepath_2, SQLITE3_TEXT);
$result = $stmt->execute();
if ($result)
{
echo "Account Successfully Created";
}
else
{
echo "Sorry!.....There was an issue creating your account. Please try again";
}
}
}
}
}
else
{
echo "You payed for the $cpackage package";
exit();
}
}
}
}
?>
那么请问任何 mu 代码有什么问题以及我如何修复并使其工作。抱歉,如果我发布不必要的代码(我只是认为它们都需要你帮助我)。谢谢
最佳答案
您正在使用不同的值覆盖文件变量:
$profimages = $_FILES['profimages']['name'];
$profimagestmpname = $_FILES['profimages']['tmp_name'];
$profimages = $_FILES['profimages']['type'];
$profimages = $_FILES['profimages']['size'];
应该是这样的:
$profImagesName = $_FILES['profimages']['name'];
$profImagesTmpName = $_FILES['profimages']['tmp_name'];
$profImagesType = $_FILES['profimages']['type'];
$profImagesSize = $_FILES['profimages']['size'];
然后使用:
$imagedir = './profimages/';
$imagepath = $imagedir . $profImagesName;
move_uploaded_file($profImagesTmpName, $imagepath);
这应该对所有图像进行更改 - 我不知道它是否能完全解决问题,但它应该得到修复。
关于javascript - 使用 PHP 和 Ajax 提交包含文本和图像的表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45449843/
我有一个 html 格式的表单: 我需要得到 JavaScript在value input 字段执行,但只能通过表单的 submit .原因是页面是一个模板所以我不控制它(不能有
我管理的论坛是托管软件,因此我无法访问源代码,我只能向页面添加 JavaScript 来实现我需要完成的任务。 我正在尝试用超链接替换所有页面上某些文本关键字的第一个实例。我还根据国家/地区代码对这些
我正在使用 JS 打开新页面并将 HTML 代码写入其中,但是当我尝试使用 document.write() 在新页面中编写 JS 时功能不起作用。显然,一旦看到 ,主 JS 就会关闭。用于即将打开的
提问不是为了解决问题,提问是为了更好地理解系统 专家!我知道每当你将 javascript 代码输入 javascript 引擎时,它会立即由 javascript 引擎执行。由于没有看过Engi
我在一个文件夹中有两个 javascript 文件。我想将一个变量的 javascript 文件传递到另一个。我应该使用什么程序? 最佳答案 window.postMessage用于跨文档消息。使
我有一个练习,我需要输入两个输入并检查它们是否都等于一个。 如果是 console.log 正则 console.log false 我试过这样的事情: function isPositive(fir
我正在做一个Web应用程序,计划允许其他网站(客户端)在其页面上嵌入以下javascript: 我的网络应用程序位于 http://example.org 。 我不能假设客户端网站的页面有 JQue
目前我正在使用三个外部 JS 文件。 我喜欢将所有三个 JS 文件合而为一。 尽一切可能。我创建 aio.js 并在 aio.js 中 src="https://code.jquery.com/
我有例如像这样的数组: var myArray = []; var item1 = { start: '08:00', end: '09:30' } var item2 = {
所以我正在制作一个 Chrome 扩展,它使用我制作的一些 TamperMonkey 脚本。我想要一个“主”javascript 文件,您可以在其中包含并执行其他脚本。我很擅长使用以下行将其他 jav
我有 A、B html 和 A、B javascript 文件。 并且,如何将 A JavaScript 中使用的全局变量直接移动到 B JavaScript 中? 示例 JavaScript) va
我需要将以下整个代码放入名为 activate.js 的 JavaScript 中。你能告诉我怎么做吗? var int = new int({ seconds: 30, mark
我已经为我的 .net Web 应用程序创建了母版页 EXAMPLE1.Master。他们的 I 将值存储在 JavaScript 变量中。我想在另一个 JS 文件中检索该变量。 示例1.大师:-
是否有任何库可以用来转换这样的代码: function () { var a = 1; } 像这样的代码: function () { var a = 1; } 在我的浏览器中。因为我在 Gi
我收到语法缺失 ) 错误 $(document).ready(function changeText() { var p = document.getElementById('bidp
我正在制作进度条。它有一个标签。我想调整某个脚本完成的标签。在找到可能的解决方案的一些答案后,我想出了以下脚本。第一个启动并按预期工作。然而,第二个却没有。它出什么问题了?代码如下: HTML:
这里有一个很简单的问题,我简单的头脑无法回答:为什么我在外部库中加载时,下面的匿名和onload函数没有运行?我错过了一些非常非常基本的东西。 Library.js 只有一行:console.log(
我知道 javascript 是一种客户端语言,但如果实际代码中嵌入的 javascript 代码以某种方式与在控制台上运行的代码不同,我会尝试找到答案。让我用一个例子来解释它: 我想创建一个像 Mi
我如何将这个内联 javascript 更改为 Unobtrusive JavaScript? 谢谢! 感谢您的回答,但它不起作用。我的代码是: PHP js文件 document.getElem
我正在寻找将简单的 JavaScript 对象“转储”到动态生成的 JavaScript 源代码中的最优雅的方法。 目的:假设我们有 node.js 服务器生成 HTML。我们在服务器端有一个对象x。
我是一名优秀的程序员,十分优秀!