我目前正在开发一个PHP脚本来将图像上传到mysql数据库,我在代码的第13行收到语法错误,指出了意外的T_IF。我对PHP比较陌生,我正在努力找出导致它的原因。代码如下;
<head>
<title>File Upload To Database</title>
</head>
<body>
<form action="index.php" method="POST" enctype="multipart/form-data">
<input type="file" name="image"><Input type="submit" name="submit" value="Upload">
</form>
<?php>
if(isset($_POST['submit']))
{
mysql_connect("localhost","appuser1","******");
mysql_select_db("PHP_Sig_test_app");
$imageName = mysql_real_escape_string($FILES["image"]["name"]);
$imageData = mysql_real_escape_string(file_get_contents($_FILES["image"]["tmp_name"]));
$imageType = mysql_real_escape_string($FILES["image"]["type""]);
if(substr($imageType,0,5) == "image)
{
mysql_query("INSERT INTO 'Data' Values('','$imageName','$imageData')";
echo "image uploaded";
}
else
{
echo "Only Images can be Inserted"
}
}
?>
</body>
</html>
由于
答案 0 :(得分:2)
<?php>
应为<?php
导致语法错误
答案 1 :(得分:2)
删除此行中的右括号:
<?php>
这会启动一个带有>
符号的新命令(这使得没有意义),因此> if
将失败,这就是您的错误原因。
你的第二个if语句也缺少引用。
if(substr($imageType,0,5) == "image)
应该是
if(substr($imageType,0,5) == "image")
答案 2 :(得分:2)
有一些语法错误 -
<?php //removed >
if(isset($_POST['submit']))
{
mysql_connect("localhost","appuser1","weeble180276");
mysql_select_db("PHP_Sig_test_app");
$imageName = mysql_real_escape_string($FILES["image"]["name"]);
$imageData = mysql_real_escape_string(file_get_contents($_FILES["image"]["tmp_name"]));
$imageType = mysql_real_escape_string($FILES["image"]["type"]); //removed "
if(substr($imageType,0,5) == "image") //added "
{
mysql_query("INSERT INTO 'Data' Values('','$imageName','$imageData')";
echo "image uploaded";
}
else
{
echo "Only Images can be Inserted"; // added ;
}
}
?>