上传文件:有人可以告诉我如何超越这个错误吗?

时间:2011-03-22 21:24:05

标签: php mysql html

这是我遇到问题的整个代码

<?php
//get the value of the selected radio value from webpage1.html
$n=$_POST['company'];
$dbhost="localhost";
$dbuser="root";
$dbpass="";
$dbname;
?>
<html><head><title>web page1</title></head><body>
<?php
// logical selection for $n
if($n==1){
echo"You selected Company <font color=red>bhagis portal</font> <br>";
$dbname="bhagis_portal";
}
elseif($n==2){
echo"You selected Company <font color=red>bli portal</font> <br>";
$dbname="bliportal";
}
elseif($n==3){
echo"You selected Company <font color=red>m portal</font> <br>";
$dbname="m_portal";
}
else{
echo"You Selected Company <font color=red>vg portal</font> <br>";
$dbname="vg_portal";
}
$conn=mysql_connect($dbhost,$dbuser,$dbpass)or die("<strong         class="highlight">Error</strong> connecting to MySQL");
mysql_select_db($dbname)or die(mysql_error());
$query="Select * from img_table";
$row=mysql_query($query)or die(mysql_error());
while($result=mysql_fetch_array($row)){
echo $result[0].") ";
echo "<img src=/".$dbname."/images/".$result[1]."><br>";
}
?>
<<strong class="highlight">form</strong> action="index_web_page2.php" method="post"         enctype="multipart/form-data">
<input name="hiddenField" type="hidden" id="hiddenField" value="999999">
<input type="file" id="timesheet" name="timesheet"><br>
<input type="submit" name="cb_read" id="cb_read" value="Upload Timekeeping File">
<input type=reset  name=reset value=clear></form>

<?php
$pic=$_file["timesheet"]["tmp_name"];
$destination='\xampp\htdocs\new'.'\\'.$dbname.'\images'.'\\'.$_files["timesheet"]        ["tmp_name"];
move_uploaded_file($pic,$destination);

/* key code */
$query="insert into img_table(img_name) values('".$pic."')";


?>
</body>
</html>

此代码首先能够选择5个数据库...我试图先输出图像,然后在浏览器中显示它的输出...默认情况下,它不是由用户上传但已经在一个文件夹(while循环语句中只有image标签的路径)。我现在的问题是,我不知道怎么做这两件事:

1。)如果用户上传某些内容,它将自动转移到$ destination

2。)用户的上次上传也会像在while循环语句中完成的那样显示

我将非常感谢您的解释和帮助

1 个答案:

答案 0 :(得分:0)

有一件事是你在这里看起来有一个语法错误,因为你的字符串包含一个过早终止字符串的引用:

"<strong         class="highlight">Error</strong> connecting to MySQL"

由于语法突出显示不正确,很容易发现错误。

要修复它,您可以使用单引号而不是双引号来分隔字符串:

'<strong         class="highlight">Error</strong> connecting to MySQL'