0

this is the whole code where in I got a problem

<?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("Error 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>";
}
?>
<form 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>

this code has the ability to select 5 database at first... I tried to have an output of images at first that will reveal it's output at the browser... by default it was not uploaded by the user but already in a folder ( only path by image tag inside the while loop statement ). My problem now is, I dunno about how to do this 2 things:

1.) if the user will upload something, it will be automatically transfered to the $destination

2.) the last upload of the user will be shown too like what is done in the while loop statement

I will truly appreciate your explanations and help to this forum

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by urtrivedi
0

you must create another php file called index_web_page2.php

<?php
 -- here proper connection parameter are required
$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."')";  


header("location:main_file_name.php");

?>

remove this code from your main file.

Edited by urtrivedi: n/a

0

you must create another php file called index_web_page2.php

<?php
 -- here proper connection parameter are required
$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."')";  


header("location:main_file_name.php");

?>

remove this code from your main file.

you mean I need to create a third page??? like webpage.php??
and remove this from webpage2.php??

0

you need two pages
1 one your main page which code you have posted above(only remove the upload logic that i mentioned from main page)
2 another page will contain upload logic i posted name that page as index_web_page2.php (because you mentioned that name in action attribute of form element)

No third page required

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.