Hi everyone, I have this issue, currently am able to save the attachment name in mysql database. However, after saving it doesn't display the attachment name in the form and so unable to open the attachment. Below is the coding. Please advise how to display the attachment name and open the attachment after clicking submit button. Really appreciate your help and thanks a lot.

<html> <body> <form name="progress" id="progress" method="post" action=""> <div id="tabs-1"> <?php
session_start();
$con = mysql_connect("localhost","user","");

if (!$con){

die("Can not connect: " . mysql_error());

}

mysql_select_db("pq",$con);

$Picid = $_GET['Picid'];
$nwQty = "SELECT * FROM progress WHERE Picid = '$Picid'";
// check if the progress is already
$solution = mysql_query($nwQty);

if(isset($_POST['submit'])){

if (mysql_num_rows($solution) == 0){

// put the progress in table
$sql = "INSERT INTO progress(Quanprogress1,Qualprogress1,Attachment1,Picid) VALUES ('" . $_POST["Quanprogress1"] . "','" . $_POST["Qualprogress1"] . "','" . $_POST["Attachment1"] . "','" . $Picid . "')";
$result = mysql_query($sql);

} else {

// update progress in table
$sql =("UPDATE progress SET Quanprogress1='" . $_POST["Quanprogress1"] . "', Qualprogress1='" . $_POST["Qualprogress1"] . "', Attachment1='" . $_POST["Attachment1"] . "' WHERE Picid='" . $Picid . "'");
$result = mysql_query($sql);
echo('Record Updated');

}

$result = mysql_query("SELECT * FROM progress WHERE Picid='$Picid' ");
$row= mysql_fetch_array($result);

}

?> <p><b>1.Target</b></p>
<Table>
<tr>
<td><font size=2>a.i.Quantitative Progress:</font></td>
<td><input type="text" name="Quanprogress1" id="Quanprogress1" class="txtField" value="<?php echo $row['Quanprogress1']; ?>"></td>
<td><font size=2>a.ii.Qualitative Progress: </font></td>
<td><input type="text" name="Qualprogress1" id="Qualprogress1" class="txtField" value="<?php echo $row['Qualprogress1']; ?>"></td>
</tr>
</table>
<p><ENCTYPE="multipart/form-data">c.i.Preformatted Forms: <input type="file" name="Attachment1" id="Attachment1" MAXLENGTH=50 ALLOW="text/*" value="<?php echo $row['Attachment1']; ?>"></p>
<input type="hidden" name="Picid" id="Picid" value="<?php echo $row['Picid']; ?>" >
<input type="hidden" name="Progressid" id="Progressid" value="<?php echo $row['Progressid']; ?>">
<td colspan="2"><input type="submit" name="submit" id="submit" value="Save" class="btnSubmit"></td>
</div>
</form>
</body>
</html>

To start, there is no tag named <ENCTYPE>. So, <ENCTYPE="multipart/form-data"> should have been <form method="post" ENCTYPE="multipart/form-data">. However, you are not allowed to "nest" <form> tags. Immediately after the <body>, I see you opened a <form> tag, which you close at the very end of the page.
The enctype attribute needs to go on first <form> tag. Additionally, when submitting attachments, you must use method='post'. Thus, the correct markup should have been <form method="post" enctype="multipart/form-data" action="<?php echo $_SERVER['SCRIPT_NAME'];?>">.

Also, in PHP, the information for all fields of <input type="file"> end up in $_FILES, not in $_POST (refer to the PHP Manual). So in your insert statement, $_POST["Attachment1"] should be $_FILES['Attachment1']['name']

You may also need to change $Picid = $_GET['Picid']; to $Picid = array_key_exists('Picid',$_POST) ? $_POST['Picdd']: $_GET['Picid'];

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.