所以,我有一项任务,我需要让用户直接向使用其网站上的表单的开发人员报告游戏中的错误。在这个表单上需要有各种信息,包括上传你遇到的错误照片的可能性。我在使用此功能时遇到问题,所以如果有人花些时间查看我的代码,我将非常感激:)
HTML:
<html>
<head>
<title>Raporter Bugs</title>
<link type="text/css" rel="stylesheet" href="stylesheet.css"/>
</head>
<body>
<div id="bug_report_table_div">
<div id="overskrift_bug">Raporter Feil</div>
<div id="bug_report_table">
<form action="insert.php" method="post">
<table>
<tr></tr>
<tr>
<td>Navn på spill</td>
<td><select name="spill">
<option value="Synapsis">Synapsis</option>
<option value="Profit">Profit</option>
<option value="Blobb">Blobb</option>
</select></td>
</tr><br>
<tr>
</tr>
<tr>
<td>Når fant feilen sted? </td>
<td><input type="text" name="tidspunkt"/></td>
</tr>
<tr>
<td>Feil funnet av</td>
<td><input type="text" name="rapportør" /></td>
</tr>
<tr>
<td>Picture of the bug</td>
<td>
<input type="hidden" name="size" value="350000">
<input type="file" name="photo">
</td>
</tr>
<tr>
<td>Beskriv problemet</td>
<td><textarea rows="5" cols="35" name="beskrivelse"></textarea></td>
</tr>
<tr>
<td colspan="2"><div id="submit_button_bugs"><input type="submit"><div></td>
</tr>
</table>
</div>
</div>
PHP:
<?php
if( !session_id() ) session_start();
$con=mysqli_connect("127.0.0.1","root","","epicsoft");
$host="127.0.0.1"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="epicsoft"; // Database name
$tbl_name="bugs"; // Table name
// Check connection
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select database");
//variables
$spill = $_POST['spill'];
$tidspunkt = $_POST['tidspunkt'];
$rapportør = $_POST['rapportør'];
$pic = ($_FILES['photo']['name']);
$beskrivelse = $_POST['beskrivelse'];
$target ="images";
$target = $target.basename( $_FILES['photo']['name']);
?>
<html>
<div id="navigation_buttons">
<form action="user_login.php" method="post">
<table><tr>
<br><br><br>
<td>Click here to go to login screen</td>
<td><input type="submit" name="register" value="Continue"></td>
</tr></form>
<form action="user_registration.php" method="post">
<tr>
<br><br><br>
<td>Click here to return to the registration page</td>
<td><input type="submit" name="register" value="Back"></td>
</tr></table>
</div>
我收到错误消息:
Notice: Undefined index: photo in C:\xampp\htdocs\insert.php on line 22
Notice: Undefined index: photo in C:\xampp\htdocs\insert.php on line 26
Notice: Undefined index: photo in C:\xampp\htdocs\insert.php on line 28
谢谢,请帮忙
答案 0 :(得分:0)
在您的表单中,您需要包含enctype才能将文件上传到系统
<form action="insert.php" method="post" enctype='multipart/form-data'>
因此在php端$_FILES
将为您提供有关正在上传的文件的所有信息
答案 1 :(得分:0)
更改
<form action="user_registration.php" method="post">
到
<form action="user_registration.php" method="post" enctype='multipart/form-data'>