我一直试图了解这个PHP代码从表单(包括字段和护照)到MySQL数据库发送数据的真正错误。我一直收到意外的文件结束。这段代码似乎是正确的,但PHP让我感觉很糟糕,我需要帮助。
代码如下所示:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>People Data</title>
<meta name="generator" content="Web Page Maker">
<style type="text/css">
/*----------Text Styles----------*/
.ws6 {font-size: 8px;}
.ws7 {font-size: 9.3px;}
.ws8 {font-size: 11px;}
.ws9 {font-size: 12px;}
.ws10 {font-size: 13px;}
.ws11 {font-size: 15px;}
.ws12 {font-size: 16px;}
.ws14 {font-size: 19px;}
.ws16 {font-size: 21px;}
.ws18 {font-size: 24px;}
.ws20 {font-size: 27px;}
.ws22 {font-size: 29px;}
.ws24 {font-size: 32px;}
.ws26 {font-size: 35px;}
.ws28 {font-size: 37px;}
.ws36 {font-size: 48px;}
.ws48 {font-size: 64px;}
.ws72 {font-size: 96px;}
.wpmd {font-size: 13px;font-family: Arial,Helvetica,Sans-Serif;font-style: normal;font-weight: normal;}
/*----------Para Styles----------*/
DIV,UL,OL /* Left */
{
margin-top: 0px;
margin-bottom: 0px;
}
</style>
<style type="text/css">
div#container
{
position:relative;
width: 1089px;
margin-top: 0px;
margin-left: auto;
margin-right: auto;
text-align:left;
}
body {text-align:center;margin:0}
</style>
</head>
<body>
<div id="container">
<form name="people" method="POST" action="info.php" enctype="multipart/form-data style="margin:0px">
<input name="fullname" type="text" style="position:absolute;width:336px;left:427px;top:178px;z-index:2">
<input name="email" type="text" style="position:absolute;width:336px;left:426px;top:213px;z-index:4">
<input name="number" type="text" style="position:absolute;width:336px;left:428px;top:253px;z-index:6">
<input name="pic" type="file" style="position:absolute;width:336px;left:435px;top:343px;z-index:9">
<input name="submit" type="submit" value="Submit data" style="position:absolute;left:534px;top:394px;z-index:10">
</form>
<div id="text1" style="position:absolute; overflow:hidden; left:339px; top:178px; width:93px; height:24px; z-index:1">
<div class="wpmd">
<div><font class="ws9">Full Name : </font></div>
</div></div>
<div id="text2" style="position:absolute; overflow:hidden; left:338px; top:213px; width:93px; height:24px; z-index:3">
<div class="wpmd">
<div><font class="ws9">Email : </font></div>
</div></div>
<div id="text3" style="position:absolute; overflow:hidden; left:340px; top:253px; width:93px; height:24px; z-index:5">
<div class="wpmd">
<div><font class="ws9">Phone Number : </font></div>
</div></div>
<div id="text4" style="position:absolute; overflow:hidden; left:402px; top:304px; width:387px; height:22px; z-index:7">
<div class="wpmd">
<div><font class="ws9"><B>Please Enter your Passport photograph, Must be jpeg, or bmp</B></font></div>
</div></div>
<div id="text5" style="position:absolute; overflow:hidden; left:300px; top:343px; width:140px; height:24px; z-index:8">
<div class="wpmd">
<div><font class="ws9">Passport photograph :</font></div>
</div></div>
<div id="text6" style="position:absolute; overflow:hidden; left:343px; top:137px; width:312px; height:27px; z-index:11">
<div class="wpmd">
<div><font class="ws16"><B>People Information</B></font></div>
</div></div>
</div>
</body>
</html>
PHP看起来有点像这样:
<?php
include 'config.php';
$con = mysqli_connect($hostname,$user,$password,$db) or die ('cannot Connect');
$fullname = mysqli_real_escape_string($con,$_POST['fullname']);
$email = mysqli_real_escape_string($con,$_POST['email']);
$number = mysqli_real_escape_string($con,$_POST['number']);
$tmpName = $_FILES['image']['tmp_name'];
$fp = fopen($tmpName, 'r');
$data = fread($fp, filesize($tmpName));
$data = addslashes($data);
fclose($fp);
$sql = "INSERT INTO personaz(Fullname,email,number,pic) VALUES ('".$fullname."','".$email."','".$number."','".$data."');
if(!mysqli_query($con,$sql))
{
die('Error: '.mysqli_error($con));
}
echo "Complete";
?>
info.php
告诉我意外的文件结束。我似乎不明白问题是什么。我确实需要帮助。
答案 0 :(得分:0)
更改
>>> A()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/mjpieters/Development/Library/buildout.python/parts/opt/lib/python3.5/unittest/mock.py", line 917, in __call__
return _mock_self._mock_call(*args, **kwargs)
File "/Users/mjpieters/Development/Library/buildout.python/parts/opt/lib/python3.5/unittest/mock.py", line 976, in _mock_call
result = next(effect)
StopIteration
TO:
$sql = "INSERT INTO personaz(Fullname,email,number,pic) VALUES ('".$fullname."','".$email."','".$number."','".$data."');
即使来自SO的代码突出显示器也显示错误。所以我会推荐一个更好的IDE