demo.php

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My First Project in PHP</title>
</head>

<body bgcolor=tan>
<h1><font color="firebrick">PHP MySQL </font></h1>

<form action="success.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="box" value="100000">
<table width="500" border="1">
<tr><td><b><label for='name'>Name :</b></label></td> <td><input type="text" name="Uname" size="20" /></td></tr>
<tr><td><b><label for='mail'>Email :</b></label></td><td><input type="text" name="mail" size="20" /></td></tr>
 <tr><td><b> <label for='Updated_file'>Attachements:</b></label></td> <td>  <input type="file" name="Updated_file" id="Updated_file" /></td></tr>
<tr><td  colspan="2" align="center"><input type="Submit" value="Submit" name="Submit" id="Submit" onClick="return validate();"> <input type="reset" value="Reset" name="reset"> </td></tr>
</table>
</form>
</body>
</html>

success.php

<?php

$con = mysql_connect("localhost", "root");    
mysql_select_db("connect_db", $con);

/*$sql = "CREATE TABLE upload1 (
id INT NOT NULL AUTO_INCREMENT,
User_Name VARCHAR(30) NOT NULL,
Email VARCHAR(30) NOT NULL,
name VARCHAR(30) NOT NULL,
type VARCHAR(30) NOT NULL,
size INT NOT NULL,
content MEDIUMBLOB NOT NULL,
PRIMARY KEY(id)
)";
mysql_query($sql,$con);*/

$Uname = $_POST['Uname'];
$mail = $_POST['mail'];
error_reporting(0); 
$fileName = $fileName . basename ($_FILES['Updated_file']['name']);
$tmpName  = move_uploaded_file($_FILES['Updated_file']['tmp_name'], $fileName);
$fileSize = $_FILES['Updated_file']['size'];
$fileType = $_FILES['Updated_file']['type'];

$fp      = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);

$query = "INSERT INTO upload1 (User_Name, Email, name, size, type, content) VALUES ('".$Uname."', '".$mail."', '".$fileName."', '".$fileSize."', '".$fileType."', '".$content."' )";
mysql_query($query) or die("Error, query failed");



$id    = $_GET['id'];
$result = mysql_query("SELECT * FROM upload1");
while($row = mysql_fetch_array($result))
    {

    echo "<font color='red'>Name :</font> ".$row['User_Name'].",<br />";

    echo "<font color='blue'>Email :</font>".$row['Email'].",<br />";

    echo "<font color='green'>Attachements :</font>"."<a href=$fileName > Open Attachments</a>".".<br />";

}

mysql_close($con);

?>

Here Insert is success. But My problem is unable to open the matching attachment. In my code Last updating file is open to all names.
Plz help me.

In your code.. $filename variable having the value of last updated file in to your database.. So only you have this problem... Use the following code...

$files=$row; // This will get filename for each iteration and stored in $files..

<a href=$files> Open Attachment </a> // Now use like this...

This will surely works.. If still problem exists, pls let me know....

Thanks alot. Its working..

demo1.html

<html>
<body>
<form action = "action.php" method = "post">
<p>Name:<input type="text" name = "name"/></p>
<p>Age:<input type="text" name = "age"/></p>
</form>
</body>
</html>

action.php

echo "Hi <b>">$_POST."</b>,Welcome!":
echo "You are".$_POST."Years older!";


My doubt

In this small example, Directly I want edit the name and age in html output screen. What is the code for editing in html output screen..

Hmmm... Fine...Have Fun...

Do you want to edit in action.php page or demo1.html page..? I can't clearly get your point...

Do you want to edit in action.php page or demo1.html page..? I can't clearly get your point...

Hey, I want to edit in action.php.

http://localhost/demo1.html

Here we get like this

Name:
Age:

and we submit the name and age, Suppose we submit Jegana and 23 means, we get like this.

Hi Jegana Welcome!
You are 23 Years older!


But, After this how we can edit this name Jegana and age 23.

You cannot edit this in php page without html form controls like textbox etc.. Use like the following sample code.. Here you can dynamically change the username by using texbox entry....

<form action='' name='myform' method='post'>
<input type='text' name='uname'><br>
<input type='text' name='uage'><br>
<input type='submit' value='Submit'>
</form>

<?php

@$un=$_REQUEST['uname'];
@$age=$_REQUEST['uage'];
if(isset($un))
{
echo "Hi ".$un." Welcome !<br>";
echo "You are ".$age." years old";
}

Input
Jegan
23

Output

Hi Jegan Welcome !
You are 23 years old

But how can i edit Jegan and 23 here.

I am sorry... You cannot edit this... you can reenter in the same field and click to change the name...

I am sorry... You cannot edit this... you can reenter in the same field and click to change the name...

K.Fine. thank u..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.