【发布时间】:2016-09-14 21:05:20
【问题描述】:
我在第 26 行和第 27 行的变量中收到此错误。我一直在寻找问题本身,有人说变量未初始化。虽然我认为他们是。我还看到有人说要使用 isset() / !empty() 但我不明白它的作用。
<?php
$nome = $_POST['nome']; //26
$preco = $_POST['preco']; //27
if(count($_FILES) > 0) {
if(is_uploaded_file($_FILES['userImage']['tmp_name'])) {
mysql_connect("localhost", "crc", "root");
mysql_select_db ("crc");
$imgData =addslashes(file_get_contents($_FILES['userImage'['tmp_name']));
$sql = "INSERT INTO fios (nome,preco,imagem)VALUES('$nome','$preco','{$imgData}')";
$current_id = mysql_query($sql) or die("<b>Erro:</b> Problema na imagem inserida!<br/>" . mysql_error());
if(isset($current_id)) {
header("Location: veradmin.php");
}}}
?>
<!DOCTYPE html>
<html>
<title>Inserir</title>
</head>
<body>
<form name="frmImage" enctype="multipart/form-data" action="" method="post" class="frmImageUpload">
<div align="center">
</p><tr>
<td width="321"><strong>Nome/Descricao:</strong></td>
<td width="102" align="left">
<input type="text" name="nome" value="" size="40" />
</td>
</tr><p>
</p><tr>
<td width="321"><strong>Preco:</strong></td>
<td width="102" align="left">
<input type="text" maxlength="9" name="preco" value="" size="20" />
</td><p>
</p></tr>
<input name="userImage" type="file" class="inputFile" /><p>
</p><input type="submit" value="Inserir Registo" class="btnSubmit" />
</form>
</div>
</body>
</html>
【问题讨论】:
-
基本上,您不知道
$_POST['nome']实际上包含任何内容。您需要先使用isset()进行检查 -
替换 $nome = $_POST['nome']; //26 $preco = $_POST['preco']; //27 由 $nome = $preco = '';.然后再试一次
-
第 26 行和第 27 行 _ 是什么??
-
我已经看到了,它没有做任何更改,仍然有同样的错误。