2011-03-22 29 views
0

這是整個代碼在那裏我有一個問題上傳文件:有人能讓我知道如何超越這個錯誤嗎?

<?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循環語句中圖像標籤的路徑)。我現在的問題是,我不知道如何做到這一點兩兩件事:

1)如果用戶會上傳一些東西,它會自動轉移到$目的地

2)的最後上傳用戶將顯示太喜歡在while循環語句來完成

我會很欣賞你的解釋和幫助

+0

,什麼是錯誤? – 2011-03-23 01:14:16

回答

0

一件事是,你似乎在這裏有一個語法錯誤,因爲你的字符串包含終止報價字符串太早:

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

由於語法高亮顯示不正確,錯誤很容易察覺。

要解決它,你可以使用單引號代替雙引號來分隔字符串:

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

@丹尼爾:實際上它確實有效,即使你有其他的錯誤,所以它不會立即和神奇地讓你的整個腳本功能。事實上,你必須在繼續之前做出這個修正。 – 2011-03-23 01:14:52

+0

@Tomalak感謝您保留它 – 2011-03-23 13:06:02

相關問題